Skip to content

core engine workflow #10

core engine workflow

core engine workflow #10

Workflow file for this run

# Documentation: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses
name: core-engine-workflow
run-name: core engine workflow
# Allow one concurrent deployment
concurrency:
group: "core-engine"
cancel-in-progress: true
on:
push:
branches:
- main
- prod
paths:
- .github/actions/build-and-push-docker-image-to-github/action.yml
- .github/actions/execute-command-on-kubernetes-cluster/action.yml
- .github/actions/lint-python-app/action.yml
- .github/actions/test-python-app/action.yml
- .github/workflows/core-engine.yml
- common-code/**/*
- core-engine/**/*
pull_request:
paths:
- .github/actions/build-and-push-docker-image-to-github/action.yml
- .github/actions/execute-command-on-kubernetes-cluster/action.yml
- .github/actions/lint-python-app/action.yml
- .github/actions/test-python-app/action.yml
- .github/workflows/core-engine.yml
- common-code/**/*
- core-engine/**/*
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Lint Python app
uses: ./.github/actions/lint-python-app
with:
python-app-path: ./core-engine
test:
needs: review
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Test Python app
uses: ./.github/actions/test-python-app
with:
python-app-path: ./core-engine
token: ${{ secrets.GITHUB_TOKEN }}
release:
needs: test
runs-on: ubuntu-latest
# Only run on main
if: success() && github.ref == 'refs/heads/main'
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Build and push Docker image to GitHub
id: build-and-push-docker-image-to-github
uses: ./.github/actions/build-and-push-docker-image-to-github
with:
docker-registry-username: ${{ github.actor }}
docker-registry-password: ${{ secrets.GITHUB_TOKEN }}
docker-image-name: swiss-ai-center/core-engine
docker-image-context: ./core-engine
outputs:
docker-image-tags: ${{ steps.build-and-push-docker-image-to-github.outputs.docker-image-tags }}
deploy:
needs: release
runs-on: ubuntu-latest
# Only run on main
if: success() && github.ref == 'refs/heads/main'
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Prepare configuration files
shell: bash
working-directory: core-engine/kubernetes
env:
HOST: https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch
ENVIRONMENT: production
LOG_LEVEL: info
DATABASE_URL: ${{ secrets.ENGINE_DEV_DATABASE_URL }}
DATABASE_CONNECT_ARGS: '"{}"'
S3_ACCESS_KEY_ID: ${{ secrets.ENGINE_DEV_S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.ENGINE_DEV_S3_SECRET_ACCESS_KEY }}
S3_HOST: ${{ secrets.ENGINE_DEV_S3_HOST }}
S3_REGION: eu-central-2
S3_BUCKET: engine
run: |
# Set Core Engine version
docker_image_tags=(${{ needs.release.outputs.docker-image-tags }})
docker_image_sha_tag="${docker_image_tags[1]}"
yq ".spec.template.spec.containers[0].image = \"$docker_image_sha_tag\"" core-engine.stateful.yml > new-core-engine.stateful.yml && mv new-core-engine.stateful.yml core-engine.stateful.yml
# Set Core Engine configuration (ConfigMap)
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' core-engine.config-map.yml | envsubst > new-core-engine.config-map.yml && mv new-core-engine.config-map.yml core-engine.config-map.yml
# Set Core Engine configuration (Ingress)
yq ".spec.rules[0].host = \"${HOST#*://}\"" core-engine.ingress.yml > new-core-engine.ingress.yml && mv new-core-engine.ingress.yml core-engine.ingress.yml
yq ".spec.tls[0].hosts[0] = \"${HOST#*://}\"" core-engine.ingress.yml > new-core-engine.ingress.yml && mv new-core-engine.ingress.yml core-engine.ingress.yml
- name: Deploy Core Engine on the Kubernetes cluster
uses: ./.github/actions/execute-command-on-kubernetes-cluster
with:
kube-config: ${{ secrets.KUBE_CONFIG_DEV }}
kube-namespace: swiss-ai-center-dev
kubectl-context: ./core-engine/kubernetes
kubectl-args: |
apply \
-f core-engine.config-map.yml \
-f core-engine.stateful.yml \
-f core-engine.service.yml \
-f core-engine.ingress.yml