-
Notifications
You must be signed in to change notification settings - Fork 9
158 lines (133 loc) · 4.59 KB
/
cd-stage.yml
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
153
154
155
156
157
158
name: CD - Stage
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-client-api:
name: Build client-api image
runs-on: ubuntu-latest
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
file: ./apps/backend/Dockerfile # build with root context
push: true
build-args: |
target=client
app_env=stage
tags: ghcr.io/${{ github.repository_owner }}/codedang-client-api:latest
build-admin-api:
name: Build admin-api image
runs-on: ubuntu-latest
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
file: ./apps/backend/Dockerfile # build with root context
push: true
build-args: |
target=admin
app_env=stage
tags: ghcr.io/${{ github.repository_owner }}/codedang-admin-api:latest
build-iris:
name: Build Iris docker image
runs-on: ubuntu-latest
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push iris image
uses: docker/build-push-action@v6
with:
push: true
context: '{{defaultContext}}:apps/iris'
build-args: |
app_env=stage
tags: ghcr.io/${{ github.repository_owner }}/codedang-iris:latest
run-server:
name: Run stage server
runs-on: self-hosted
needs: [build-client-api, build-admin-api, build-iris]
environment: stage
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
docker-compose.yml
scripts/deploy.sh
.env.development
apps/infra/stage/Caddyfile
apps/grafana-logs/promtail/promtail-config.yml
- name: Load dotenv from secret
run: |
echo "${{ secrets.ENV_DEVELOPMENT }}" > .env
echo "${{ secrets.LOKI_SERVER_URL }}" >> .env
- name: Check if containers are running
id: check-container
run: |
{
echo 'stdout<<EOF'
docker compose --profile deploy ps -q
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Initialize containers
if: steps.check-container.outputs.stdout == ''
run: docker compose --profile deploy up -d --no-recreate
- name: Pull docker images
run: docker compose --profile update-target pull
- name: Run docker compose up
run: |
docker compose --profile deploy up backend-client -d --no-deps
docker compose --profile deploy up backend-admin -d --no-deps
docker compose --profile deploy up iris -d --no-deps
docker compose --profile deploy up promtail -d --no-deps
- name: Copy Caddyfile into Caddy Container
run: docker cp ./apps/infra/stage/Caddyfile caddy:/etc/caddy/Caddyfile
- name: Graceful reload Caddy
run: docker exec -w /etc/caddy caddy caddy reload
- name: Remove unused docker storages
run: docker system prune -a -f --volumes
# TODO: Uncomment this section when E2E test is ready
# e2e-test:
# name: Run E2E test
# runs-on: ubuntu-latest
# needs: [run-server]
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: 20
# - name: Install Bruno CLI
# run: npm install -g @usebruno/cli
# - name: Run Bruno Collection (Client)
# working-directory: ./collection/client
# run: bru run --env Stage
# - name: Run Bruno Collection (Admin)
# working-directory: ./collection/admin
# run: bru run --env Stage