Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiarch Docker support and improved Compose #54

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
**/.git
**/archive
**/static
**/logs
**/db
**/tmp
.git
.vscode
.mypy_cache
archive
static
logs
db
tmp
docker.env
buildx.sh
Dockerfile
Makefile
docker-compose.yml
nginx.conf
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ static/nltk_data/
db/
logs/
tmp/
static/admin/
static/rest_framework/
.vscode
.mypy_cache
26 changes: 15 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
From python:3.6-slim-stretch
FROM python:3.6-alpine3.12

WORKDIR /usr/src/reminiscence

RUN apt-get update \
&& apt-get install --no-install-recommends -y chromium netcat wget \
&& wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb \
&& apt-get install -y ./wkhtmltox_0.12.5-1.stretch_amd64.deb \
&& rm ./wkhtmltox_0.12.5-1.stretch_amd64.deb \
&& rm -rf /var/lib/apt/lists/*
RUN apk add --no-cache \
gcc=9.3.0-r2 \
libxslt-dev=1.1.34-r0 \
libxml2-dev=2.9.10-r5 \
musl-dev=1.1.24-r9 \
postgresql-dev=12.4-r0 \
wkhtmltopdf=0.12.5-r1

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . /usr/src/reminiscence
COPY . .

RUN mkdir -p logs archive tmp \
&& python manage.py applysettings --docker yes \
&& python manage.py generatesecretkey
RUN mkdir -p logs archive tmp

RUN python manage.py applysettings --docker yes
RUN python manage.py generatesecretkey

ENTRYPOINT [ "./entrypoint.sh" ]
31 changes: 0 additions & 31 deletions Dockerfile.armv7l

This file was deleted.

2 changes: 0 additions & 2 deletions Dockerfile.nginx

This file was deleted.

18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
REPO_OWNER:='reminiscence'
MULTIARCH:=false
ARCHS:=linux/amd64
ifeq ($(MULTIARCH), true)
ARCHS:=linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x,linux/386
endif
VERSION:='latest'

all: setup build

setup:
@./buildx.sh
clean:
@sudo rm -rf logs db archive static/admin static/rest_framework
build: clean
docker buildx build $(ENV) \
--platform $(ARCHS) \
--push --tag $(REPO_OWNER)/reminiscence:$(VERSION) .
29 changes: 29 additions & 0 deletions buildx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
export DOCKER_CLI_EXPERIMENTAL=enabled
export DOCKER_BUILDKIT=1

docker build --platform=local -o . git://github.com/docker/buildx
mkdir -p ~/.docker/cli-plugins
mv buildx ~/.docker/cli-plugins/docker-buildx
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --name builder --driver docker-container --use

# https://github.com/docker/docker-ce/blob/master/components/cli/experimental/README.md
sudo printf "{\n\
\t\"experimental\": true\n\
}\n" | sudo tee /etc/docker/daemon.json

SHELL_RC="/dev/null"

if [[ "zsh" == $SHELL ]]; then
SHELL_RC="/.zshrc"
fi
if [[ "bash" == $SHELL ]]; then
SHELL_RC="/.bashrc"
fi

printf "\n\
# Docker's buildx support\n\
export DOCKER_CLI_EXPERIMENTAL=enabled\n\
export DOCKER_BUILDKIT=1\n\
" >> $HOME$SHELL_RC
10 changes: 2 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@ version: '3'

services:
nginx:
build:
context: .
dockerfile: Dockerfile.nginx
image: nginx
volumes:
- .:/usr/src/reminiscence
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
depends_on:
- web

web:
build: .
command: bash -c "while ! nc -w 1 -z db 5432; do sleep 0.1; done; python manage.py migrate; python manage.py createdefaultsu; python manage.py collectstatic --no-input; if [ ! -d '/usr/src/reminiscence/static/nltk_data' ]; then echo 'wait..downloading..nltk_data'; python manage.py nltkdownload; fi; gunicorn --max-requests 1000 --worker-class gthread --workers 4 --thread 10 --timeout 300 --bind 0.0.0.0:8000 reminiscence.wsgi"
env_file:
- ./docker.env
ports:
- "8000:8000"
volumes:
- ./static:/usr/src/reminiscence/static/
- ./archive:/usr/src/reminiscence/archive/
- ./logs:/usr/src/reminiscence/logs/
depends_on:
- db

Expand Down
1 change: 1 addition & 0 deletions docker.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
DB_HOST=db
14 changes: 14 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
while ! nc -w 1 -z ${DB_HOST} 5432; do sleep 0.1; done;
python manage.py migrate;
python manage.py createdefaultsu;
python manage.py collectstatic --no-input;
if [ ! -d '/usr/src/reminiscence/static/nltk_data' ]; then
echo 'wait..downloading..nltk_data';
python manage.py nltkdownload;
fi;
gunicorn --max-requests 1000 \
--worker-class gthread \
--workers 4 --thread 10 \
--timeout 300 \
--bind 0.0.0.0:8000 reminiscence.wsgi
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kombu==4.2.1
lxml==4.2.4
multidict==4.3.1
nltk==3.4.5
psycopg2==2.7.5
psycopg2-binary==2.8.6
pytz==2018.5
readability-lxml==0.7
redis==2.10.6
Expand Down