Rework of Dockerfile and multiarch build with workflows (#23)

This commit is contained in:
George V 2020-08-31 00:30:17 +03:00 committed by GitHub
parent 6f165aff43
commit 696b20cd91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 103 additions and 130 deletions

63
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,63 @@
name: Build Apprise API image
on:
push:
branches: container-rework
tags:
- v*
jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Prepare
id: prepare
run: |
DOCKER_IMAGE=georgegedox/apprise-api
DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="--tag ${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg VCS_REF=${GITHUB_SHA::8} \
${TAGS} .
-
name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
-
name: Docker Buildx (build)
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
-
name: Login to DockerHub
if: success() && github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Docker Buildx (push)
if: success() && github.event_name != 'pull_request'
run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}
-
name: Inspect image
if: always() && github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}

View File

@ -1,5 +1,5 @@
# Use the standard Nginx image from Docker Hub
FROM nginx
ARG ARCH
FROM ${ARCH}python:3.8-slim
# set version label
ARG BUILD_DATE
@ -12,28 +12,23 @@ ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV APPRISE_CONFIG_DIR /config
# Install Python Dependencies
COPY ./requirements.txt etc/requirements.txt
# Install requirements and gunicorn
COPY ./requirements.txt /etc/requirements.txt
RUN pip3 install -r /etc/requirements.txt gunicorn
# Install Python
# Install nginx and supervisord
RUN apt-get update && \
apt-get install -y curl python3 python3-pip && \
pip3 install -r etc/requirements.txt gunicorn
apt-get install -y nginx supervisor
# Install s6-overlay
RUN curl -fL -o /tmp/s6-overlay.tar.gz \
https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-amd64.tar.gz \
&& tar -xzf /tmp/s6-overlay.tar.gz -C / \
&& rm -rf /tmp/*
ENV S6_KEEP_ENV=1 \
S6_CMD_WAIT_FOR_SERVICES=1
# Nginx configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY /etc/nginx.conf /etc/nginx/conf.d/nginx.conf
# Copy our static content in place
COPY apprise_api/static /usr/share/nginx/html/s/
# System Configuration
COPY etc /etc/
# Supervisor configuration
COPY /etc/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# set work directory
WORKDIR /opt/apprise
@ -41,16 +36,10 @@ WORKDIR /opt/apprise
# Copy over Apprise API
COPY apprise_api/ webapp
# gunicorn to expose on port 8080
# nginx to expose on port 8000
# disable logging on gunicorn
RUN \
sed -i -e 's/backend:8000/localhost:8080/g' \
-e 's/listen\([ \t]\+\)[^;]\+;/listen\18000;/g' \
/etc/nginx/conf.d/default.conf && \
sed -i -e 's/:8000/:8080/g' /opt/apprise/webapp/gunicorn.conf.py
# Change port of gunicorn
RUN sed -i -e 's/:8000/:8080/g' /opt/apprise/webapp/gunicorn.conf.py
EXPOSE 8000
VOLUME /config
ENTRYPOINT ["/init"]
CMD ["/usr/bin/supervisord"]

View File

@ -1,22 +0,0 @@
# pull official base image
FROM python:3.8.0-alpine
# set work directory
WORKDIR /opt/apprise
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV APPRISE_CONFIG_DIR /var/apprise/config
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt etc/requirements.txt
RUN pip install -r etc/requirements.txt \
gunicorn
# copy project
COPY apprise_api/ webapp
EXPOSE 8000
CMD ["gunicorn", "-c", "/opt/apprise/webapp/gunicorn.conf.py", "core.wsgi"]

View File

@ -1,8 +0,0 @@
# pull official base image
FROM nginx
# Copy our customized NginX configuration (for container usage)
COPY etc/nginx /etc/nginx/
# Copy our static content in place
COPY apprise_api/static /usr/share/nginx/html/s/

View File

@ -1,19 +1,8 @@
version: '3.3'
version: '3'
services:
backend:
build:
context: .
dockerfile: Dockerfile-gunicorn
volumes:
- ./var:/var/apprise
restart: always
frontend:
build:
context: .
dockerfile: Dockerfile-nginx
apprise:
build: .
container_name: apprise
ports:
- "8000:80"
links:
- backend
- 8000:8000

View File

@ -1,13 +1,5 @@
# The backend API server
upstream apprise_backend {
server backend:8000 fail_timeout=0;
}
server {
listen 80;
server_name _;
charset utf-8;
listen 8000;
# Main Website
location / {
@ -16,7 +8,7 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://apprise_backend;
proxy_pass http://localhost:8080;
# Give ample time for notifications to fire
proxy_read_timeout 120s;
}
@ -35,4 +27,4 @@ server {
location = /50x.html {
root /usr/share/nginx/html;
}
}
}

View File

@ -1,31 +0,0 @@
#
# Apprise Docker NginX Configuration
#
error_log /dev/stdout info;
user nginx;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
include /etc/nginx/conf.d/*.conf;
}

View File

@ -1,5 +0,0 @@
#!/usr/bin/env sh
echo >&2 "gunicorn exited. code=${1}"
# terminate other services to exit from the container
exec s6-svscanctl -t /var/run/s6/services

View File

@ -1,3 +0,0 @@
#!/usr/bin/with-contenv sh
echo >&2 "Starting gunicorn"
exec gunicorn -c /opt/apprise/webapp/gunicorn.conf.py --worker-tmp-dir /dev/shm core.wsgi

View File

@ -1,5 +0,0 @@
#!/usr/bin/env sh
echo >&2 "nginx exited. code=${1}"
# terminate other services to exit from the container
exec s6-svscanctl -t /var/run/s6/services

View File

@ -1,3 +0,0 @@
#!/usr/bin/with-contenv sh
echo >&2 "Starting nginx"
nginx -g 'daemon off;'

17
etc/supervisord.conf Normal file
View File

@ -0,0 +1,17 @@
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:gunicorn]
command=gunicorn -c /opt/apprise/webapp/gunicorn.conf.py --worker-tmp-dir /dev/shm core.wsgi
directory=/opt/apprise/webapp
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0