44 push :
55 tags :
66 - ' [0-9]+.[0-9]+.[0-9]+*'
7+ # Allows building SNAPSHOT releases with the commit SHA inlcuded for testing purposes
78 workflow_dispatch :
89 # Test this workflow in PRs in case it changed
910 pull_request :
@@ -30,16 +31,32 @@ jobs:
3031 java-version : ' 11'
3132 - name : Set up Gradle
3233 uses : gradle/gradle-build-action@v3
34+
3335 - name : Configure the project version
34- env :
35- IS_PR : ${{ github.event_name == 'pull_request' }}
36+ id : version
3637 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"
3940 else
40- echo "${GITHUB_REF#refs/*/}" > version.txt
41+ version= "${GITHUB_REF#refs/*/}"
4142 fi
43+
44+ echo "${version}" > version.txt
4245 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+
4360 # Perform the build in a separate call to avoid trying to publish
4461 # something where the build already failed partially. This could happen
4562 # due to the use of the --continue flag in the publish step.
@@ -78,18 +95,28 @@ jobs:
7895 env :
7996 NODE_AUTH_TOKEN : ${{ secrets.ARTIFACTS_ITEMIS_CLOUD_NPM_TOKEN }}
8097 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 }}
81104 - name : Set up QEMU
82105 uses : docker/setup-qemu-action@v3
83106 - name : Set up Docker Buildx
84107 uses : docker/setup-buildx-action@v3
85108 with :
86109 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
91112 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