-
-
Notifications
You must be signed in to change notification settings - Fork 6
197 lines (172 loc) · 8.33 KB
/
template.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: "<template>"
on:
workflow_call:
inputs:
expansion:
required: true
type: string
jobs:
build-builder:
name: "Builder"
runs-on: ubuntu-latest
steps:
- name: Clone the repository
uses: actions/checkout@v4
- name: Configure the Docker environment
uses: Byloth/docker-setup-action@v1
with:
registry: ghcr.io
repository: ${{ github.repository_owner }}/CMaNGOS
- name: Login to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Definition of environmental variables
env:
BUILDER_IMAGE: "${{ env.DOCKER_IMAGE }}/${{ inputs.expansion }}/builder"
run: |
echo BUILDER_IMAGE_REF="${BUILDER_IMAGE}:${{ env.GITHUB_SHORT_SHA }}" >> "${GITHUB_ENV}" && \
echo BUILDER_IMAGE_TAG="${BUILDER_IMAGE}:${{ env.GITHUB_REF_SLUG }}" >> "${GITHUB_ENV}" && \
\
echo BUILDER_IMAGE_DAY="${BUILDER_IMAGE}:$(date -u +"%Y-%m-%d")" >> "${GITHUB_ENV}" && \
\
echo BUILDER_IMAGE_LATEST="${BUILDER_IMAGE}:latest" >> "${GITHUB_ENV}" && \
echo BUILDER_IMAGE_CACHE="${BUILDER_IMAGE}:cache" >> "${GITHUB_ENV}"
- name: Pull the Docker cache images
run: |
if docker pull "${{ env.BUILDER_IMAGE_REF }}"
then
docker tag "${{ env.BUILDER_IMAGE_REF }}" "${{ env.BUILDER_IMAGE_CACHE }}"
elif docker pull "${{ env.BUILDER_IMAGE_TAG }}"
then
docker tag "${{ env.BUILDER_IMAGE_TAG }}" "${{ env.BUILDER_IMAGE_CACHE }}"
elif docker pull "${{ env.BUILDER_IMAGE_DAY }}"
then
docker tag "${{ env.BUILDER_IMAGE_DAY }}" "${{ env.BUILDER_IMAGE_CACHE }}"
elif docker pull "${{ env.BUILDER_IMAGE_LATEST }}"
then
docker tag "${{ env.BUILDER_IMAGE_LATEST }}" "${{ env.BUILDER_IMAGE_CACHE }}"
fi
- name: Definition of build arguments
run: |
echo MANGOS_SHA1="$(curl -sSL https://api.github.com/repos/cmangos/mangos-${{ inputs.expansion }}/commits/master \
-H "Accept: application/vnd.github.VERSION.sha")" >> "${GITHUB_ENV}" && \
echo DATABASE_SHA1="$(curl -sSL https://api.github.com/repos/cmangos/${{ inputs.expansion }}-db/commits/master \
-H "Accept: application/vnd.github.VERSION.sha")" >> "${GITHUB_ENV}" && \
\
echo TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "${GITHUB_ENV}" && \
echo VERSION_CODE="1.0.0-nightly+$(date -u +"%Y%m%d")" >> "${GITHUB_ENV}"
- name: Build the Docker images
run: |
docker build --build-arg EXPANSION="${{ inputs.expansion }}" \
--build-arg MANGOS_SHA1="${{ env.MANGOS_SHA1 }}" \
--build-arg DATABASE_SHA1="${{ env.DATABASE_SHA1 }}" \
--build-arg THREADS="2" \
--build-arg COMMIT_SHA="${{ github.sha }}" \
--build-arg CREATE_DATE="${{ env.TIMESTAMP }}" \
--build-arg VERSION="${{ env.VERSION_CODE }}" \
--cache-from "${{ env.BUILDER_IMAGE_CACHE }}" \
--tag "${{ env.BUILDER_IMAGE_REF }}" \
--tag "${{ env.BUILDER_IMAGE_TAG }}" \
--target "builder" \
\
. # There's a `dot` on this line!
- name: Push the Docker images
run: |
docker push "${{ env.BUILDER_IMAGE_REF }}" && \
docker push "${{ env.BUILDER_IMAGE_TAG }}"
- name: Push latest Docker image
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker tag "${{ env.BUILDER_IMAGE_REF }}" "${{ env.BUILDER_IMAGE_DAY }}" && \
docker tag "${{ env.BUILDER_IMAGE_REF }}" "${{ env.BUILDER_IMAGE_LATEST }}" && \
\
docker push "${{ env.BUILDER_IMAGE_DAY }}" && \
docker push "${{ env.BUILDER_IMAGE_LATEST }}"
build-runner:
name: "Runner"
needs: build-builder
runs-on: ubuntu-latest
steps:
- name: Clone the repository
uses: actions/checkout@v4
- name: Configure the Docker environment
uses: Byloth/docker-setup-action@v1
with:
registry: ghcr.io
repository: ${{ github.repository_owner }}/CMaNGOS
- name: Login to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Definition of environmental variables
env:
RUNNER_IMAGE: "${{ env.DOCKER_IMAGE }}/${{ inputs.expansion }}"
run: |
echo BUILDER_IMAGE="${RUNNER_IMAGE}/builder:${{ env.GITHUB_SHORT_SHA }}" >> "${GITHUB_ENV}" && \
\
echo RUNNER_IMAGE_REF="${RUNNER_IMAGE}:${{ env.GITHUB_SHORT_SHA }}" >> "${GITHUB_ENV}" && \
echo RUNNER_IMAGE_TAG="${RUNNER_IMAGE}:${{ env.GITHUB_REF_SLUG }}" >> "${GITHUB_ENV}" && \
\
echo RUNNER_IMAGE_DAY="${RUNNER_IMAGE}:$(date -u +"%Y-%m-%d")" >> "${GITHUB_ENV}" && \
\
echo RUNNER_IMAGE_LATEST="${RUNNER_IMAGE}:latest" >> "${GITHUB_ENV}" && \
echo RUNNER_IMAGE_CACHE="${RUNNER_IMAGE}:cache" >> "${GITHUB_ENV}"
- name: Pull the CMaNGOS builder image
run: docker pull "${{ env.BUILDER_IMAGE }}"
- name: Pull the Docker cache images
run: |
if docker pull "${{ env.RUNNER_IMAGE_REF }}"
then
docker tag "${{ env.RUNNER_IMAGE_REF }}" "${{ env.RUNNER_IMAGE_CACHE }}"
elif docker pull "${{ env.RUNNER_IMAGE_TAG }}"
then
docker tag "${{ env.RUNNER_IMAGE_TAG }}" "${{ env.RUNNER_IMAGE_CACHE }}"
elif docker pull "${{ env.RUNNER_IMAGE_DAY }}"
then
docker tag "${{ env.RUNNER_IMAGE_DAY }}" "${{ env.RUNNER_IMAGE_CACHE }}"
elif docker pull "${{ env.RUNNER_IMAGE_LATEST }}"
then
docker tag "${{ env.RUNNER_IMAGE_LATEST }}" "${{ env.RUNNER_IMAGE_CACHE }}"
fi
- name: Definition of build arguments
run: |
echo MANGOS_SHA1="$(curl -sSL https://api.github.com/repos/cmangos/mangos-${{ inputs.expansion }}/commits/master \
-H "Accept: application/vnd.github.VERSION.sha")" >> "${GITHUB_ENV}" && \
echo DATABASE_SHA1="$(curl -sSL https://api.github.com/repos/cmangos/${{ inputs.expansion }}-db/commits/master \
-H "Accept: application/vnd.github.VERSION.sha")" >> "${GITHUB_ENV}" && \
\
echo TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "${GITHUB_ENV}" && \
echo VERSION_CODE="1.0.0-nightly+$(date -u +"%Y%m%d")" >> "${GITHUB_ENV}"
- name: Build the Docker images
run: |
docker build --build-arg EXPANSION="${{ inputs.expansion }}" \
--build-arg MANGOS_SHA1="${{ env.MANGOS_SHA1 }}" \
--build-arg DATABASE_SHA1="${{ env.DATABASE_SHA1 }}" \
--build-arg THREADS="2" \
--build-arg COMMIT_SHA="${{ github.sha }}" \
--build-arg CREATE_DATE="${{ env.TIMESTAMP }}" \
--build-arg VERSION="${{ env.VERSION_CODE }}" \
--cache-from "${{ env.BUILDER_IMAGE }}" \
--cache-from "${{ env.RUNNER_IMAGE_CACHE }}" \
--tag "${{ env.RUNNER_IMAGE_REF }}" \
--tag "${{ env.RUNNER_IMAGE_TAG }}" \
--target "runner" \
\
. # There's a `dot` on this line!
- name: Push the Docker images
run: |
docker push "${{ env.RUNNER_IMAGE_REF }}" & \
docker push "${{ env.RUNNER_IMAGE_TAG }}"
- name: Push latest Docker image
if: ${{ github.ref == 'refs/heads/master' }}
run: |
docker tag "${{ env.RUNNER_IMAGE_REF }}" "${{ env.RUNNER_IMAGE_DAY }}" && \
docker tag "${{ env.RUNNER_IMAGE_REF }}" "${{ env.RUNNER_IMAGE_LATEST }}" && \
\
docker push "${{ env.RUNNER_IMAGE_DAY }}" & \
docker push "${{ env.RUNNER_IMAGE_LATEST }}"