-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (126 loc) · 4.48 KB
/
Copy pathdeploy.yml
File metadata and controls
152 lines (126 loc) · 4.48 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Build and Push Images
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
packages: write # Required to push to GHCR
env:
REGISTRY: ghcr.io
IMAGE_NAME: pd-graduation-project/pd-server
jobs:
build-app:
name: Build App Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push App
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.app
platforms: linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-app:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-app:${{ github.sha }}
cache-from: type=gha,scope=pd-app
cache-to: type=gha,mode=max,scope=pd-app
build-worker:
name: Build Worker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Worker
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.worker
platforms: linux/arm64
target: prod
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-worker:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-worker:${{ github.sha }}
cache-from: type=gha,scope=pd-worker
cache-to: type=gha,mode=max,scope=pd-worker
build-nginx:
name: Build Nginx Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Nginx
uses: docker/build-push-action@v6
with:
context: ./docker/nginx
file: ./docker/nginx/Dockerfile
platforms: linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-nginx:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pd-nginx:${{ github.sha }}
cache-from: type=gha,scope=pd-nginx
cache-to: type=gha,mode=max,scope=pd-nginx
deploy:
name: Signal Server to Pull
runs-on: ubuntu-latest
needs: [build-app, build-worker, build-nginx]
steps:
- name: SSH and deploy
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.ORACLE_HOST }}
username: ubuntu
port: 22
key: ${{ secrets.SSH_KEY }}
script: |
cd ~/PD-Server
# Pull latest code
git pull origin main
cd ~/PD-Server/docker
# Pull latest images from GHCR
docker pull ghcr.io/pd-graduation-project/pd-server/pd-app:latest
docker pull ghcr.io/pd-graduation-project/pd-server/pd-worker:latest
docker pull ghcr.io/pd-graduation-project/pd-server/pd-nginx:latest
# Tag for local use
docker tag ghcr.io/pd-graduation-project/pd-server/pd-app:latest pd-server-app:local
docker tag ghcr.io/pd-graduation-project/pd-server/pd-worker:latest pd-server-worker:local
docker tag ghcr.io/pd-graduation-project/pd-server/pd-nginx:latest pd-server-nginx:local
# Restart containers with new images
docker compose --profile prod up -d --no-build app worker nginx watchtower
# Clean up old image layers
docker image prune -f
# Verify everything came up
docker compose ps
docker compose logs app --tail=20