-
Notifications
You must be signed in to change notification settings - Fork 1
76 lines (66 loc) · 2.52 KB
/
docker-build-staging.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
name: Docker Build Staging
on:
push:
branches-ignore:
- main
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Generate Matrix
id: set-matrix
run: |
apps=$(ls -d apps/*/)
matrix="{\"include\":["
for app in $apps; do
app_name=$(basename $app)
matrix="${matrix}{\"app-dir\":\"${app_name}\",\"app-package-name\":\"@npcs/${app_name}\",\"image-name\":\"ghcr.io/${{ github.actor }}/npcs-${app_name}:staging\"},"
done
matrix="${matrix%?}]}"
echo "::set-output name=matrix::${matrix}"
build:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login Registry
if: github.ref == 'refs/heads/develop'
run: |
echo ${{ secrets.PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build Docker Image
id: docker_build
uses: docker/build-push-action@v6
with:
push: ${{ github.ref == 'refs/heads/develop' && 'true' || 'false' }}
tags: ${{ matrix.image-name }}
cache-from: type=registry,ref=${{ matrix.image-name }}
cache-to: type=inline
context: .
file: ${{ secrets.DOCKERFILE }}
build-args: |
TURBO_TEAM=${{ secrets.TURBO_TEAM }}
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}
APP_DIR=apps/${{ matrix.app-dir }}
APP_PACKAGE_NAME=${{ matrix.app-package-name }}
- run: |
echo "Docker Image ID: ${{ steps.docker_build.outputs.imageid }}"
echo "Docker Image digest: ${{ steps.docker_build.outputs.digest }}"
echo "Docker Image metadata: ${{ steps.docker_build.outputs.metadata }}"
- name: Trigger Deploy
if: github.ref == 'refs/heads/develop'
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PAT }}" \
-d "{\"event_type\":\"deploy_staging\",\"client_payload\":{\"app\":\"${{ matrix.app-dir }}\"}}" \
https://api.github.com/repos/${{ github.repository }}/dispatches
- name: Check Deploy Event
run: |
echo "Deploy event triggered for app: ${{ matrix.app-dir }}"