Skip to content

Commit

Permalink
optimize pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmegatelo committed Jan 22, 2025
1 parent 70f608d commit c15921a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ on:

jobs:
build:
name: Build image
name: Build docker images
runs-on: ubuntu-latest
environment: production
strategy:
matrix:
image_name: ['django', 'frontend', 'nginx']
steps:
- uses: actions/checkout@master
- run: docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }}
- run: docker build -f ./infra/production/django/Dockerfile -t ghcr.io/$GITHUB_ACTOR/walter:latest -t ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA .
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter:latest
- run: docker build -f ./infra/production/${{matrix.image_name}}/Dockerfile -t ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:latest -t ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:$GITHUB_SHA .
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:$GITHUB_SHA
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:latest

deploy:
name: Deploy
Expand Down Expand Up @@ -59,4 +62,4 @@ jobs:
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} -r $(pwd)/* ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} .env ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter/.env
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} docker-compose.prod.yml ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter/docker-compose.prod.yml
- run: ssh -i ${{ env.SSH_KEY_PATH }} ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }} "cd /home/walter/walter && docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }} && docker pull ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA && docker compose -f docker-compose.prod.yml up -d --build && docker system prune --all --force"
- run: ssh -i ${{ env.SSH_KEY_PATH }} ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }} "cd /home/walter/walter && docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }} && docker pull ghcr.io/$GITHUB_ACTOR/walter-django:$GITHUB_SHA && docker pull ghcr.io/$GITHUB_ACTOR/walter-frontend:$GITHUB_SHA && docker compose -f docker-compose.prod.yml up -d && docker system prune --all --force"
26 changes: 7 additions & 19 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:

nginx:
build: ./infra/production/nginx
image: ghcr.io/mrmegatelo/walter-nginx:${GITHUB_SHA:-latest}
volumes:
- staticfiles:/app/staticfiles
- mediafiles:/app/mediafiles
Expand All @@ -24,11 +24,10 @@ services:
- ./certbot/conf/:/etc/letsencrypt/:rw

web:
build:
context: .
dockerfile: infra/production/django/Dockerfile
image: ghcr.io/mrmegatelo/walter-django:${GITHUB_SHA:-latest}
command: /start
volumes:
- ./frontend:/app/frontend
- staticfiles:/app/staticfiles
- mediafiles:/app/mediafiles
env_file:
Expand All @@ -44,9 +43,7 @@ services:
condition: service_started

frontend:
build:
context: .
dockerfile: ./infra/local/frontend/Dockerfile
image: ghcr.io/mrmegatelo/walter-frontend:${GITHUB_SHA:-latest}
command: build
volumes:
- ./frontend:/app
Expand All @@ -65,10 +62,7 @@ services:
image: redis:7-alpine

celery_worker:
build:
context: .
dockerfile: infra/production/django/Dockerfile
image: walter_celery_worker
image: ghcr.io/mrmegatelo/walter-django:${GITHUB_SHA:-latest}
command: /start-celeryworker
volumes:
- staticfiles:/app/staticfiles
Expand All @@ -80,10 +74,7 @@ services:
- db

celery_beat:
build:
context: .
dockerfile: infra/production/django/Dockerfile
image: walter_celery_beat
image: ghcr.io/mrmegatelo/walter-django:${GITHUB_SHA:-latest}
command: /start-celerybeat
volumes:
- staticfiles:/app/staticfiles
Expand All @@ -95,10 +86,7 @@ services:
- db

flower:
build:
context: .
dockerfile: infra/production/django/Dockerfile
image: walter_celery_flower
image: ghcr.io/mrmegatelo/walter-django:${GITHUB_SHA:-latest}
command: /start-flower
volumes:
- staticfiles:/app/staticfiles
Expand Down
5 changes: 5 additions & 0 deletions infra/production/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM node:23-alpine

RUN addgroup --system django \
&& adduser --system --ingroup django django

WORKDIR /app

COPY ./frontend/package.json ./package.json
COPY ./frontend/package-lock.json ./package-lock.json

RUN npm i

USER django

ENTRYPOINT ["npm", "run"]
2 changes: 1 addition & 1 deletion infra/production/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:1.25.3-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY ./infra/production/nginx/nginx.conf /etc/nginx/conf.d

0 comments on commit c15921a

Please sign in to comment.