diff --git a/.github/scripts/staging/Dockerfile b/.github/scripts/staging/Dockerfile index 292ada9a..be9e47c5 100644 --- a/.github/scripts/staging/Dockerfile +++ b/.github/scripts/staging/Dockerfile @@ -1,3 +1,9 @@ -FROM centos/httpd:latest -COPY . /var/www/html/ -COPY http2.conf /etc/httpd/conf/httpd.conf +FROM httpd:2.4.64 + +# Install curl for healthcheck +RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* + +# Copy the built site content (context is _site directory) +COPY . /usr/local/apache2/htdocs/ +# Copy the Apache configuration (copied to _site in workflow as httpd.conf) +COPY httpd.conf /usr/local/apache2/conf/httpd.conf diff --git a/.github/workflows/on_call_staging_test.yaml b/.github/workflows/on_call_staging_test.yaml index c6f14995..d7d5fd79 100644 --- a/.github/workflows/on_call_staging_test.yaml +++ b/.github/workflows/on_call_staging_test.yaml @@ -14,30 +14,31 @@ jobs: - name: extract site artifact run: | tar -xzf _site.tar.gz - - name: Prepare for docker build - run: | - cp .github/scripts/staging/Dockerfile _site/ - cp .github/scripts/staging/http2.conf _site/ - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build the container - uses: docker/build-push-action@v6 - with: - context: "_site" - tags: orionrobots:latest - cache-from: type=gha - cache-to: type=gha,mode=max - push: false - load: true - + - name: Prepare staging context + run: | + # Copy staging files into the _site directory for the docker build + cp .github/scripts/staging/default.conf _site/httpd.conf + - name: Run as service and test run: | - docker run --rm -d -p8080:80 --name orionrobots orionrobots:latest - # Wait for the service to start - sleep 10 - curl -I -L -f http://localhost:8080/ - curl -I -L -f http://localhost:8080/construction_guide.html - curl -I -L -f http://localhost:8080/wiki/lego - docker stop orionrobots + # Start the staging service using docker compose with --wait for health checks + # Use CI-specific override for GitHub Actions cache + docker compose -f docker-compose.yml -f docker-compose.ci.yml up -d --build --wait staging + + # Perform the tests + set +e # Don't exit on error so we can clean up + exit_code=0 + + curl -I -f http://localhost:8080/ || exit_code=1 + curl -I -f http://localhost:8080/construction_guide.html || exit_code=1 + curl -I -f http://localhost:8080/wiki/lego || exit_code=1 + + # Stop the service regardless of test outcome + docker compose -f docker-compose.yml -f docker-compose.ci.yml stop staging + + # Exit with the test result + exit $exit_code diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 00000000..0e550648 --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,7 @@ +services: + staging: + build: + cache_from: + - type=gha + cache_to: + - type=gha,mode=max \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1c5e4eed..fe3f9a67 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,3 +103,17 @@ services: command: ["http://http_serve"] profiles: - manual + + # Staging service for on_call_staging_test workflow + staging: + build: + context: ./_site + dockerfile: ../.github/scripts/staging/Dockerfile + ports: + - 8080:80 + healthcheck: + test: ["CMD", "curl", "-o", "/dev/null", "-s", "http://localhost"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 30s