-
Notifications
You must be signed in to change notification settings - Fork 3
141 lines (119 loc) · 4.36 KB
/
deploy.yaml
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
name: Deploy
run-name: Deploy (${{ github.ref_name }})
on:
push:
branches:
- master
- develop
concurrency:
group: deploy-${{ github.ref_name }}
cancel-in-progress: true
env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/wink-official-frontend:${{ github.ref_name }}
API_URL: ${{ github.ref_name == 'master' && secrets.API_MASTER_URL || secrets.API_DEVELOP_URL }}
SSH_HOST: ${{ github.ref_name == 'master' && secrets.SSH_MASTER_HOST || secrets.SSH_DEVELOP_HOST }}
SSH_USERNAME: ${{ github.ref_name == 'master' && secrets.SSH_MASTER_USERNAME || secrets.SSH_DEVELOP_USERNAME }}
SSH_KEY: ${{ github.ref_name == 'master' && secrets.SSH_MASTER_KEY || secrets.SSH_DEVELOP_KEY }}
jobs:
build-amd64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64
provenance: false
tags: ${{ env.IMAGE_NAME }}-amd64
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}-amd64-cache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}-amd64-cache
build-arm64:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/arm64
tags: ${{ env.IMAGE_NAME }}-arm64
provenance: false
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}-arm64-cache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}-arm64-cache
merge-image:
runs-on: ubuntu-latest
needs: [ build-amd64, build-arm64 ]
steps:
- name: Login to Docker Hub
run: |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
- name: Pull Frontend Image
run: |
docker pull --platform linux/amd64 ${{ env.IMAGE_NAME }}-amd64
docker pull --platform linux/arm64 ${{ env.IMAGE_NAME }}-arm64
- name: Merge Frontend Image
run: |
docker manifest create ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-amd64 ${{ env.IMAGE_NAME }}-arm64
docker manifest annotate ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-amd64 --os linux --arch amd64
docker manifest annotate ${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}-arm64 --os linux --arch arm64
- name: Push Frontend Image
run: docker manifest push ${{ env.IMAGE_NAME }}
check-server:
runs-on: ubuntu-latest
steps:
- name: Check exists project
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
if [ ! -d "Frontend" ]; then
echo "Directory "Frontend" not found"
exit 1
fi
- name: Check docker compose file
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
if [ ! -f "Frontend/docker-compose.yaml" ]; then
echo "File "Frontend/docker-compose.yaml" not found"
exit 1
fi
deploy:
runs-on: ubuntu-latest
needs: [ check-server, build-amd64 ]
steps:
- name: Write .env file
run: |
echo "API_URL=${{ env.API_URL }}" > Frontend/.env
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
key: ${{ env.SSH_KEY }}
script: |
cd Frontend
docker compose pull
docker compose up -d