From 0756e1d9a7858598405d1240393f28142df6efa2 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Tue, 9 Jun 2020 12:49:55 +0200 Subject: [PATCH] Add a SVGO Docker image for Simpleicons formatting (#1532) * Add a SVGO Docker image * Update Dockerfile and .dockerignore Update the Dockerfile to create a docker image that is generally applicable to run NPM commands, including but not limited to: - npm run test - npm run svgo - npm run lint Also updated the .dockerignore file to exclude: - The node_modules folder - Common Jekyll folders/files - Files generated by the build script The reason for choosing the alpine docker image (rather than a node docker image) is that the CLI out of the box is better. * Add section on using Docker to Contributing Guidelines * Readd entrypoint for SVGO optimization to Dockerfile Update the Dockerfile based on the original work in 32993385daad3a66d6a2f8094c1dde5c33d2a03b by re-adding an ENTRYPOINT to the Dockerfile. This ENTRYPOINT makes it extremely easy to spin up a quick Docker container to optimize a single SVG (much simpler than my copy-in -> optimize -> copy-out approach). The description for how to use the Docker image to run other NPM scripts has been updated accordingly. The provided command overrides the above ENTRYPOINT by simple starting a shell so the user can interact with the project. Co-authored-by: Eric Cornelisesn --- .dockerignore | 11 +++++++++++ CONTRIBUTING.md | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 11 +++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000000..31c0d4585350 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +node_modules/ + +# Jekyll +_site/ +.sass-cache/ +.jekyll-cache/ +.jekyll-metadata + +# Build files +icons/*.js +/index.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a68c3a01c5e..5e2d17da5d9b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,6 +13,7 @@ Simple Icons welcomes contributions and corrections. Before contributing, please * [Requesting an Icon](#requesting-an-icon) * [Adding or Updating an Icon](#adding-or-updating-an-icon) * [Building the Website](#building-locally) +* [Using Docker](#using-docker) ## Requesting an Icon @@ -90,6 +91,10 @@ All icons in Simple Icons have been optimized with the [SVGO tool](https://githu * Set the precision to about 3, depending on if there is a loss of quality. * Leave the remaining settings untouched (or reset them with the button at the bottom of the settings). * Click the download button. +* The [SVGO Command Line Tool](https://github.com/svg/svgo) in Docker + * If none of the options above work for you, it is possible to build a Docker image for compressing the images. + * Build: `docker build . -t simple-icons` + * Run: `docker run --rm -v ${PWD}/icons/file-to-optimize.svg:/image.svg simple-icons` ### 4. Annotate the Icon @@ -222,6 +227,33 @@ Alternatively, you can build and run the website in a readily configured online [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io#https://github.com/simple-icons/simple-icons) +## Using Docker + +You can build a Docker image for this project from the Dockerfile by running: + +```bash +# Build the Docker image for simple-icons (if you haven't yet) +$ docker build . -t simple-icons + +# Start a Docker container for simple-icons and attach to it +$ docker run -it --rm --entrypoint "/bin/ash" simple-icons +``` + +### Jekyll Server using Docker + +To use a Docker container to run the Jekyll server for the website, run: + +```bash +# Start a container running `jekyll serve` in the background +$ docker run -d -p 4000:4000 --rm --volume $PWD:/srv/jekyll --name simple-icons-server jekyll/jekyll jekyll serve + +# Inspect the server logs +$ docker logs simple-icons-server + +# Stop the server (and delete the container) +$ docker stop simple-icons-server +``` + --- # Versioning diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000000..2f697aa518de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM alpine:3.12 + +RUN apk add --update nodejs npm + +WORKDIR /simple-icons +COPY package*.json /simple-icons/ +RUN npm install + +COPY . . + +ENTRYPOINT ["npm", "run", "svgo", "--", "/image.svg"]