-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (116 loc) · 4.73 KB
/
build_and_unitest.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
name: Build and Test Monorepo
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
setup-environment:
name: Setup environment
runs-on: ubuntu-latest
outputs:
docker_matrix: ${{ steps.docker-environment.outputs.docker_matrix }}
registry: ${{ steps.docker-environment.outputs.registry }}
repository: ${{ steps.docker-environment.outputs.repository }}
source_branch: ${{ steps.github-environment.outputs.source_branch }}
target_branch: ${{ steps.github-environment.outputs.target_branch }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Watod Environment
run: ./watod_scripts/watod-setup-env.sh
shell: bash
- name: Generate Docker Environment
id: docker-environment
uses: "./.github/templates/docker_context"
- name: Generate GitHub Environment
id: github-environment
uses: "./.github/templates/github_context"
build-and-unittest:
name: Build Image and Run Unit Testing Suite
runs-on: ubuntu-latest
needs: setup-environment
env:
DOCKER_REGISTRY: ${{ needs.setup-environment.outputs.registry }}
DOCKER_REPOSITORY: ${{ needs.setup-environment.outputs.repository }}
SOURCE_BRANCH: ${{ needs.setup-environment.outputs.source_branch }}
TARGET_BRANCH: ${{ needs.setup-environment.outputs.target_branch }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup-environment.outputs.docker_matrix) }}
concurrency:
group: ${{ matrix.service }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Construct Registry URL
id: construct-registry-url
run: |
echo "url=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_REPOSITORY }}/${{ matrix.module }}/${{ matrix.service }}" \
>> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: buildx
- name: Docker Login
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_PWD }}
- name: Prepare Image Dependencies
if: ${{ matrix.module != 'infrastructure' }}
uses: docker/build-push-action@v5
with:
context: .
file: docker/${{ matrix.module }}/${{ matrix.service }}/${{ matrix.service }}.Dockerfile
push: true
tags: |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.SOURCE_BRANCH }}
cache-from: |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.SOURCE_BRANCH }}
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.TARGET_BRANCH }}
cache-to: type=inline
builder: ${{ steps.buildx.outputs.name }}
target: dependencies
- name: Build Image from Source
uses: docker/build-push-action@v5
with:
context: .
file: docker/${{ matrix.module }}/${{ matrix.service }}/${{ matrix.service }}.Dockerfile
push: true
tags: |
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.SOURCE_BRANCH }}
cache-from: |
${{ steps.construct-registry-url.outputs.url }}:source_${{ env.SOURCE_BRANCH }}
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.SOURCE_BRANCH }}
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.TARGET_BRANCH }}
cache-to: type=inline
builder: ${{ steps.buildx.outputs.name }}
target: build
- name: Security Sanitation for Deployment
uses: docker/build-push-action@v5
with:
context: .
file: docker/${{ matrix.module }}/${{ matrix.service }}/${{ matrix.service }}.Dockerfile
push: true
tags: |
${{ steps.construct-registry-url.outputs.url }}:${{ env.SOURCE_BRANCH }}
cache-from: |
${{ steps.construct-registry-url.outputs.url }}:build_${{ env.SOURCE_BRANCH }}
${{ steps.construct-registry-url.outputs.url }}:${{ env.SOURCE_BRANCH }}
${{ steps.construct-registry-url.outputs.url }}:${{ env.TARGET_BRANCH }}
cache-to: type=inline
builder: ${{ steps.buildx.outputs.name }}
target: deploy
- name: Run testing suite
uses: "./.github/templates/test"
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
BUILDKIT_INLINE_CACHE: 1
with:
image: ${{ steps.construct-registry-url.outputs.url }}
tag: build_${{ env.SOURCE_BRANCH }}