Skip to content

Commit cca2007

Browse files
committed
ci: fix Docker build step with tags
1 parent 3c955bd commit cca2007

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

.github/workflows/test-docker.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,54 @@ name: Test Docker Image
33
# TODO: set docker auth
44
on:
55
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:
1510

1611
jobs:
1712
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 }}
1921
steps:
2022
#
2123
# Checkout the code
2224
- name: Checkout
2325
uses: actions/checkout@v4
2426

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
2734
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
3140
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 }}
3550

3651
# Start the container in detached mode
3752
- 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 }}
3954

4055
# Wait for the container to be ready
4156
- name: Wait for container to be ready

0 commit comments

Comments
 (0)