Slower, but even steadier 🐇 #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
pull_request: | |
types: [opened, synchronize, closed] | |
workflow_dispatch: | |
inputs: | |
test: | |
type: boolean | |
description: 'Run tests' | |
required: true | |
default: true | |
deploy: | |
type: boolean | |
description: 'Deploy application' | |
required: true | |
default: false | |
jobs: | |
build-api: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: docker/setup-buildx-action@v1 | |
- name: Build API Image | |
run: | | |
docker build -t api:latest ./api | |
docker save api:latest -o api_image.tar | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: api_image | |
path: api_image.tar | |
retention-days: 7 | |
build-app: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: docker/setup-buildx-action@v1 | |
- name: Build Testing Image | |
run: | | |
docker build --build-arg VITE_HUU_API_BASE_URL=http://127.0.0.1:8080/api --target development --tag app:latest-test ./app | |
docker save app:latest-test -o app_test_image.tar | |
- name: Build Production Image | |
run: | | |
docker build --build-arg VITE_HUU_API_BASE_URL=http://127.0.0.1:8080/api --target production --tag app:latest ./app | |
docker save app:latest -o app_image.tar | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: app_test_image | |
path: app_test_image.tar | |
retention-days: 7 | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: app_image | |
path: app_image.tar | |
retention-days: 7 | |
test-api: | |
runs-on: ubuntu-latest | |
needs: [build-api] | |
if: >- | |
github.event_name == 'push' || | |
github.event.pull_request || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.test) | |
env: | |
COGNITO_REGION: ${{ secrets.COGNITO_REGION }} | |
COGNITO_ACCESS_ID: ${{ secrets.COGNITO_ACCESS_ID }} | |
COGNITO_ACCESS_KEY: ${{ secrets.COGNITO_ACCESS_KEY }} | |
steps: | |
- name: Download API Image Artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: api_image | |
path: . | |
- name: Load API Image | |
run: docker load -i api_image.tar | |
- name: Run Debug Tests | |
run: docker run api:latest pytest | |
- name: Run Release Tests | |
run: docker run --env COGNITO_REGION --env COGNITO_ACCESS_ID --env COGNITO_ACCESS_KEY api:latest "pytest --mode=release" | |
test-app: | |
runs-on: ubuntu-latest | |
needs: [build-app, build-api] | |
steps: | |
- name: Download API Images | |
uses: actions/download-artifact@v3 | |
with: | |
name: api_image | |
path: . | |
- name: Download App Images | |
uses: actions/download-artifact@v3 | |
with: | |
name: app_test_image | |
path: . | |
- name: Load Images | |
run: | | |
docker load -i api_image.tar | |
docker load -i app_test_image.tar | |
- name: Launch networked test application | |
run: | | |
docker network create huu-test-network | |
docker run --network huu-test-network -d --rm --name backend --env HOST=0.0.0.0 api:latest | |
docker run --network huu-test-network -d --rm --name frontend --env VITE_HUU_API_BASE_URL=http://backend:api app:latest-test "npx vite --host" | |
docker run --network huu-test-network -d --name cypress_tests --env CYPRESS_BASE_URL="http:frontend:4040" --env CYPRESS_REAL_EMAIL="[email protected]" --env CYPRESS_REAL_PASSWORD="totallyfake" app:latest-test "npx cypress run" | |
- name: Wait for Test to Complete | |
run: | | |
while [ $(docker container inspect -f '{{.State.Running}}' cypress_tests) = "true" ]; do | |
sleep 5 | |
done | |
- name: Stop Backend and Frontend Containers | |
if: always() | |
run: | | |
docker stop backend frontend | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [build-api, build-app] | |
if: >- | |
(github.event_name == 'push' && github.ref == 'refs/heads/main') || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy) | |
steps: | |
- uses: actions/checkout@v2 |