-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerfile splitted into server and worker targets 😯
- Loading branch information
Showing
11 changed files
with
207 additions
and
30 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
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,75 @@ | ||
name: Docker | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
# Publish semver tags as releases. | ||
tags: [ '*.*.*' ] | ||
|
||
env: | ||
# Use docker.io for Docker Hub if empty | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: ${{ github.repository }}-worker | ||
DOCKER_BUILDKIT: 1 | ||
|
||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Install poetry | ||
run: | | ||
sudo apt install -y pipx | ||
pipx ensurepath | ||
pipx install poetry | ||
pipx inject poetry poetry-plugin-export | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Create requirements.txt | ||
run: | | ||
poetry export -f requirements.txt --without-hashes --output requirements.txt | ||
# Login against a Docker registry except on PR | ||
# https://github.com/docker/login-action | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
# https://github.com/docker/metadata-action | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
# Build and push Docker image with Buildx (don't push on PR) | ||
# https://github.com/docker/build-push-action | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
target: worker |
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,49 @@ | ||
name: dbs-tester | ||
|
||
services: | ||
server: | ||
build: | ||
context: . | ||
target: server | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
- private_volume:/usr/local/app/private | ||
environment: | ||
DATABASE_HOST: ${DATABASE_HOST} | ||
DATABASE_NAME: ${DATABASE_NAME} | ||
DATABASE_PASSWORD: ${DATABASE_PASSWORD} | ||
DATABASE_PORT: ${DATABASE_PORT} | ||
DATABASE_USER: ${DATABASE_USER} | ||
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE} | ||
GITHUB_TOKEN: ${GITHUB_TOKEN} | ||
GITHUB_USER: ${GITHUB_USER} | ||
REDIS_HOST: ${REDIS_HOST} | ||
SECRET_KEY: ${SECRET_KEY} | ||
ports: | ||
- 8000:9000 | ||
worker: | ||
build: | ||
context: . | ||
target: worker | ||
volumes: | ||
- /var/run/docker.sock:/var/run/docker.sock | ||
environment: | ||
DATABASE_HOST: ${DATABASE_HOST} | ||
DATABASE_NAME: ${DATABASE_NAME} | ||
DATABASE_PASSWORD: ${DATABASE_PASSWORD} | ||
DATABASE_PORT: ${DATABASE_PORT} | ||
DATABASE_USER: ${DATABASE_USER} | ||
DJANGO_SETTINGS_MODULE: ${DJANGO_SETTINGS_MODULE} | ||
GITHUB_TOKEN: ${GITHUB_TOKEN} | ||
GITHUB_USER: ${GITHUB_USER} | ||
REDIS_HOST: ${REDIS_HOST} | ||
SECRET_KEY: ${SECRET_KEY} | ||
scale: 4 | ||
depends_on: | ||
- server | ||
networks: | ||
intranet: | ||
name: dbs | ||
external: true | ||
volumes: | ||
private_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,14 @@ | ||
#!/bin/sh | ||
|
||
until PGPASSWORD=$DATABASE_PASSWORD psql -h "$DATABASE_HOST" -U "$DATABASE_USER" -c '\q'; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
python3 manage.py collectstatic --no-input | ||
python3 manage.py migrate | ||
python3 manage.py setup | ||
|
||
echo "$GITHUB_TOKEN" | docker login ghcr.io -u $GITHUB_USER --password-stdin | ||
|
||
supervisord -c /etc/supervisor/supervisord.conf |
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,10 @@ | ||
#!/bin/sh | ||
|
||
until PGPASSWORD=$DATABASE_PASSWORD psql -h "$DATABASE_HOST" -U "$DATABASE_USER" -c '\q'; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
echo "$GITHUB_TOKEN" | docker login ghcr.io -u $GITHUB_USER --password-stdin | ||
|
||
python3 manage.py rqworker default |
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 @@ | ||
#!/bin/bash | ||
|
||
RUNNING_WORKER_PROCESS_COUNT=$(pgrep -f ".*rq" --count) | ||
|
||
echo "$RUNNING_WORKER_PROCESS_COUNT/$WORKER_PROCESS_COUNT processes running " | ||
|
||
if [ ${RUNNING_WORKER_PROCESS_COUNT} == ${WORKER_PROCESS_COUNT} ] | ||
then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi |