Skip to content

Commit

Permalink
rework of the docker containers to make build them for multi archs an…
Browse files Browse the repository at this point in the history
…d some cleanup work.

- upgraded to node 16 lts, updated dependencies and docker images
- reworked the Makefile for build and release targets, added multiple archs thanks to the template from chrisamti.
- moved the docker image insides into /app for better review.
- changed port mentioned in the docs to 8080, cleaned up test.http example
- added new test subfolder to dockerignore
- moved tests to subfolder, included a simple curl test as well to be run on local docker host
- added docker section to readme, detailing about multi arch builds with buildx
  • Loading branch information
adrianrudnik committed Oct 21, 2021
1 parent d463714 commit 5ceba75
Show file tree
Hide file tree
Showing 10 changed files with 2,230 additions and 306 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/node_modules
**/.idea
**./vscode
**/test
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:15-alpine
FROM node:16-alpine

ENV NODE_ENV=production

Expand All @@ -13,6 +13,8 @@ ENV HEALTHCHECK=true
ENV CHARSET="utf8"
ENV DEFAULT_RESPONSE_CONTENT_TYPE="text/html; charset=utf-8"

WORKDIR /app

COPY package* ./

RUN set -ex \
Expand All @@ -22,9 +24,9 @@ RUN set -ex \

COPY index.js ./index.js

COPY healthcheck.sh /healthcheck.sh
COPY healthcheck.sh /app/healthcheck.sh

HEALTHCHECK --start-period=10s --retries=1 CMD /healthcheck.sh || exit 1
HEALTHCHECK --start-period=10s --retries=1 CMD /app/healthcheck.sh || exit 1

EXPOSE 80

Expand Down
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ ifeq ($(UNAME_M),x86_64)
RACE=-race
endif

all: docker ## Test, lint check and build application
GET_LAST_TAGV = $(shell git tag --sort=v:refname | tail -1)

all: docker-build ## Test, lint check and build application

docker: ## create docker images
# create arm64
docker buildx build -f Dockerfile --platform linux/arm64 --tag dndit/mjml-server:arm64 .
# create amd64
docker buildx build -f Dockerfile --platform linux/amd64 --tag dndit/mjml-server:amd64 .
# push arm64
docker push dndit/mjml-server:arm64
# push amd64
docker push dndit/mjml-server:amd64
# create multi arch manifest
# docker manifest create $(DOCKER_REGISTRY):alpine3.12-manual --amend $(DOCKER_REGISTRY):alpine3.12-arm64 --amend $(DOCKER_REGISTRY):alpine3.12-amd64
docker manifest create dndit/mjml-server --amend dndit/mjml-server:arm64 --amend dndit/mjml-server:amd64
# push
docker manifest push dndit/mjml-server
docker-build: ## build latest version locally
docker buildx build -f Dockerfile -t adrianrudnik/mjml-server --load .

docker-release: DOCKER_CLI_EXPERIMENTAL=enabled
docker-release: ## build latest tag version and publish
# read latest version tag from local git for release
$(eval TAGV=$(GET_LAST_TAGV))
# build and publish multiarch
docker buildx build -f Dockerfile --platform linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7,linux/ppc64le -t adrianrudnik/mjml-server:testx -t adrianrudnik/mjml-server:test-${TAGV} --push .

npm-upgrade:
npm install -g npm-check-updates
ncu -u

help: ## Print all possible targets
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Due to GDPR / DSGVO reasons I required the mjml instance to be under my own cont
Starting the image is as easy as running a test instance through docker

```sh
docker run -it --rm -p 8889:80 mjml-server
docker run -it --rm -p 8080:80 mjml-server
```

or `docker-compose` with the following example:
Expand Down Expand Up @@ -107,3 +107,23 @@ spec:
```

Be aware that this does only check the connectivity and that the port might vary. If you want a functional check as well, you could shift to an approach like the ones used for docker with the result of the [healthcheck.sh](healthcheck.sh). But I'm not a kubernetes user, so feel free to do a pull request if you have a slim approach.

### Docker

If you want to rely on the Makefile or build for multiple architectures, ensure you have the experimental features activated for Docker and you can use [docker buildx](https://docs.docker.com/buildx/working-with-buildx/).

Setup on my Ubuntu 20.04 workstation was as follows, based on the docs mentioned above:

```bash
# Install additional platforms for the default node on the current host linux os
docker run --privileged --rm tonistiigi/binfmt --install all

# create a separate endpoint that uses the default node
docker buildx create --use mjml-server default

# After that a local build should be possible with something like
docker buildx build -f Dockerfile --platform linux/amd64,linux/arm64 -t [registry-and-tag] --push .

# ... or if you want to use it locally with the mjml-server tag
docker buildx build -f Dockerfile --platform linux/amd64,linux/arm64 -t mjml-server --load .
```
Loading

0 comments on commit 5ceba75

Please sign in to comment.