@@ -3,39 +3,54 @@ name: Test Docker Image
3
3
# TODO: set docker auth
4
4
on :
5
5
workflow_dispatch :
6
- # on:
7
- # push:
8
- # tags:
9
- # - "v*"
10
-
11
- env :
12
- IMAGE : nemoguardrails
13
- TEST_TAG : ${{ env.IMAGE }}:test
14
- LATEST_TAG : ${{ env.IMAGE }}:latest
6
+ push :
7
+ # tags:
8
+ # - "v*"
9
+ pull_request :
15
10
16
11
jobs :
17
12
docker :
18
- runs-on : ubuntu-latest
13
+ runs-on : ${{ matrix.os }}
14
+ strategy :
15
+ matrix :
16
+ # os: [ubuntu-latest, macos-15, windows-latest]
17
+ os : [ubuntu-latest]
18
+ env :
19
+ IMAGE : nemoguardrails
20
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
19
21
steps :
20
22
#
21
23
# Checkout the code
22
24
- name : Checkout
23
25
uses : actions/checkout@v4
24
26
25
- # Extract the tag version and set Docker tags
26
- - name : Get git tag and set Docker tags
27
+ # Get runner architecture
28
+ - name : Get runner architecture
29
+ id : runner-arch
30
+ run : echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
31
+
32
+ # Extract the PR SHA and set Docker tags
33
+ - name : Get PR SHA and set Docker tags
27
34
run : |
28
- VERSION=${GITHUB_REF#refs/tags/v}
29
- echo "VERSION=$VERSION" >> $GITHUB_ENV
30
- echo "VERSION_TAG=${{ env.IMAGE }}:$VERSION" >> $GITHUB_ENV
35
+ SHA=${GITHUB_SHA}
36
+ OS=${{ matrix.os }}
37
+ ARCH=${{ steps.runner-arch.outputs.arch }}
38
+ echo "SHA=$SHA" >> $GITHUB_ENV
39
+ echo "PR_TAG=${{ env.IMAGE }}:$SHA-$OS-$ARCH" >> $GITHUB_ENV
31
40
32
- # Build the Docker image
33
- - name : Build the Docker image
34
- run : docker build . --file Dockerfile --tag ${{ env.TEST_TAG }} --tag ${{ env.VERSION_TAG }}
41
+ - name : Set up Docker Buildx
42
+ uses : docker/setup-buildx-action@v3
43
+ - name : Build image
44
+ uses : docker/build-push-action@v6
45
+ with :
46
+ context : .
47
+ file : Dockerfile
48
+ load : true
49
+ tags : ${{ env.PR_TAG }}
35
50
36
51
# Start the container in detached mode
37
52
- name : Start container
38
- run : docker run -d --name test_container -p 8000:8000 ${{ env.TEST_TAG }}
53
+ run : docker run -d --name test_container -p 8000:8000 ${{ env.PR_TAG }}
39
54
40
55
# Wait for the container to be ready
41
56
- name : Wait for container to be ready
0 commit comments