Repository navigation
168 lines (164 loc) · 5.85 KB
/
Copy pathci.yml
File metadata and controls
168 lines (164 loc) · 5.85 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
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
159
160
161
162
163
164
165
166
167
168
name: CI
on:
push:
branches:
- 'dev'
- 'main'
pull_request:
types: [opened, reopened, synchronize]
jobs:
meta:
name: Generate and check metadata
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.environment.outputs.environment }}
labels: ${{ steps.meta.outputs.labels }}
tag: ${{ steps.meta.outputs.tags }}
tag_names: ${{ steps.meta.outputs.tag_names }}
tag_exists: ${{ steps.check-image.outputs.tag_exists }}
json: ${{ steps.meta.outputs.json }}
version: ${{ steps.meta.outputs.version }}
steps:
- name: Set environment variable based on branch
id: environment
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "environment=main" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.ref_name }}" == "dev" ]]; then
echo "environment=dev" >> "$GITHUB_OUTPUT"
fi
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.REGISTRY_IMAGE }}
tags: |
type=sha,format=long
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if image exists already
id: check-image
run: |
if docker manifest inspect ${{ steps.meta.outputs.tags }} > /dev/null 2>&1; then
echo "tag_exists=true" >> "$GITHUB_OUTPUT"
else
echo "tag_exists=false" >> "$GITHUB_OUTPUT"
fi
test:
name: Test
needs: meta
runs-on: ubuntu-latest
if: ${{ needs.meta.outputs.tag_exists == 'false' }}
container: node:18.20.8-bookworm
services:
db:
image: postgres:12
env:
POSTGRES_HOST_AUTH_METHOD: trust
mailcatcher:
image: dockage/mailcatcher:0.9.0
env:
DATABASE_URL: postgres://postgres@db/bats
SMTP_HOST: mailcatcher
AGORA_APP_CERTIFICATE: ${{ secrets.AGORA_APP_CERTIFICATE }}
REACT_APP_AGORA_APP_ID: ${{ secrets.REACT_APP_AGORA_APP_ID }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Set up package cache
uses: actions/setup-node@v4
with:
node-version: '18.20.8'
cache: 'yarn'
- name: Install Dependencies
run: yarn install && yarn workspace e2e install-chromium
- name: Create database
run: yarn workspace server sequelize db:create && yarn workspace server sequelize db:create --env test
- name: Run migrations
run: yarn workspace server sequelize db:migrate && yarn workspace server sequelize db:migrate --env test
- name: Run seeds
run: yarn workspace server sequelize db:seed:all
- name: Run Tests
run: eval $(cat example.env | grep -v -e 'AGORA_APP_CERTIFICATE' -e 'REACT_APP_AGORA_APP_ID' -e 'DATABASE_URL' -e 'SMTP_HOST' | sed 's/^/export /'); yarn run test
build:
name: Build Image
needs: [meta, test]
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-24.04
- ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
if: ${{ github.ref_name == 'main' }}
steps:
- name: Prepare
run: |
if [[ ${{ matrix.runner }} == "ubuntu-24.04-arm" ]]; then
platform=linux/arm64
else
platform=linux/amd64
fi
echo "PLATFORM=${platform}" >> $GITHUB_ENV
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- 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 by digest
id: build
uses: docker/build-push-action@v6
with:
platforms: ${{ env.PLATFORM }}
labels: ${{ needs.meta.outputs.labels }}
tags: ${{ vars.REGISTRY_IMAGE }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs: [meta, build]
env:
DOCKER_METADATA_OUTPUT_VERSION: ${{ needs.meta.outputs.version }}
DOCKER_METADATA_OUTPUT_TAGS: ${{ needs.meta.outputs.tag }}
DOCKER_METADATA_OUTPUT_TAG_NAMES: ${{ needs.meta.outputs.tag_names }}
DOCKER_METADATA_OUTPUT_LABELS: ${{ needs.meta.outputs.labels }}
DOCKER_METADATA_OUTPUT_JSON: ${{ needs.meta.outputs.json }}
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ vars.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ needs.meta.outputs.tag }}