Skip to content

More logs, More Problems 🙈 #17

More logs, More Problems 🙈

More logs, More Problems 🙈 #17

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: Test with mocking
run: |
docker network create huu-test-network
docker run --network huu-test-network -d --name frontend_mock --env VITE_HUU_API_BASE_URL=http://backend:api app:latest-test "npx vite --host"
docker run --network huu-test-network --name cypress_tests_mock --env CYPRESS_BASE_URL="http://frontend_mock:4040" --env CYPRESS_USE_MOCK=true app:latest-test "npx cypress run"
- name: Test without mocking
run: |
docker run --network huu-test-network -d --name backend --env HOST=0.0.0.0 api:latest
docker run --network huu-test-network -d --name frontend_nomock --env VITE_HUU_API_BASE_URL=http://backend:api app:latest-test "npx vite --host"
sleep 10
docker exec backend curl http://localhost:8080/api/auth/signup/host -H "accept: application/json" -H "Content-Type: application/json" -d '{\"email\": \"nottarealemail@gmail.com\", \"password\": \"alskdf454$Adfa\"}'
docker run --network huu-test-network --name cypress_tests_nomock --env CYPRESS_BASE_URL="http://frontend_nomock:4040" --env CYPRESS_USE_MOCK=false --env CYPRESS_REAL_EMAIL='nottarealemail@gmail.com' --env CYPRESS_REAL_PASSWORD='alskdf454$Adfa' app:latest-test "npx cypress run"
- name: Wait for Test to Complete
run: |
while true; do
mock_status=$(docker container inspect -f '{{.State.Running}}' cypress_tests_mock)
nomock_status=$(docker container inspect -f '{{.State.Running}}' cypress_tests_nomock)
if [ "$mock_status" = "false" ] && [ "$nomock_status" = "false" ]; then
break
fi
sleep 5
done
- name: Print microservice logs
if: always()
run: |
docker logs frontend_mock
docker logs backend
docker logs frontend_nomock
- name: Stop Backend and Frontend Containers
if: always()
run: |
docker stop backend frontend_mock frontend_nomock
deploy:
runs-on: ubuntu-latest
needs: [build-api, build-app, test-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