-
Notifications
You must be signed in to change notification settings - Fork 77
194 lines (170 loc) · 5.97 KB
/
tests.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
name: Tests
on:
push:
paths:
- '.github/workflows/tests.yml'
- 'ecs/**'
- 'mix/**'
pull_request:
paths:
- '.github/workflows/tests.yml'
- 'ecs/**'
- 'mix/**'
env:
REGISTRY_GHCR: ghcr.io
REGISTRY_LOCAL: localhost:5000
REGISTRY_DOCKER: docker.io
MIX_IMAGENAME_GHCR: ${{ github.repository_owner }}/mix
ECS_IMAGENAME_GHCR: ${{ github.repository_owner }}/ecs
MIX_IMAGENAME_DOCKERHUB: ejabberd/mix
ECS_IMAGENAME_DOCKERHUB: ejabberd/ecs
jobs:
build:
name: Build
runs-on: ubuntu-22.04
strategy:
fail-fast: true
max-parallel: 1
permissions:
packages: write
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get git describe
id: gitdescribe
run: echo "ver=$(git describe --tags --exact-match 2>/dev/null || echo latest)" >> $GITHUB_OUTPUT
- name: Extract mix metadata (tags, labels)
id: mixmeta
if: github.ref_type == 'tag'
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ env.MIX_IMAGENAME_GHCR }}
${{ env.REGISTRY_DOCKER }}/${{ env.MIX_IMAGENAME_DOCKERHUB }}
labels: |
org.opencontainers.image.revision=${{ steps.gitdescribe.outputs.ver }}
org.opencontainers.image.licenses=GPL-2.0
org.opencontainers.image.vendor=ProcessOne
- name: Extract ecs metadata (tags, labels)
id: ecsmeta
if: github.ref_type == 'tag'
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ env.ECS_IMAGENAME_GHCR }}
${{ env.REGISTRY_DOCKER }}/${{ env.ECS_IMAGENAME_DOCKERHUB }}
labels: |
org.opencontainers.image.revision=${{ steps.gitdescribe.outputs.ver }}
org.opencontainers.image.licenses=GPL-2.0
org.opencontainers.image.vendor=ProcessOne
- name: Prepare local tags
id: localreg
run: |
tag="$(echo ${{ github.ref_name }} | sed -e 's|[/]\+|-|g')"
echo "mixlocaltag=${{ env.REGISTRY_LOCAL }}/${{ env.MIX_IMAGENAME_GHCR }}:$tag" >> $GITHUB_OUTPUT
echo "ecslocaltag=${{ env.REGISTRY_LOCAL }}/${{ env.ECS_IMAGENAME_GHCR }}:$tag" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Build and push local mix image
uses: docker/build-push-action@v5
with:
build-args: |
VERSION=${{ steps.gitdescribe.outputs.ver }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: mix
labels: ${{ steps.mixmeta.outputs.labels }}
platforms: linux/amd64
push: true
tags: |
${{ steps.localreg.outputs.mixlocaltag }}
- name: Prepare ecs Dockerfile
run: sed -i 's|ejabberd/mix|${{ steps.localreg.outputs.mixlocaltag }}|g' ecs/Dockerfile
- name: Build and push local ecs image
uses: docker/build-push-action@v5
with:
build-args: |
VERSION=${{ steps.gitdescribe.outputs.ver }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: ecs
labels: ${{ steps.ecsmeta.outputs.labels }}
platforms: linux/amd64
push: true
tags: |
${{ steps.localreg.outputs.ecslocaltag }}
- name: Run ecs image
run: |
docker images
docker run --name ejabberd -d -p 5222:5222 ${{ steps.localreg.outputs.ecslocaltag }}
- name: Wait ejabberd started
run: |
docker exec ejabberd bin/ejabberdctl started
- name: Check ecs results
if: always()
run: |
docker ps -s
docker logs ejabberd
docker logs ejabberd | grep -q "Start accepting TCP connections" || exit 1
docker logs ejabberd | grep -q "error" && exit 1 || exit 0
docker logs ejabberd | grep -q "Error" && exit 1 || exit 0
- name: Save image
run: |
docker image save ${{ steps.localreg.outputs.ecslocaltag }} --output ejabberd-latest.tar
- name: Upload image
uses: actions/upload-artifact@v4
with:
name: ejabberd-image
path: ejabberd-latest.tar
- run: |
echo "::notice::To get this image, download ejabberd-image.zip, "\
"uncompress it and run: " \
"docker image load -i ejabberd-latest.tar"
- name: Build and push mix image
uses: docker/build-push-action@v5
if: github.ref_type == 'tag'
with:
build-args: |
VERSION=${{ steps.gitdescribe.outputs.ver }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: mix
labels: ${{ steps.mixmeta.outputs.labels }}
platforms: linux/amd64
push: true
tags: |
${{ steps.mixmeta.outputs.tags }}
- name: Build and push ecs image
uses: docker/build-push-action@v5
if: github.ref_type == 'tag'
with:
build-args: |
VERSION=${{ steps.gitdescribe.outputs.ver }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: ecs
labels: ${{ steps.ecsmeta.outputs.labels }}
platforms: linux/amd64
push: true
tags: |
${{ steps.ecsmeta.outputs.tags }}