Skip to content

Commit c295d1a

Browse files
Copilotdannystaple
andcommitted
Implement Docker Compose staging test workflow
Co-authored-by: dannystaple <[email protected]>
1 parent 15d7415 commit c295d1a

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

.github/scripts/staging/Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
FROM centos/httpd:latest
2-
COPY . /var/www/html/
3-
COPY http2.conf /etc/httpd/conf/httpd.conf
1+
FROM httpd:2.4.64
2+
3+
# Install curl for healthcheck
4+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
5+
6+
# Copy the built site content (context is _site directory)
7+
COPY . /usr/local/apache2/htdocs/
8+
# Copy the Apache configuration (copied to _site in workflow as httpd.conf)
9+
COPY httpd.conf /usr/local/apache2/conf/httpd.conf

.github/workflows/on_call_staging_test.yaml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,34 @@ jobs:
1414
- name: extract site artifact
1515
run: |
1616
tar -xzf _site.tar.gz
17-
- name: Prepare for docker build
18-
run: |
19-
cp .github/scripts/staging/Dockerfile _site/
20-
cp .github/scripts/staging/http2.conf _site/
2117
2218
- name: Set up Docker Buildx
2319
uses: docker/setup-buildx-action@v3
2420

25-
- name: Build the container
26-
uses: docker/build-push-action@v6
27-
with:
28-
context: "_site"
29-
tags: orionrobots:latest
30-
cache-from: type=gha
31-
cache-to: type=gha,mode=max
32-
push: false
33-
load: true
34-
21+
- name: Prepare staging context
22+
run: |
23+
# Copy staging files into the _site directory for the docker build
24+
cp .github/scripts/staging/default.conf _site/httpd.conf
25+
3526
- name: Run as service and test
3627
run: |
37-
docker run --rm -d -p8080:80 --name orionrobots orionrobots:latest
38-
# Wait for the service to start
39-
sleep 10
40-
curl -I -L -f http://localhost:8080/
41-
curl -I -L -f http://localhost:8080/construction_guide.html
42-
curl -I -L -f http://localhost:8080/wiki/lego
43-
docker stop orionrobots
28+
# Start the staging service using docker compose (context will be _site now)
29+
docker compose up -d --build staging
30+
31+
# Wait for the health check to pass (healthcheck should handle readiness)
32+
echo "Waiting for service to be ready..."
33+
timeout 60 bash -c 'until curl -f http://localhost:8080/ >/dev/null 2>&1; do sleep 2; done'
34+
35+
# Perform the tests
36+
set +e # Don't exit on error so we can clean up
37+
exit_code=0
38+
39+
curl -I -f http://localhost:8080/ || exit_code=1
40+
curl -I -f http://localhost:8080/construction_guide.html || exit_code=1
41+
curl -I -f http://localhost:8080/wiki/lego || exit_code=1
42+
43+
# Stop the service regardless of test outcome
44+
docker compose stop staging
45+
46+
# Exit with the test result
47+
exit $exit_code

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,21 @@ services:
103103
command: ["http://http_serve"]
104104
profiles:
105105
- manual
106+
107+
# Staging service for on_call_staging_test workflow
108+
staging:
109+
build:
110+
context: ./_site
111+
dockerfile: ../.github/scripts/staging/Dockerfile
112+
cache_from:
113+
- type=gha
114+
cache_to:
115+
- type=gha,mode=max
116+
ports:
117+
- 8080:80
118+
healthcheck:
119+
test: ["CMD", "curl", "-o", "/dev/null", "-s", "http://localhost"]
120+
interval: 10s
121+
timeout: 5s
122+
retries: 5
123+
start_period: 30s

0 commit comments

Comments
 (0)