Skip to content

Commit

Permalink
Add a SVGO Docker image for Simpleicons formatting (#1532)
Browse files Browse the repository at this point in the history
* 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 
3299338 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 <ericornelissen@gmail.com>
  • Loading branch information
oleg-nenashev and ericcornelissen committed Jun 9, 2020
1 parent 540635c commit 0756e1d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
@@ -0,0 +1,11 @@
node_modules/

# Jekyll
_site/
.sass-cache/
.jekyll-cache/
.jekyll-metadata

# Build files
icons/*.js
/index.js
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions 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"]

0 comments on commit 0756e1d

Please sign in to comment.