Skip to content

Commit

Permalink
feat(DOCKER): split docker compose config for better managment (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
The0zzy authored Oct 19, 2023
2 parents 3038c2c + 62c3b28 commit ed5f8ab
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Docker Build
name: Build Docker Image

on:
workflow_dispatch:
pull_request:
branches:
- none
push:
branches:
- main
Expand Down Expand Up @@ -54,3 +51,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
file: './docker/dockerfile'
33 changes: 13 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,37 @@ If you're not familiar with Django or Wagtail, it might be good to start with [w

You need to install the following applications on your system

- [Python](https://www.python.org/downloads/)
- [NodeJS / npm package manager](https://nodejs.org/en/download)
- [Python](https://www.python.org/downloads/) [^3.11]
- [Docker](https://www.docker.com)

### Setup
## Todo
- [ ] docker `pre-commit` hooks in docker environment
- all hooks except `commit-msg-validator` are working.

- Create a Python Virtual Environment and activate it
### Setup
- Clone in repo and cd into it
```
py -m venv ./python-venvs/bfportal
./python-venvs/bfportal/Scripts/activate
git clone https://gh.bfportal.gg/
```
- Install [poetry](https://python-poetry.org/docs/#installation) for dependency management
```
curl -sSL https://install.python-poetry.org | python3 -
```
- Install python dependencies
- Install project dependencies
```
cd bfportal.gg
poetry install
```
- Install the pre-commit hooks by running
```
pre-commit install --install-hooks
```
- Install npm dependencies
```
cd bfportal.gg/bfportal
npm install
```

- Copy the `.env.template` file to `.env`
- (optional) Create a [discord application](https://discord.com/developers/applications) for OAuth2 and copy the client id and secret
- Paste the client id and secret in `.env` file to `DISCORD_CLIENT_ID` and `DISCORD_SECRET` respectively
- From the repositories root directory build the necessary docker images and run the platform
```
docker-compose --profile dev_local up
docker-compose up
```
- The website should become available at `127.0.0.1:8000`

Expand All @@ -115,17 +111,14 @@ You need to install the following applications on your system

You need to install the following applications on your system

- [Python](https://www.python.org/downloads/)
- [Python](https://www.python.org/downloads/) [^3.11]
- [NodeJS / npm package manager](https://nodejs.org/en/download)
- [PostgreSQL](https://www.postgresql.org/)

### Setup

- Create a Python Virtual Environment and activate it
```
py -m venv ./python-venvs/bfportal
./python-venvs/bfportal/Scripts/activate
```
<!-- no need to create venv as poetry will create one -->

- Install [poetry](https://python-poetry.org/docs/#installation) for dependency management
```
curl -sSL https://install.python-poetry.org | python3 -
Expand Down
9 changes: 9 additions & 0 deletions bfportal/core/management/commands/playground.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pathlib import Path

from django.core.management import BaseCommand
from loguru import logger


class Command(BaseCommand):
def handle(self, *args, **options):
logger.debug("This is a command to be used as a playground")
145 changes: 10 additions & 135 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,131 +2,12 @@ version: "3.7"

services:

# Production environment services
db:
image: postgres:14
restart: always
profiles:
- production
volumes:
- postgress_db:/var/lib/postgresql/data

environment:
- POSTGRES_NAME=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: "10s"
timeout: "5s"
retries: 5
start_period: "10s"

bfportal_gg_production:
image: docker.pkg.github.com/battlefield-portal-community/bfportal.gg/main:latest
restart: always
command: bash -c "python manage.py migrate --noinput && python manage.py ensure_superuser --username bfportal --email [email protected] --password '${SU_PASSWD}' && python manage.py ensure_initialization && gunicorn --workers 4 --bind 0.0.0.0:${PRODUCTION_PORT}"
user: "33:33"
profiles:
- production
ports:
- "${PRODUCTION_PORT}:${PRODUCTION_PORT}"
volumes:
- type: "bind"
source: /var/www/bfportal-media
target: /app/media
environment:
- PRODUCTION_KEY=${PRODUCTION_KEY}
- DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID}
- DISCORD_SECRET=${DISCORD_SECRET}
- DB_NAME=${DB_NAME}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- POSTGRES_HOST=db # takes precedent over .env file
- DEBUG=${DEBUG}
- APPROVAL_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_CHANNEL_WEBHOOK_ID=${APPROVAL_CHANNEL_WEBHOOK_ID}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID}
- PRODUCTION_HOST=${PRODUCTION_HOST}
- PRODUCTION_PORT=${PRODUCTION_PORT}
- OWNERS=${OWNERS}
depends_on:
- db
healthcheck:
test: curl -fk http://0.0.0.0:${PRODUCTION_PORT}/ || exit 1
interval: "60s"
timeout: "3s"
retries: 3
start_period: "5s"

# Dev environment services (on remote server)
db_devel:
image: postgres:14
restart: always
profiles:
- dev
volumes:
- postgress_db_devel:/var/lib/postgresql/data

environment:
- POSTGRES_NAME=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: "10s"
timeout: "5s"
retries: 5
start_period: "10s"

bfportal_gg_dev:
image: docker.pkg.github.com/battlefield-portal-community/bfportal.gg/dev:latest
restart: always
command: bash -c "python manage.py migrate --noinput && python manage.py ensure_superuser --username bfportal --email [email protected] --password '${SU_PASSWD}' && python manage.py ensure_initialization && gunicorn --workers 4 --bind 0.0.0.0:${DEVEL_PORT}"
user: "33:33"
profiles:
- dev
ports:
- "${DEVEL_PORT}:${DEVEL_PORT}"
volumes:
- type: "bind"
source: /var/www/bfportal-devel-media
target: /app/media
environment:
- PRODUCTION_KEY=${PRODUCTION_KEY}
- DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID}
- DISCORD_SECRET=${DISCORD_SECRET}
- DB_NAME=${DB_NAME}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- POSTGRES_HOST=db_devel # takes precedent over .env file
- DEBUG=True
- APPROVAL_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_CHANNEL_WEBHOOK_ID=${APPROVAL_CHANNEL_WEBHOOK_ID}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID}
- PRODUCTION_HOST=${PRODUCTION_HOST}
- PRODUCTION_PORT=${PRODUCTION_PORT}
- OWNERS=${OWNERS}
- DEVEL_PORT=${DEVEL_PORT}
depends_on:
- db_devel
healthcheck:
test: curl -fk http://0.0.0.0:${DEVEL_PORT}/ || exit 1
interval: "60s"
timeout: "3s"
retries: 3
start_period: "5s"

# Dev environment services (on local machine)
db_dev_local:
db:
image: postgres:14
restart: always
volumes:
- postgress_db_dev_local:/var/lib/postgresql/data
profiles:
- dev_local
- postgres_db_dev_local:/var/lib/postgresql/data
environment:
- POSTGRES_NAME=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
Expand All @@ -138,16 +19,14 @@ services:
retries: 5
start_period: "10s"

bfportal_dev_local:
bfportal:
build:
context: .
dockerfile: Dockerfile
dockerfile: docker/Dockerfile
target: dev
restart: no
command: bash -c "python manage.py migrate --noinput && python manage.py ensure_superuser --username bfportal --email [email protected] --password 1234 && python manage.py ensure_initialization && python manage.py mock -u 10 -e 50 --noregen && python manage.py runserver 0.0.0.0:8000"
container_name: bfportal_dev_local
profiles:
- dev_local
ports:
- "8000:8000"
volumes:
Expand All @@ -158,7 +37,7 @@ services:
- DB_NAME=${DB_NAME}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- POSTGRES_HOST=db_dev_local # takes precedent over .env file
- POSTGRES_HOST=db # takes precedent over .env file
- DEBUG=True
- APPROVAL_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_CHANNEL_WEBHOOK_ID=${APPROVAL_CHANNEL_WEBHOOK_ID}
Expand All @@ -175,26 +54,22 @@ services:
retries: 5
start_period: "10s"
depends_on:
- db_dev_local
- db

bfportal_dev_local_tailwind:
tailwind:
build:
context: .
dockerfile: Dockerfile
dockerfile: docker/dockerfile
target: dev
command: npm run watch
restart: always
container_name: bfportal_dev_local_tailwind
profiles:
- dev_local
volumes:
- ./bfportal:/app
depends_on:
bfportal_dev_local:
bfportal:
condition: service_healthy
stdin_open: true

volumes:
postgress_db_devel:
postgress_db:
postgress_db_dev_local:
postgres_db_dev_local:
Loading

0 comments on commit ed5f8ab

Please sign in to comment.