New attempt at fixing production build. #431
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: "Tests" | |
on: | |
push: | |
paths-ignore: | |
- "documentation/**" | |
- "templates/**" | |
jobs: | |
# Make data lists available across jobs for use in matrix. | |
matrix: | |
runs-on: "ubuntu-latest" | |
outputs: | |
all-apps: ${{ steps.set-apps.outputs.full-json }} | |
deploy-apps: ${{ steps.set-apps.outputs.deploy-json }} | |
all-environments: ${{ steps.set-environments.outputs.full-json }} | |
deploy-environments: ${{ steps.set-environments.outputs.deploy-json }} | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- id: "set-apps" | |
name: "Read apps into matrix" | |
uses: "./.github/actions/set-json-output" | |
with: | |
filename: "data/apps.json" | |
- id: "set-environments" | |
name: "Read environments into matrix" | |
uses: "./.github/actions/set-json-output" | |
with: | |
filename: "data/environments.json" | |
# Update the pip cache with new requirements. | |
update-pip-cache: | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Setup python cache" | |
uses: "actions/setup-python@v4" | |
with: | |
python-version: "3.13" | |
cache: "pip" | |
- name: "Fill python cache" | |
run: "pip install -r ./backend/requirements.txt -r ./backend/requirements-develop.txt" | |
# Generate the protos. | |
generate-protos: | |
runs-on: "ubuntu-latest" | |
needs: [ "update-pip-cache" ] | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Setup python cache" | |
uses: "actions/setup-python@v4" | |
with: | |
python-version: "3.13" | |
cache: "pip" | |
- name: "Generate protos" | |
run: "./scripts/generate_protos.sh" | |
- name: "Upload python protos" | |
uses: "actions/upload-artifact@v4" | |
with: | |
name: "protos-python" | |
path: "backend/khaleesi/proto/" | |
retention-days: 2 | |
- name: "Upload typescript protos" | |
uses: "actions/upload-artifact@v4" | |
with: | |
name: "protos-typescript" | |
path: "frontend/khaleesi/app/khaleesi/proto/" | |
retention-days: 2 | |
# Build the backend base images with new requirements. | |
build-backend-base-images: | |
runs-on: "ubuntu-latest" | |
needs: [ "update-pip-cache" ] | |
strategy: | |
matrix: | |
image: [ "construction", "image" ] | |
env: | |
base-image-version: "1.0.0" | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Setup python cache" | |
uses: "actions/setup-python@v4" | |
with: | |
python-version: "3.13" | |
cache: "pip" | |
- name: "Build image" | |
run: ./scripts/util/build-backend-base.sh ${{ env.base-image-version }} ${{ matrix.image }} | |
- name: "Upload image as artifact" | |
uses: "./.github/actions/upload-image" | |
with: | |
image: khaleesi/base/backend-${{ matrix.image }}:${{ env.base-image-version }} | |
# Verify the helm templates. | |
test-helm: | |
runs-on: "ubuntu-latest" | |
needs: [ "matrix" ] | |
strategy: | |
matrix: | |
app: ${{ fromJson(needs.matrix.outputs.deploy-apps) }} | |
environment: ${{ fromJson(needs.matrix.outputs.all-environments) }} | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Helm lint cluster" | |
run: "helm lint ./kubernetes/khaleesi-ninja-cluster" | |
- name: "Helm lint environment" | |
run: | | |
helm lint ./kubernetes/khaleesi-ninja-environment \ | |
--values ./kubernetes/configuration/environment/${{ matrix.environment.name }}.yml | |
- name: "Helm lint site" | |
run: | | |
helm lint ./kubernetes/khaleesi-ninja-site \ | |
--values ./kubernetes/configuration/site/${{ matrix.app.site }}.yml \ | |
--values ./kubernetes/configuration/environment/${{ matrix.environment.name }}.yml | |
- name: "Helm lint app" | |
run: | | |
helm lint ./kubernetes/khaleesi-ninja-app \ | |
--values ./kubernetes/configuration/site/${{ matrix.app.site }}.yml \ | |
--values ./kubernetes/configuration/type/${{ matrix.app.type }}.yml \ | |
--values ./kubernetes/configuration/app/${{ matrix.app.site }}/${{ matrix.app.name }}.yml \ | |
--values ./kubernetes/configuration/environment/${{ matrix.environment.name }}.yml | |
# Build the images for reuse. | |
build: | |
runs-on: "ubuntu-latest" | |
needs: [ "matrix", "generate-protos", "build-backend-base-images" ] | |
strategy: | |
matrix: | |
app: ${{ fromJson(needs.matrix.outputs.all-apps) }} | |
env: | |
base-image-version: "1.0.0" | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Prepare backend build" | |
if: matrix.app.type == 'micro' | |
uses: "./.github/actions/prepare-backend-build" | |
with: | |
site: ${{ matrix.app.site }} | |
app: ${{ matrix.app.name }} | |
- name: "Download typescript protos" | |
if: matrix.app.type == 'frontend' | |
uses: "actions/download-artifact@v4" | |
with: | |
name: "protos-typescript" | |
path: frontend/${{ matrix.app.site }}/app/khaleesi/proto/ | |
- name: "Build the development container image" | |
run: ./scripts/build.sh ${{ matrix.app.site }} ${{ matrix.app.name }} ${{ matrix.app.type }} ${{ matrix.app.version }} ${{ matrix.app.deploy }} development | |
- name: "Build the production container image" | |
run: ./scripts/build.sh ${{ matrix.app.site }} ${{ matrix.app.name }} ${{ matrix.app.type }} ${{ matrix.app.version }} ${{ matrix.app.deploy }} production | |
- name: "Upload development image" | |
uses: "./.github/actions/upload-image" | |
with: | |
image: khaleesi-ninja/${{ matrix.app.site }}/${{ matrix.app.name }}:latest-development | |
- name: "Upload production image" | |
uses: "./.github/actions/upload-image" | |
with: | |
image: khaleesi-ninja/${{ matrix.app.site }}/${{ matrix.app.name }}:latest-production | |
# Execute the unit tests in parallel. | |
unit-test: | |
runs-on: "ubuntu-latest" | |
needs: [ "matrix", "build" ] | |
strategy: | |
matrix: | |
app: ${{ fromJson(needs.matrix.outputs.all-apps) }} | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Download image" | |
uses: "./.github/actions/download-image" | |
with: | |
image: khaleesi-ninja/${{ matrix.app.site }}/${{ matrix.app.name }}:latest-development | |
- name: "Execute the container test" | |
run: ./scripts/test.sh ${{ matrix.app.site }} ${{ matrix.app.name }} ${{ matrix.app.type }} ${{ matrix.app.version }} ${{ matrix.app.deploy }} | |
- name: "Upload coverage to codecov" | |
if: ${{ always() }} | |
uses: "codecov/codecov-action@v3" | |
with: | |
token: ${{secrets.CODECOV_TOKEN}} | |
flags: "integration" | |
fail_ci_if_error: true | |
directory: "temp/" | |
# Execute the E2E tests in parallel. | |
e2e-test: | |
runs-on: "ubuntu-latest" | |
needs: [ "matrix", "build", "test-helm" ] | |
strategy: | |
matrix: | |
environment: ${{ fromJson(needs.matrix.outputs.deploy-environments) }} | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Start minikube" | |
uses: "medyagh/setup-minikube@latest" | |
- name: "Setup helm" | |
uses: "azure/setup-helm@v3" | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Set up the cluster" | |
run: "./scripts/operations/setup_cluster.sh" | |
- name: "Set up the environment" | |
run: ./scripts/operations/setup_environment.sh ${{ matrix.environment.name }} | |
- name: "Download all images" | |
uses: "actions/download-artifact@v4" | |
with: | |
pattern: khaleesi-ninja_*_*.latest-${{ matrix.environment.container_mode }} | |
path: /tmp | |
merge-multiple: true | |
- name: "Load all images into minikube" | |
run: ls -1 /tmp/khaleesi-ninja_*_*.latest-${{ matrix.environment.container_mode }} | xargs --no-run-if-empty -L 1 minikube image load | |
- name: "Wait for the environment to be ready" | |
run: kubectl -n "khaleesi-ninja-${{ matrix.environment.name }}" wait pod -l job!=true --for condition=ready --timeout 5m | |
- name: "Spin up the environment" | |
run: ./scripts/ci/deploy.sh ${{ matrix.environment.name }} | |
- name: "Wait for successful spinup" | |
run: kubectl -n khaleesi-ninja-${{ matrix.environment.name }} wait pod -l job!=true --for condition=ready --timeout 2m | |
- name: "Check the status" | |
if: always() | |
run: kubectl -n khaleesi-ninja-${{ matrix.environment.name }} get pod | |
- name: "DEBUG" | |
if: always() | |
run: kubectl -n khaleesi-ninja-${{ matrix.environment.name }} logs --tail 100 -l site=core -l app=sawmill | |
# Clean up cache. | |
clean-cache: | |
runs-on: "ubuntu-latest" | |
needs: [ "unit-test", "e2e-test" ] | |
if: always() | |
permissions: | |
actions: "write" | |
steps: | |
- name: "Checkout repository" | |
uses: "actions/checkout@v3" | |
- name: "Clean up cache." | |
uses: "./.github/actions/clean-cache" |