average-shade workflow #222
Workflow file for this run
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
# Documentation: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses | |
name: average-shade_workflow | |
run-name: average-shade workflow | |
# Allow one concurrent deployment | |
concurrency: | |
group: "average-shade" | |
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/average-shade.yml | |
- common-code/**/* | |
- services/average-shade/**/* | |
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/average-shade.yml | |
- common-code/**/* | |
- services/average-shade/**/* | |
# 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: ./services/average-shade | |
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: ./services/average-shade | |
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/average-shade | |
docker-image-context: ./services/average-shade | |
outputs: | |
docker-image-tags: ${{ steps.build-and-push-docker-image-to-github.outputs.docker-image-tags }} | |
deploy-dev: | |
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: services/average-shade/kubernetes | |
env: | |
ENVIRONMENT: production | |
LOG_LEVEL: info | |
ENGINE_URLS: "'[\"https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch\"]'" | |
SERVICE_URL: https://average-shade-swiss-ai-center.kube.isc.heia-fr.ch | |
run: | | |
# Set average-shade 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\"" average-shade.stateful.yml > new-average-shade.stateful.yml && mv new-average-shade.stateful.yml average-shade.stateful.yml | |
# Set average-shade configuration (ConfigMap) | |
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' average-shade.config-map.yml | envsubst > new-average-shade.config-map.yml && mv new-average-shade.config-map.yml average-shade.config-map.yml | |
# Set average-shade configuration (Ingress) | |
yq ".spec.rules[0].host = \"${SERVICE_URL#*://}\"" average-shade.ingress.yml > new-average-shade.ingress.yml && mv new-average-shade.ingress.yml average-shade.ingress.yml | |
yq ".spec.tls[0].hosts[0] = \"${SERVICE_URL#*://}\"" average-shade.ingress.yml > new-average-shade.ingress.yml && mv new-average-shade.ingress.yml average-shade.ingress.yml | |
- name: Deploy average-shade 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: ./services/average-shade/kubernetes | |
kubectl-args: | | |
apply \ | |
-f average-shade.config-map.yml \ | |
-f average-shade.stateful.yml \ | |
-f average-shade.service.yml \ | |
-f average-shade.ingress.yml | |
deploy-prod: | |
needs: release | |
runs-on: ubuntu-latest | |
# Only run on main | |
if: success() && github.ref == 'refs/heads/prod' | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
- name: Prepare configuration files | |
shell: bash | |
working-directory: services/average-shade/kubernetes | |
env: | |
ENVIRONMENT: production | |
LOG_LEVEL: info | |
ENGINE_URLS: "'[\"https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch\"]'" | |
SERVICE_URL: https://average-shade-swiss-ai-center.kube.isc.heia-fr.ch | |
run: | | |
# Set average-shade 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\"" average-shade.stateful.yml > new-average-shade.stateful.yml && mv new-average-shade.stateful.yml average-shade.stateful.yml | |
# Set average-shade configuration (ConfigMap) | |
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' average-shade.config-map.yml | envsubst > new-average-shade.config-map.yml && mv new-average-shade.config-map.yml average-shade.config-map.yml | |
# Set average-shade configuration (Ingress) | |
yq ".spec.rules[0].host = \"${SERVICE_URL#*://}\"" average-shade.ingress.yml > new-average-shade.ingress.yml && mv new-average-shade.ingress.yml average-shade.ingress.yml | |
yq ".spec.tls[0].hosts[0] = \"${SERVICE_URL#*://}\"" average-shade.ingress.yml > new-average-shade.ingress.yml && mv new-average-shade.ingress.yml average-shade.ingress.yml | |
- name: Deploy average-shade on the Kubernetes cluster | |
uses: ./.github/actions/execute-command-on-kubernetes-cluster | |
with: | |
kube-config: ${{ secrets.KUBE_CONFIG_PROD }} | |
kube-namespace: swiss-ai-center-prod | |
kubectl-context: ./services/average-shade/kubernetes | |
kubectl-args: | | |
apply \ | |
-f average-shade.config-map.yml \ | |
-f average-shade.stateful.yml \ | |
-f average-shade.service.yml \ | |
-f average-shade.ingress.yml |