@@ -8,40 +8,88 @@ name: CI Pipeline
8
8
on :
9
9
push :
10
10
branches : [ "main" ]
11
+ # ###### Uncomment this to test the CI pipeline in a PR
12
+ # ###### You'll also need to comment the rules containing {{branch}}
13
+ # ###### in the `Extract Docker metadata` step
14
+ # pull_request:
15
+ # branches: [ "main" ]
11
16
12
17
env :
13
18
# Use docker.io for Docker Hub if empty
14
19
REGISTRY : ghcr.io
15
20
# github.repository as <account>/<repo>
16
- IMAGE_NAME : ${{ github.repository }}
21
+ REGISTRY_PATH : ${{ github.repository }}
17
22
TEST_TAG : user/app:test
18
23
19
24
jobs :
25
+ test :
26
+ runs-on : ubuntu-latest
27
+ steps :
28
+ - name : Checkout repository
29
+ uses : actions/checkout@v4
30
+
31
+ # This might be unnecessary as tests are not
32
+ # multiplatform
33
+ - name : Setup Docker buildx
34
+
35
+
36
+ # Build but don't push Docker image with Buildx
37
+ # https://github.com/docker/build-push-action
38
+ - name : Build test image
39
+ id : build-test
40
+
41
+ with :
42
+ context : .
43
+ load : true
44
+ target : dev
45
+ tags : ${{ env.TEST_TAG }}
46
+ cache-from : type=gha
47
+ cache-to : type=gha,mode=max
48
+
49
+ # This is a barrier check to make sure we push a functional
50
+ # docker image, we can avoid linting
51
+ - name : Run tests in the test image
52
+ run : |
53
+ docker run --rm ${{ env.TEST_TAG }} make ci-test
54
+
20
55
build :
21
56
runs-on : ubuntu-latest
57
+ needs : test
22
58
permissions :
23
59
contents : read
24
60
packages : write
25
61
# This is used to complete the identity challenge
26
62
# with sigstore/fulcio when running outside of PRs.
27
63
id-token : write
28
-
64
+ strategy :
65
+ matrix :
66
+ docker_target :
67
+ - http
68
+ - socketio
69
+ - dramatiq
29
70
steps :
71
+ # GitHub gives only repository complete in <owner>/<repo> format.
72
+ # Need some manual sheanigans
73
+ # Set IMAGE_NAME so we can push to <owner>/<repo>/<image>
74
+ - name : Set ENV variables
75
+ run : |
76
+ echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
77
+
30
78
- name : Checkout repository
31
79
uses : actions/checkout@v4
32
80
33
81
- name : Set up QEMU
34
82
uses : docker/setup-qemu-action@v3
35
83
36
- # Install the cosign tool except on PR
84
+ # Install the cosign tool
37
85
# https://github.com/sigstore/cosign-installer
38
86
- name : Install cosign
39
87
40
88
41
89
- name : Setup Docker buildx
42
90
43
91
44
- # Login against a Docker registry except on PR
92
+ # Login against a Docker registry
45
93
# https://github.com/docker/login-action
46
94
- name : Log into registry ${{ env.REGISTRY }}
47
95
@@ -50,32 +98,16 @@ jobs:
50
98
username : ${{ github.actor }}
51
99
password : ${{ secrets.GITHUB_TOKEN }}
52
100
53
- # Build and push Docker image with Buildx
54
- # https://github.com/docker/build-push-action
55
- - name : Build test image
56
- id : build-test
57
-
58
- with :
59
- context : .
60
- load : true
61
- target : dev
62
- tags : ${{ env.TEST_TAG }}
63
- cache-from : type=gha
64
- cache-to : type=gha,mode=max
65
-
66
- - name : Test
67
- run : |
68
- docker run --rm ${{ env.TEST_TAG }} make ci-test
69
-
70
101
# Extract metadata (tags, labels) for Docker
71
102
# https://github.com/docker/metadata-action
72
103
- name : Extract Docker metadata
73
104
id : meta
74
105
75
106
with :
76
107
# list of Docker images to use as base name for tags
108
+ # <registry/<owner>/<repo_name>/<repo_name>-<target>
77
109
images : |
78
- ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
110
+ ${{ env.REGISTRY }}/${{ env.REGISTRY_PATH }}/${{ env. IMAGE_NAME }}-${{ matrix.docker_target }}
79
111
# generate Docker tags based on the following events/attributes
80
112
tags : |
81
113
type=sha
89
121
90
122
with :
91
123
context : .
92
- target : http_app
124
+ target : ${{ matrix.docker_target }}
93
125
platforms : linux/amd64,linux/arm64
94
126
push : true
95
127
tags : ${{ steps.meta.outputs.tags }}
0 commit comments