-
Notifications
You must be signed in to change notification settings - Fork 14
89 lines (78 loc) · 2.78 KB
/
deploy-production.yml
File metadata and controls
89 lines (78 loc) · 2.78 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
# reference:
# 1. https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md
# 2. https://github.com/docker/build-push-action/blob/master/docs/advanced/share-image-jobs.md
# 3. https://github.com/marketplace/actions/unregistry-docker-push-action
name: Deploy to Production environment
on:
push:
tags:
- v*
env:
BOX_NAME: kys-ows
BOX_URL: kaiyuanshe/kys-ows
DOCKER_BUILD_SUMMARY: false
DOCKER_BUILD_RECORD_UPLOAD: false
jobs:
deploy_docker_image:
name: Deploy Docker image
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
lfs: true
- run: git submodule update --remote
- name: Inject Environment variables
run: |
cat >> .npmrc <<EOF
//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}
@kaiyuanshe:registry=https://npm.pkg.github.com
always-auth=true
EOF
cat > .env.local <<EOF
${{ secrets.ENV_FILE }}
VERCEL_URL=kaiyuanshe.cn
EOF
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
tags: ${{ env.BOX_URL }}:latest
load: true # Load image to local Docker daemon for unregistry
# use cache from GitHub Actions
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Add server to known hosts
run: ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
- name: Deploy Docker image to server
uses: SonOfBytes/unregistry-action@v0.1.0
with:
image: ${{ env.BOX_URL }}:latest
destination: ${{ secrets.USER }}@${{ secrets.HOST }}
ssh_key: ${{ secrets.SSH_KEY }}
- name: Deploy Docker Compose and start services
uses: garygrossgarten/github-action-ssh@release
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.SSH_KEY }}
command: |
mkdir -p ~/${{ env.BOX_NAME }}
cd ~/${{ env.BOX_NAME }}
# Check if docker-compose.yml exists
if [ ! -f docker-compose.yml ]; then
echo "Error: docker-compose.yml not found in ~/${{ env.BOX_NAME }}"
echo "Please create a docker-compose.yml file before deployment"
exit 1
fi
# Stop existing containers and start new ones
docker-compose down -v --remove-orphans
docker-compose up -d
# Clean up unused images
docker image prune -a -f