-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (127 loc) · 3.91 KB
/
staging.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
142
143
144
145
146
147
148
149
150
151
152
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Bingo
on:
push:
tags:
- "v*"
branches:
- develop
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Unit tests.
run: make cover
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: coverage
path: ./_output/coverage.out
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the version
id: get_version
run: |
VERSION=$(git describe --tags)
VERSION=${VERSION#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate pb files
run: make protoc
- name: Build by Docker Compose
run: bash ./scripts/docker/build.sh ${{ env.VERSION }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${app_name}
path: |
_output/*tar.gz
publish:
name: Deploy Staging
needs:
- test
- build
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the version
id: get_version
run: |
VERSION=$(git describe --tags)
VERSION=${VERSION#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: actions/download-artifact@v4
with:
name: ${app_name}
path: ./
- name: Display structure of downloaded files
run: |
ls -l
- name: Scp
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_KEY }}
source: "./*.tar.gz"
target: "/tmp"
- name: Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_KEY }}
script: |
app_name=bingo
mkdir -p /opt/${app_name}
cd /opt/${app_name} || exit
tar -xzvpf /tmp/${app_name}-docker.tar.gz -C ./
if [ ! -f .env ]; then
cp .env.example .env
fi
if [ ! -f config/${app_name}-apiserver.yaml ]; then
cp config/${app_name}-apiserver.example.yaml config/${app_name}-apiserver.yaml
fi
if [ ! -f config/promtail.yaml ]; then
cp config/promtail.example.yaml config/promtail.yaml
fi
# Update app version by .env
if [ -n "${{ env.VERSION }}" ]; then
sed -i "s/APP_VERSION=.*/APP_VERSION=${{ env.VERSION }}/g" .env
fi
# Load and tag latest
loaded=$(docker load </tmp/${app_name}-images.tar.gz)
for image_with_version in $(echo "$loaded" | awk -F ': ' '{print $2}'); do
image=${image_with_version%:*}
docker tag "$image_with_version" "$image":latest
done
docker-compose up -d
rm /tmp/${app_name}*.tar.gz
rm config/${app_name}-apiserver.example.yaml
rm config/promtail.example.yaml