Repository navigation
93 lines (82 loc) · 2.65 KB
/
Copy pathtest-docker.yml
File metadata and controls
93 lines (82 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Test Docker Image
# TODO: set docker auth
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0"
push:
tags:
- "v*"
pull_request:
paths:
- "Dockerfile"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/test-docker.yml"
permissions:
contents: read
jobs:
docker:
runs-on: ubuntu-latest
env:
IMAGE: nemoguardrails
steps:
#
# Checkout the code
- name: Checkout
uses: actions/checkout@v7.0.1
with:
persist-credentials: false
# Get runner architecture
- name: Get runner architecture
id: runner-arch
run: echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
- name: Set Docker tags
run: |
ARCH=${STEPS_RUNNER_ARCH_OUTPUTS_ARCH}
echo "TEST_TAG=${{ env.IMAGE }}:${{ github.sha }}-$ARCH" >> $GITHUB_ENV
env:
STEPS_RUNNER_ARCH_OUTPUTS_ARCH: ${{ steps.runner-arch.outputs.arch }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0
- name: Build image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: Dockerfile
load: true
tags: ${{ env.TEST_TAG }}
cache-from: type=gha,scope=nemoguardrails-test
cache-to: type=gha,mode=max,scope=nemoguardrails-test
# Start the container in detached mode
- name: Start container
run: docker run -d --name test_container -p 8000:8000 ${TEST_TAG}
# Wait for the container to be ready
- name: Wait for container to be ready
timeout-minutes: 3
run: |
echo "Waiting for container to be ready..."
until curl --output /dev/null --silent --fail http://localhost:8000/v1/rails/configs; do
printf '.'
sleep 2
done
echo "Container is ready!"
# Perform a health check on the server
- name: Check server status
run: |
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/v1/rails/configs)
if [ "$RESPONSE_CODE" -ne 200 ]; then
echo "Server responded with code $RESPONSE_CODE."
exit 1
fi
# Run additional tests on the running container
- name: Run tests
run: |
# Example test command
curl -f http://localhost:8000/v1/rails/configs
# Add more tests here if needed
# Stop and remove the container
- name: Stop and remove container
run: |
docker stop test_container
docker rm test_container