-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (104 loc) · 3.94 KB
/
preview.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
name: Ci Cd Staging Environment
on:
pull_request:
branches: main
jobs:
test:
runs-on: ubuntu-latest
environment:
name: staging
# because we cannot use env directly when using docker run
env:
GOOGLE_CLOUD_STORAGE_SERVICE_ACCOUNT: ${{secrets.GOOGLE_CLOUD_STORAGE_SERVICE_ACCOUNT}}
GOOGLE_CLOUD_STORAGE_BUCKET: ${{secrets.GOOGLE_CLOUD_STORAGE_BUCKET}}
SERVER_URL: ${{secrets.SERVER_URL}}
GOOGLE_CLOUD_STORAGE_EMULATOR_ENDPOINT: ${{secrets.GOOGLE_CLOUD_STORAGE_EMULATOR_ENDPOINT}}
GOOGLE_OAUTH2_REFRESH_TOKEN_TEST: ${{secrets.GOOGLE_OAUTH2_REFRESH_TOKEN_TEST}}
GOOGLE_OAUTH2_CLIENT_ID_TEST: ${{secrets.GOOGLE_OAUTH2_CLIENT_ID_TEST}}
GOOGLE_OAUTH2_CLIENT_SECRET_TEST: ${{secrets.GOOGLE_OAUTH2_CLIENT_SECRET_TEST}}
PORT: ${{secrets.PORT}}
steps:
- uses: actions/checkout@v4
- uses: jbergstroem/hadolint-gh-action@v1
with:
dockerfile: build/package/**Containerfile
# Setup new docker builder for cache
- uses: docker/setup-buildx-action@v3
- name: Run Firebase Emulator
run: docker compose -f deployments/compose.yaml up -d
- name: Build Image Test
uses: docker/build-push-action@v5
with:
context: .
load: true
file: build/package/test.Containerfile
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{github.event.repository.name}}
- name: Unit testing
run: |
docker run --rm \
--name ${{github.event.repository.owner.login}} \
--network tempsy_net \
-e GOOGLE_CLOUD_STORAGE_SERVICE_ACCOUNT -e GOOGLE_CLOUD_STORAGE_BUCKET \
-e SERVER_URL -e GOOGLE_CLOUD_STORAGE_EMULATOR_ENDPOINT \
-e GOOGLE_OAUTH2_REFRESH_TOKEN_TEST -e PORT \
-e GOOGLE_OAUTH2_CLIENT_ID_TEST -e GOOGLE_OAUTH2_CLIENT_SECRET_TEST \
${{github.event.repository.name}} \
go test --cover -v \
-ldflags "-w -s" ./...
- name: Clean up Services
if: always()
continue-on-error: true
run: docker compose -f deployments/compose.yaml down -v --rmi all
deploy:
needs: test
runs-on: ubuntu-latest
environment:
name: staging
url: ${{vars.STAGING_URL}}
permissions:
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{github.repository}}
steps:
- uses: actions/checkout@v4
# Setup new docker builder and qemu for multi arch build
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{env.REGISTRY}}
username: ${{github.repository_owner}}
password: ${{secrets.GITHUB_TOKEN}}
- uses: docker/build-push-action@v5
with:
context: .
file: build/package/Containerfile
platforms: linux/amd64,linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{env.IMAGE_NAME}}:beta-${{github.sha}}
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: azure/container-apps-deploy-action@v2
with:
registryUrl: ${{env.REGISTRY}}
containerAppName: ${{github.event.repository.name}}-staging
resourceGroup: ${{secrets.AZURE_RESOURCE_GROUP}}
imageToDeploy: ${{env.IMAGE_NAME}}:beta-${{github.sha}}
targetPort: ${{secrets.PORT}}
- name: Job Successful Feedback
if: ${{ success() }}
run: |
cat >> $GITHUB_STEP_SUMMARY <<MD
# Successful CI & CD staging environment
**This test include:**
- [x] Tidy
- [x] Formatting
- [x] Unit Test
**App Published to:** ${{vars.STAGING_URL}}
MD