From 07afe516185536463a5f8233a339a10d83c34b9b Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 30 Aug 2024 21:34:01 +0800 Subject: [PATCH] Fix directory and image tags not being read properly --- .woodpecker.yml | 24 +++--- README.md | 2 +- docker-compose.yml => docker-compose.dev.yml | 1 - docker-compose.prod.yml | 79 ++++++++++++++++++++ 4 files changed, 92 insertions(+), 14 deletions(-) rename docker-compose.yml => docker-compose.dev.yml (98%) create mode 100644 docker-compose.prod.yml diff --git a/.woodpecker.yml b/.woodpecker.yml index 04de634..456fc99 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -1,18 +1,18 @@ # .woodpecker.yml steps: - - name: build-push + - name: build image: docker when: - branch: master - event: push commands: - - docker build . -t "$IMAGE_TAG" - - echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY" --password-stdin -u "$REGISTRY_USERNAME" - - docker push "$IMAGE_TAG" + - docker build . -t git.keannu1.duckdns.org/keannu125/drf_template + - echo "$REGISTRY_PASSWORD" | docker login git.keannu1.duckdns.org --password-stdin -u "$REGISTRY_USERNAME" + - docker push git.keannu1.duckdns.org/keannu125/drf_template volumes: - /var/run/docker.sock:/var/run/docker.sock - secrets: [IMAGE_TAG, REGISTRY, REGISTRY_USERNAME, REGISTRY_PASSWORD] - - name: update deployment and reset database + secrets: [REGISTRY_USERNAME, REGISTRY_PASSWORD] + - name: deploy image: docker when: - branch: master @@ -23,10 +23,10 @@ steps: - chmod 600 /root/.ssh/id_rsa - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > /root/.ssh/config - ssh root@10.0.10.4 ' - cd "${PROJECT_DIR}"; + cd "/mnt/nvme/files/docker projects/DRF-Template"; docker-compose down; - docker image rm "${IMAGE_TAG}" || true; - docker pull "${IMAGE_TAG}:latest"; - docker volume rm "${IMAGE_TAG}_db_data" || true; - docker compose up -d' - secrets: [IMAGE_TAG, SSH_KEY, PROJECT_DIR] + docker image rm git.keannu1.duckdns.org/keannu125/drf_template || true; + docker pull git.keannu1.duckdns.org/keannu125/drf_template:latest; + docker volume rm "git.keannu1.duckdns.org/keannu125/drf_template_db_data" || true; + docker compose up -f docker-compose.prod.yml -d;' + secrets: [SSH_KEY] diff --git a/README.md b/README.md index 0cff909..2aab694 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is a Django template that I personally use for my projects. This covers the - Create a copy of the `.env.sample` file and name it as `.env` in the same directory - Populate .env with values -- Run `docker-compose up` +- Run `docker-compose up -f docker-compose.dev.yml` Be sure to follow through the steps shown in the `stripe-listener` container for initial setup with Stripe! diff --git a/docker-compose.yml b/docker-compose.dev.yml similarity index 98% rename from docker-compose.yml rename to docker-compose.dev.yml index 44690b2..175867c 100644 --- a/docker-compose.yml +++ b/docker-compose.dev.yml @@ -2,7 +2,6 @@ version: "3.9" services: # Django Backend - # http://localhost:8000 django: env_file: .env build: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..2c61d86 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,79 @@ +version: "3.9" + +services: + # Django Backend + django: + env_file: .env + image: git.keannu1.duckdns.org/keannu125/drf_template:latest + ports: + - "${BACKEND_PORT}:${BACKEND_PORT}" + environment: + - PYTHONBUFFERED=1 + - RUN_TYPE=web + volumes: + - .:/code + depends_on: + - postgres + + # Django Celery Worker + celery: + env_file: .env + environment: + - RUN_TYPE=worker + image: git.keannu1.duckdns.org/keannu125/drf_template:latest + volumes: + - .:/code + - ./chrome:/chrome + - ./firefox:/firefox + - ./dumps:/dumps + depends_on: + - django + - postgres + - redis + ## Runs multiple worker instances + scale: 4 + + # Django Celery Beat + celery_beat: + env_file: .env + environment: + - RUN_TYPE=beat + image: git.keannu1.duckdns.org/keannu125/drf_template:latest + volumes: + - .:/code + depends_on: + - celery + - django + - postgres + - redis + + # SQL Database + postgres: + env_file: .env + image: postgres + environment: + - POSTGRES_DB=${DB_DATABASE} + - POSTGRES_USER=${DB_USERNAME} + - POSTGRES_PASSWORD=${DB_PASSWORD} + ports: + - "${DB_PORT}:5432" + volumes: + - db-data:/var/lib/postgresql/data + + # Redis Server + redis: + image: redis:latest + ports: + - "${REDIS_PORT}:6379" + + # Stripe CLI Webhook Listener + stripe-listener: + env_file: .env + image: stripe/stripe-cli:latest + environment: + - STRIPE_WEBHOOK_SECRET=${STRIPE_SECRET_WEBHOOK} + - STRIPE_API_KEY=${STRIPE_SECRET_KEY} + command: listen --forward-to django:8000/api/v1/stripe/webhook/ + +volumes: + db-data: