Skip to content

Commit

Permalink
feat: add Dockerfile & Github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dimalo authored and cadriel committed Jan 8, 2021
1 parent b556f46 commit d7c697d
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/multiarch_dockerhub.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions docs/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions docs/docker/client.conf
Original file line number Diff line number Diff line change
@@ -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/;
}
}
4 changes: 4 additions & 0 deletions docs/docker/common_vars.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
4 changes: 4 additions & 0 deletions docs/docker/upstreams.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
upstream mjpgstreamer {
ip_hash;
server ${JPEG_STREAM_HOST}:${JPEG_STREAM_PORT};
}

0 comments on commit d7c697d

Please sign in to comment.