From d7c697d42c5205a453ca1f2599c076f6abc3d2d0 Mon Sep 17 00:00:00 2001 From: Dieter Schmidt Date: Tue, 5 Jan 2021 02:27:33 +0100 Subject: [PATCH] feat: add Dockerfile & Github workflow --- .github/workflows/multiarch_dockerhub.yml | 66 +++++++++++++++++++++++ docs/docker/Dockerfile | 21 ++++++++ docs/docker/client.conf | 38 +++++++++++++ docs/docker/common_vars.conf | 4 ++ docs/docker/upstreams.conf.template | 4 ++ 5 files changed, 133 insertions(+) create mode 100644 .github/workflows/multiarch_dockerhub.yml create mode 100644 docs/docker/Dockerfile create mode 100644 docs/docker/client.conf create mode 100644 docs/docker/common_vars.conf create mode 100644 docs/docker/upstreams.conf.template diff --git a/.github/workflows/multiarch_dockerhub.yml b/.github/workflows/multiarch_dockerhub.yml new file mode 100644 index 0000000000..3de4f2c7e8 --- /dev/null +++ b/.github/workflows/multiarch_dockerhub.yml @@ -0,0 +1,66 @@ +name: Build and Push Multiarch Docker image for Dockerhub + +on: + push: + branches: + - master + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prepare + id: prep + run: | + DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/fluidd + VERSION=latest + SHORTREF=${GITHUB_SHA::8} + + # If this is git tag, use the tag name as a docker tag + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/v} + fi + TAGS="${DOCKER_IMAGE}:${VERSION}" + + # If the VERSION looks like a version number, assume that + # this is the most recent version of the image and also + # tag it 'latest'. + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + TAGS="$TAGS,${DOCKER_IMAGE}:latest" + fi + + # Set output parameters. + echo ::set-output name=tags::${TAGS} + echo ::set-output name=docker_image::${DOCKER_IMAGE} + echo ::set-output name=git_tag::${VERSION} + + - name: Set up QEMU + uses: docker/setup-qemu-action@master + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@master + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + context: docs/docker + file: docs/docker/Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ steps.prep.outputs.tags }} + build-args: | + FRONTEND_ZIP_URL=https://github.com/cadriel/fluidd/releases/${{ steps.prep.outputs.git_tag }}/download/fluidd.zip diff --git a/docs/docker/Dockerfile b/docs/docker/Dockerfile new file mode 100644 index 0000000000..4e3c95a003 --- /dev/null +++ b/docs/docker/Dockerfile @@ -0,0 +1,21 @@ +FROM debian as unzip + +ARG FRONTEND_ZIP_URL=https://github.com/cadriel/fluidd/releases/latest/download/fluidd.zip + +ARG DEBIAN_FRONTEND=noninteractive +WORKDIR /frontend + +ADD ${FRONTEND_ZIP_URL} /tmp/frontend.zip +RUN apt-get update && apt-get install -y unzip +RUN unzip /tmp/frontend.zip -d /frontend + +FROM nginx:alpine as image + +ENV JPEG_STREAM_HOST localhost +ENV JPEG_STREAM_PORT 8080 + +ADD --chown=101:101 common_vars.conf /etc/nginx/conf.d/common_vars.conf +COPY --chown=101:101 upstreams.conf.template /etc/nginx/templates/upstreams.conf.template +COPY --chown=101:101 client.conf /etc/nginx/conf.d/default.conf +COPY --from=unzip --chown=101:101 /frontend /usr/share/nginx/html +EXPOSE 80 diff --git a/docs/docker/client.conf b/docs/docker/client.conf new file mode 100644 index 0000000000..f47ae9a626 --- /dev/null +++ b/docs/docker/client.conf @@ -0,0 +1,38 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + # disable this section on smaller hardware like a pi zero + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_proxied expired no-cache no-store private auth; + gzip_comp_level 4; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml; + + # web_path from fluidd static files + root /usr/share/nginx/html; + + index index.html; + server_name _; + + # max upload size for gcode files + client_max_body_size 500M; + + location / { + try_files $uri $uri/ /index.html; + } + + location = /index.html { + add_header Cache-Control "no-store, no-cache, must-revalidate"; + } + + location /webcam/ { + proxy_pass http://mjpgstreamer/; + } +} diff --git a/docs/docker/common_vars.conf b/docs/docker/common_vars.conf new file mode 100644 index 0000000000..0cc431c4f6 --- /dev/null +++ b/docs/docker/common_vars.conf @@ -0,0 +1,4 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} diff --git a/docs/docker/upstreams.conf.template b/docs/docker/upstreams.conf.template new file mode 100644 index 0000000000..3a08e5a0fb --- /dev/null +++ b/docs/docker/upstreams.conf.template @@ -0,0 +1,4 @@ +upstream mjpgstreamer { + ip_hash; + server ${JPEG_STREAM_HOST}:${JPEG_STREAM_PORT}; +}