forked from carlreid/StreamMaster
-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (140 loc) · 5.02 KB
/
Copy pathdocker-build-shared.yml
File metadata and controls
163 lines (140 loc) · 5.02 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
name: Shared Docker Build
on:
workflow_call:
inputs:
version:
required: true
type: string
build_all:
type: boolean
default: false
build_base:
type: boolean
default: false
build_build:
type: boolean
default: false
build_sm:
type: boolean
default: false
skip_release_main_build:
type: boolean
default: false
release_as_latest:
type: boolean
default: false
secrets:
token:
required: true
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
BASE_IMAGE_NAME: ${{ github.repository_owner }}/streammaster-builds
FINAL_IMAGE_NAME: ${{ github.repository_owner }}/streammaster
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.gitversion.outputs.semVer }}
branchName: ${{ steps.gitversion.outputs.branchName }}
buildMeta: ${{ steps.gitversion.outputs.buildMetadata }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.token }}
fetch-depth: 0
clean: true
fetch-tags: true
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: "5.x"
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0
test:
needs: [setup]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.token }}
fetch-depth: 0
clean: true
fetch-tags: true
- name: Generate code hash
id: hash
run: |
find src -type f \( -name "*.cs" -o -name "*.csproj" -o -name "*.json" -o -name "*.xml" \) -print0 | sort -z | xargs -0 sha256sum | sha256sum | cut -d' ' -f1 > code_hash.txt
echo "code_hash=$(cat code_hash.txt)" >> $GITHUB_OUTPUT
- name: Check code hash cache
id: cache-hash
uses: actions/cache@v4
with:
path: code_hash.txt
key: ${{ runner.os }}-code-${{ steps.hash.outputs.code_hash }}
- name: Set up Docker Buildx
if: steps.cache-hash.outputs.cache-hit != 'true'
uses: docker/setup-buildx-action@v3
- name: Run Tests
run: |
docker buildx build \
--platform linux/amd64 \
-f Dockerfile.tests \
--progress=plain \
--no-cache \
.
build:
needs: [setup, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
token: ${{ secrets.token }}
fetch-depth: 0
clean: true
fetch-tags: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.token }}
- name: Base - Build and Push
if: ${{ inputs.build_base || inputs.build_all }}
run: |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-base -f Dockerfile.base --push .
- name: Build - Build and Push
if: ${{ inputs.build_build || inputs.build_all }}
run: |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-build -f Dockerfile.build --push .
- name: SM - Build and Push
if: ${{ inputs.build_sm || inputs.build_all }}
run: |
set -e
echo "FROM --platform=\$BUILDPLATFORM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-build AS build" > Dockerfile.sm
cat Dockerfile.sm.template >> Dockerfile.sm
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-sm -f Dockerfile.sm --push .
- name: Final - Build and Push
if: ${{ !inputs.skip_release_main_build }}
run: |
set -e
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-sm AS sm" > Dockerfile
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ inputs.version }}-base AS base" >> Dockerfile
cat Dockerfile.template >> Dockerfile
TAGS="-t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:${{ inputs.version }}"
if [[ "${{ inputs.release_as_latest }}" == "true" ]]; then
TAGS="$TAGS -t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:latest"
else
TAGS="$TAGS -t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:$(echo "${{ needs.setup.outputs.branchName }}" | tr '/' '-')"
fi
docker buildx build --platform linux/amd64,linux/arm64 \
$TAGS \
-f Dockerfile --push .