-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: dockerize the app * Update .github/workflows/docker.yml Co-authored-by: Marek Grzelak <[email protected]> * Address review comments * Address review comments --------- Co-authored-by: Marek Grzelak <[email protected]>
- Loading branch information
Showing
19 changed files
with
336 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Dockerfile | ||
db.sqlite3 | ||
docker-compose.dev.yml | ||
docker-compose.yml | ||
nginx/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
DEBUG=1 | ||
SQL_ENGINE=django.db.backends.postgresql | ||
SQL_DATABASE=kcc3 | ||
SQL_USER=kcc3 | ||
SQL_PASSWORD=kcc3 | ||
SQL_HOST=db | ||
SQL_PORT=5432 | ||
POSTGRES_USER=kcc3 | ||
POSTGRES_PASSWORD=kcc3 | ||
POSTGRES_DB=kcc3 | ||
CELERY_BROKER=amqp://guest:guest@rabbitmq:5672// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DEBUG=0 | ||
SECRET_KEY=CHANGE_ME | ||
DJANGO_ALLOWED_HOSTS=fanpai.chombo.club,yakuman.chombo.club | ||
SQL_DATABASE=kcc3 | ||
SQL_USER=kcc3 | ||
SQL_PASSWORD=CHANGE_ME | ||
SQL_HOST=db | ||
SQL_PORT=5432 | ||
POSTGRES_USER=kcc3 | ||
POSTGRES_PASSWORD=CHANGE_ME | ||
POSTGRES_DB=kcc3 | ||
CELERY_BROKER=amqp://guest:guest@rabbitmq:5672// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: Docker Images | ||
|
||
on: | ||
push: | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-web: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/riichi/kcc3-web | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
build-and-push-proxy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/riichi/kcc3-proxy | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: nginx/ | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,6 @@ coverage.xml | |
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
celerybeat.pid | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM python:3.11-slim-bookworm | ||
|
||
RUN mkdir -p /app/web | ||
WORKDIR /app/web | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN apt-get update && \ | ||
apt-get -y upgrade && \ | ||
apt-get install -y netcat-openbsd zlib1g-dev libjpeg-dev gcc | ||
|
||
RUN pip install --upgrade pip | ||
COPY ./requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
ENV MEDIA_ROOT /app/media | ||
ENV STATIC_ROOT /app/static | ||
|
||
EXPOSE 8000 | ||
ENTRYPOINT ["/app/web/entrypoint.sh"] | ||
CMD ["gunicorn", "kcc3.wsgi:application", "--bind", "0.0.0.0:8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
x-env: | ||
&env-file | ||
- ./.env.dev | ||
|
||
services: | ||
web: | ||
build: | ||
context: . | ||
container_name: kcc3_web | ||
volumes: | ||
- static_volume:/app/static | ||
- media_volume:/app/media | ||
depends_on: | ||
- db | ||
- beat | ||
env_file: *env-file | ||
|
||
worker: | ||
build: | ||
context: . | ||
container_name: kcc3_worker | ||
command: celery -A kcc3 worker --loglevel=info | ||
depends_on: | ||
- db | ||
- rabbitmq | ||
env_file: *env-file | ||
|
||
beat: | ||
build: | ||
context: . | ||
container_name: kcc3_beat | ||
command: celery -A kcc3 beat -S django --loglevel=info | ||
depends_on: | ||
- db | ||
- rabbitmq | ||
- worker | ||
env_file: *env-file | ||
|
||
db: | ||
image: postgres:16 | ||
container_name: kcc3_db | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data/ | ||
env_file: *env-file | ||
|
||
rabbitmq: | ||
image: rabbitmq:3 | ||
container_name: kcc3_rabbitmq | ||
|
||
proxy: | ||
build: ./nginx | ||
container_name: kcc3_proxy | ||
volumes: | ||
- static_volume:/app/static | ||
- media_volume:/app/media | ||
ports: | ||
- 8000:80 | ||
depends_on: | ||
- web | ||
|
||
volumes: | ||
postgres_data: | ||
static_volume: | ||
media_volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
x-env: | ||
&env-file | ||
- ./.env.prod | ||
|
||
services: | ||
web: | ||
image: ghcr.io/riichi/kcc3-web:master | ||
container_name: kcc3_web | ||
volumes: | ||
- ./static_files:/app/static | ||
- ./media_files:/app/media | ||
depends_on: | ||
- db | ||
- beat | ||
env_file: *env-file | ||
|
||
worker: | ||
image: ghcr.io/riichi/kcc3-web:master | ||
container_name: kcc3_worker | ||
command: celery -A kcc3 worker --loglevel=info | ||
depends_on: | ||
- db | ||
- rabbitmq | ||
env_file: *env-file | ||
|
||
beat: | ||
image: ghcr.io/riichi/kcc3-web:master | ||
container_name: kcc3_beat | ||
command: celery -A kcc3 beat -S django --loglevel=info | ||
depends_on: | ||
- db | ||
- rabbitmq | ||
- worker | ||
env_file: *env-file | ||
|
||
db: | ||
image: postgres:16 | ||
container_name: kcc3_db | ||
volumes: | ||
- ./pgdata:/var/lib/postgresql/data/ | ||
env_file: *env-file | ||
|
||
rabbitmq: | ||
image: rabbitmq:3 | ||
container_name: kcc3_rabbitmq | ||
|
||
proxy: | ||
image: ghcr.io/riichi/kcc3-proxy:master | ||
container_name: kcc3_proxy | ||
volumes: | ||
- ./static_files:/app/static | ||
- ./media_files:/app/media | ||
ports: | ||
- 8000:80 | ||
depends_on: | ||
- web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
if [ "$SQL_ENGINE" = "django.db.backends.postgresql" ] | ||
then | ||
echo "Waiting for postgres..." | ||
|
||
while ! nc -z "$SQL_HOST" "$SQL_PORT"; do | ||
sleep 0.1 | ||
done | ||
|
||
echo "PostgreSQL started" | ||
fi | ||
|
||
python manage.py migrate --noinput | ||
python manage.py collectstatic --no-input --clear | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from .base import * | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'CHANGE_ME') | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = bool(os.environ.get('DEBUG', default=0)) | ||
|
||
ALLOWED_HOSTS = os.environ.get( | ||
'DJANGO_ALLOWED_HOSTS', | ||
'fanpai.localhost,yakuman.localhost,localhost' | ||
).split(',') | ||
PARENT_HOST = os.environ.get('DJANGO_PARENT_HOST', 'localhost:8000') | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': os.environ.get('SQL_ENGINE', 'django.db.backends.sqlite3'), | ||
'NAME': os.environ.get('SQL_DATABASE', os.path.join(BASE_DIR, 'db.sqlite3')), | ||
'USER': os.environ.get('SQL_USER', None), | ||
'PASSWORD': os.environ.get('SQL_PASSWORD', None), | ||
'HOST': os.environ.get('SQL_HOST', None), | ||
'PORT': os.environ.get('SQL_PORT', None), | ||
} | ||
} | ||
|
||
|
||
MEDIA_ROOT = os.environ.get('MEDIA_ROOT', os.path.join(BASE_DIR, 'media')) | ||
MEDIA_URL = '/media/' | ||
STATIC_ROOT = os.environ.get('STATIC_ROOT', os.path.join(BASE_DIR, 'static')) | ||
|
||
CELERY_BROKER_URL = os.environ.get( | ||
'CELERY_BROKER', 'amqp://guest:guest@localhost:5672//') |
Oops, something went wrong.