-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (68 loc) · 2.37 KB
/
deploy.yml
File metadata and controls
78 lines (68 loc) · 2.37 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
# ========================================
# Build images on GitHub's runner (free 7 GB RAM, plenty for Maven + npm),
# push to Docker Hub, then SSH into the droplet to pull + restart.
# Triggered on every push to main, or manually via the "Run workflow" button.
# ========================================
name: Build and Deploy ai-code
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push backend
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64
tags: zxuhan7/ai-code-backend:latest
cache-from: type=gha,scope=ai-code-backend
cache-to: type=gha,mode=max,scope=ai-code-backend
- name: Build and push frontend
uses: docker/build-push-action@v5
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
platforms: linux/amd64
tags: zxuhan7/ai-code-frontend:latest
cache-from: type=gha,scope=ai-code-frontend
cache-to: type=gha,mode=max,scope=ai-code-frontend
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Copy docker-compose.prod.yml to droplet
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_SSH_KEY }}
source: "docker-compose.prod.yml"
target: "/opt/ai-code/"
- name: Pull and restart on droplet
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_SSH_KEY }}
script: |
cd /opt/ai-code
docker compose -f docker-compose.prod.yml pull
docker compose -f docker-compose.prod.yml up -d
docker image prune -f