From 73a854e9d121a22b040ff88a126ba00bd30e0f30 Mon Sep 17 00:00:00 2001 From: Chetan Sarva Date: Mon, 22 Nov 2021 15:09:48 -0500 Subject: [PATCH] feat: create docker images for standalone use (#793) --- .dockerignore | 6 +++++ .github/workflows/on_push.yaml | 1 - .github/workflows/on_tag.yaml | 20 +++++++++++++++ docker/00-check-config.sh | 8 ++++++ docker/Dockerfile | 21 +++++++++++++++ docker/Dockerfile.build | 17 ++++++++++++ docker/Dockerfile.run | 7 +++++ docker/README.md | 47 ++++++++++++++++++++++++++++++++++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100755 docker/00-check-config.sh create mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.build create mode 100644 docker/Dockerfile.run create mode 100644 docker/README.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c2b31c53 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git/ +.github/ +.gitignore +docker/Dockerfile* +docker/README.md +node_modules/ diff --git a/.github/workflows/on_push.yaml b/.github/workflows/on_push.yaml index 92ba0973..2dd0d01f 100644 --- a/.github/workflows/on_push.yaml +++ b/.github/workflows/on_push.yaml @@ -13,7 +13,6 @@ jobs: name: Lint and Build runs-on: ubuntu-latest steps: - - name: Checkout code uses: actions/checkout@v2 diff --git a/.github/workflows/on_tag.yaml b/.github/workflows/on_tag.yaml index 3534a9b9..66f5f0cf 100644 --- a/.github/workflows/on_tag.yaml +++ b/.github/workflows/on_tag.yaml @@ -48,3 +48,23 @@ jobs: release_url: https://github.com/resoai/TileBoard/releases/tag/v${{ steps.get-version.outputs.version }} env: GITHUB_TOKEN: ${{ secrets.REPO_WORKFLOW_TOKEN }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Docker build + run: | + docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 \ + --pull \ + -t tileboard/tileboard:latest \ + -t tileboard/tileboard:${{ steps.get-version.outputs.version }} \ + -f docker/Dockerfile.run \ + --push \ + . diff --git a/docker/00-check-config.sh b/docker/00-check-config.sh new file mode 100755 index 00000000..1b05e6b6 --- /dev/null +++ b/docker/00-check-config.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +NGINX_HOME=/usr/share/nginx/html + +if [ ! -f $NGINX_HOME/config.js ]; then + echo "error: $NGINX_HOME/config.js not found" + exit 1 +fi diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..2e344962 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,21 @@ +FROM node:16 AS builder + +RUN mkdir -p /build +WORKDIR /build + +COPY ./package.json yarn.lock /build/ + +RUN yarn install + +COPY ./ /build + +RUN yarn run build + + +# Runtime image +FROM nginx:alpine AS runtime + +COPY ./docker/00-check-config.sh /docker-entrypoint.d/ +COPY --from=builder /build/build /usr/share/nginx/html + +RUN touch /usr/share/nginx/html/styles/custom.css diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build new file mode 100644 index 00000000..173a60a7 --- /dev/null +++ b/docker/Dockerfile.build @@ -0,0 +1,17 @@ +FROM node:16 AS builder + +RUN mkdir -p /build +WORKDIR /build + +COPY ./package.json yarn.lock /build/ + +RUN yarn install + +COPY ./ /build + +RUN yarn run build + + +# Hack for easily copying built files +FROM scratch AS exporter +COPY --from=builder /build/build . diff --git a/docker/Dockerfile.run b/docker/Dockerfile.run new file mode 100644 index 00000000..3c323bd5 --- /dev/null +++ b/docker/Dockerfile.run @@ -0,0 +1,7 @@ +# Runtime image +FROM nginx:alpine AS runtime + +COPY ./docker/00-check-config.sh /docker-entrypoint.d/ +COPY ./build /usr/share/nginx/html + +RUN touch /usr/share/nginx/html/styles/custom.css diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..8319802f --- /dev/null +++ b/docker/README.md @@ -0,0 +1,47 @@ +# Running with Docker + +1. Download the [sample +config](https://raw.githubusercontent.com/resoai/TileBoard/master/config.example.js) +file to `config.js` and edit it. + + ```sh + wget -O config.js https://raw.githubusercontent.com/resoai/TileBoard/master/config.example.js + vim config.js + ``` + +2. Copy the following to `docker-compose.yml`: + + ```yaml + version: '2' + services: + tileboard: + image: tileboard/tileboard:latest + restart: unless-stopped + ports: + - 9000:80 + volumes: + - ./config.js:/usr/share/nginx/html/config.js + ``` + +3. Run with `docker-compose up --detach` +4. Access at http://localhost:9000 + +## Building + +```sh +docker build -t tileboard/tileboard -f docker/Dockerfile . +``` + +Multi-platform: + +```sh +rm -rf ./build/ +docker buildx build -t tileboard/tileboard:build -f docker/Dockerfile.build --output build . +docker buildx build \ + --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ + --pull \ + -t tileboard/tileboard:latest \ + -f docker/Dockerfile.run \ + --push \ + . +```