4
4
push :
5
5
tags :
6
6
- ' [0-9]+.[0-9]+.[0-9]+*'
7
+ # Allows building SNAPSHOT releases with the commit SHA inlcuded for testing purposes
7
8
workflow_dispatch :
8
9
# Test this workflow in PRs in case it changed
9
10
pull_request :
@@ -30,16 +31,32 @@ jobs:
30
31
java-version : ' 11'
31
32
- name : Set up Gradle
32
33
uses : gradle/gradle-build-action@v3
34
+
33
35
- name : Configure the project version
34
- env :
35
- IS_PR : ${{ github.event_name == 'pull_request' }}
36
+ id : version
36
37
run : |-
37
- if [[ "$IS_PR " = 'true ' ]]; then
38
- echo "0.0.1-SNAPSHOT" > version.txt
38
+ if [[ "${{ github.event_name }} " == 'pull_request' || "${{ github.event_name }}" == 'workflow_dispatch ' ]]; then
39
+ version= "0.0.1-${GITHUB_SHA:0:7}- SNAPSHOT"
39
40
else
40
- echo "${GITHUB_REF#refs/*/}" > version.txt
41
+ version= "${GITHUB_REF#refs/*/}"
41
42
fi
43
+
44
+ echo "${version}" > version.txt
42
45
cat version.txt
46
+
47
+ echo "VERSION=${version}" >> $GITHUB_OUTPUT
48
+ - name : Determine Docker metadata
49
+ id : meta
50
+ uses : docker/metadata-action@v5
51
+ with :
52
+ images : |
53
+ modelix/model-server
54
+ modelix/modelix-model
55
+ tags : |
56
+ type=raw,value=${{ steps.version.outputs.VERSION }},enable=true
57
+ type=raw,value=latest,event=tag
58
+ type=ref,event=tag
59
+
43
60
# Perform the build in a separate call to avoid trying to publish
44
61
# something where the build already failed partially. This could happen
45
62
# due to the use of the --continue flag in the publish step.
@@ -78,18 +95,28 @@ jobs:
78
95
env :
79
96
NODE_AUTH_TOKEN : ${{ secrets.ARTIFACTS_ITEMIS_CLOUD_NPM_TOKEN }}
80
97
IS_PR : ${{ github.event_name == 'pull_request' }}
98
+ # Try to log in early. If this fails, there's no reason to perform the remaining steps
99
+ - name : Log in to Docker Hub
100
+ uses : docker/login-action@v3
101
+ with :
102
+ username : ${{ secrets.DOCKER_HUB_USER }}
103
+ password : ${{ secrets.DOCKER_HUB_KEY }}
81
104
- name : Set up QEMU
82
105
uses : docker/setup-qemu-action@v3
83
106
- name : Set up Docker Buildx
84
107
uses : docker/setup-buildx-action@v3
85
108
with :
86
109
platforms : linux/amd64,linux/arm64
87
- - name : Build and Publish Docker
88
- # As publishing is currently baked into the scripts, we can't test this
89
- # in PRs
90
- if : ${{ github.event_name != 'pull_request' }}
110
+ - name : Build and publish model-server Docker image
111
+ uses : docker/build-push-action@v5
91
112
env :
92
- DOCKER_HUB_USER : ${{ secrets.DOCKER_HUB_USER }}
93
- DOCKER_HUB_KEY : ${{ secrets.DOCKER_HUB_KEY }}
94
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
95
- run : ./docker-ci.sh
113
+ # We only push the resulting image when we are on release tag (i.e., the only time we have a push event) or on
114
+ # manual request via the workflow_dispatch event.
115
+ PUSH : ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
116
+ with :
117
+ context : ./model-server
118
+ file : ./model-server/Dockerfile
119
+ platforms : linux/amd64,linux/arm64
120
+ push : ${{ env.PUSH }}
121
+ tags : ${{ steps.meta.outputs.tags }}
122
+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments