-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (51 loc) · 1.98 KB
/
deploy.yml
File metadata and controls
60 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# .github/workflows/deploy.yml
# Final version using multiple compose files
name: Build and Deploy to Server
on:
push:
branches: [ "main" ]
env:
IMAGE_NAME: ghcr.io/jardahrazdera/portfolio-jaroslav-tech
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./src/Dockerfile
push: true
tags: ${{ env.IMAGE_NAME }}:latest
build-args: |
CACHEBUST=${{ github.run_number }}
GIT_COMMIT=${{ github.sha }}
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /opt/stacks/3-apps/jaroslav.tech
git pull origin main
echo ${{ secrets.GHCR_PAT }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
# Stop the app container
docker compose -f docker-compose.yml stop app
# Clear the static files volume to force fresh static files
docker volume rm jaroslavtech_static_volume || true
# Pull new image and recreate
docker compose -f docker-compose.yml pull app
docker compose -f docker-compose.yml down app
docker volume rm jaroslavtech_static_volume || true
docker compose -f docker-compose.yml up -d --no-deps app
# Run database migrations
docker compose -f docker-compose.yml run --rm app python manage.py migrate --no-input