digit-recognition workflow #203
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: digit-recognition_workflow | |
run-name: digit-recognition workflow | |
# Allow one concurrent deployment | |
concurrency: | |
group: "digit-recognition" | |
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/run-ml-experiment-with-dvc/action.yml | |
- .github/actions/test-python-app/action.yml | |
- .github/workflows/digit-recognition.yml | |
- common-code/**/* | |
- services/digit-recognition/**/* | |
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/run-ml-experiment-with-dvc/action.yml | |
- .github/actions/test-python-app/action.yml | |
- .github/workflows/digit-recognition.yml | |
- common-code/**/* | |
- services/digit-recognition/**/* | |
# 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/digit-recognition/model-serving | |
train: | |
needs: review | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
- name: Run ML experiment with DVC | |
uses: ./.github/actions/run-ml-experiment-with-dvc | |
with: | |
ml-experiment-path: ./services/digit-recognition/model-creation | |
s3-access-key-id: ${{ secrets.DIGIT_RECOGNITION_S3_ACCESS_KEY_ID }} | |
s3-secret-access-key: ${{ secrets.DIGIT_RECOGNITION_S3_SECRET_ACCESS_KEY }} | |
- name: Upload model | |
uses: actions/upload-artifact@v3 | |
with: | |
name: model | |
path: services/digit-recognition/model-creation/mnist_model.h5 | |
retention-days: 5 | |
test: | |
needs: train | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
- name: Download model | |
uses: actions/download-artifact@v3 | |
with: | |
name: model | |
path: services/digit-recognition/model-serving | |
- name: Test Python app | |
uses: ./.github/actions/test-python-app | |
with: | |
python-app-path: ./services/digit-recognition/model-serving | |
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: Download model | |
uses: actions/download-artifact@v3 | |
with: | |
name: model | |
path: services/digit-recognition/model-serving | |
- 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/digit-recognition | |
docker-image-context: ./services/digit-recognition/model-serving | |
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/digit-recognition/model-serving/kubernetes | |
env: | |
ENVIRONMENT: production | |
LOG_LEVEL: info | |
ENGINE_URLS: "'[\"https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch\"]'" | |
SERVICE_URL: https://digit-recognition-swiss-ai-center.kube.isc.heia-fr.ch | |
run: | | |
# Set digit-recognition 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\"" digit-recognition.stateful.yml > new-digit-recognition.stateful.yml && mv new-digit-recognition.stateful.yml digit-recognition.stateful.yml | |
# Set digit-recognition configuration (ConfigMap) | |
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' digit-recognition.config-map.yml | envsubst > new-digit-recognition.config-map.yml && mv new-digit-recognition.config-map.yml digit-recognition.config-map.yml | |
# Set digit-recognition configuration (Ingress) | |
yq ".spec.rules[0].host = \"${SERVICE_URL#*://}\"" digit-recognition.ingress.yml > new-digit-recognition.ingress.yml && mv new-digit-recognition.ingress.yml digit-recognition.ingress.yml | |
yq ".spec.tls[0].hosts[0] = \"${SERVICE_URL#*://}\"" digit-recognition.ingress.yml > new-digit-recognition.ingress.yml && mv new-digit-recognition.ingress.yml digit-recognition.ingress.yml | |
- name: Deploy digit-recognition 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/digit-recognition/model-serving/kubernetes | |
kubectl-args: | | |
apply \ | |
-f digit-recognition.config-map.yml \ | |
-f digit-recognition.stateful.yml \ | |
-f digit-recognition.service.yml \ | |
-f digit-recognition.ingress.yml | |
deploy-prod: | |
needs: release | |
runs-on: ubuntu-latest | |
# Only run on prod | |
if: success() && github.ref == 'refs/heads/prod' | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
- name: Prepare configuration files | |
shell: bash | |
working-directory: services/digit-recognition/model-serving/kubernetes | |
env: | |
ENVIRONMENT: production | |
LOG_LEVEL: info | |
ENGINE_URLS: "'[\"https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch\"]'" | |
SERVICE_URL: https://digit-recognition-swiss-ai-center.kube.isc.heia-fr.ch | |
run: | | |
# Set digit-recognition 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\"" digit-recognition.stateful.yml > new-digit-recognition.stateful.yml && mv new-digit-recognition.stateful.yml digit-recognition.stateful.yml | |
# Set digit-recognition configuration (ConfigMap) | |
yq '.data = (.data | to_entries | map({"key": .key, "value": "${" + .key + "}"}) | from_entries)' digit-recognition.config-map.yml | envsubst > new-digit-recognition.config-map.yml && mv new-digit-recognition.config-map.yml digit-recognition.config-map.yml | |
# Set digit-recognition configuration (Ingress) | |
yq ".spec.rules[0].host = \"${SERVICE_URL#*://}\"" digit-recognition.ingress.yml > new-digit-recognition.ingress.yml && mv new-digit-recognition.ingress.yml digit-recognition.ingress.yml | |
yq ".spec.tls[0].hosts[0] = \"${SERVICE_URL#*://}\"" digit-recognition.ingress.yml > new-digit-recognition.ingress.yml && mv new-digit-recognition.ingress.yml digit-recognition.ingress.yml | |
- name: Deploy digit-recognition 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/digit-recognition/model-serving/kubernetes | |
kubectl-args: | | |
apply \ | |
-f digit-recognition.config-map.yml \ | |
-f digit-recognition.stateful.yml \ | |
-f digit-recognition.service.yml \ | |
-f digit-recognition.ingress.yml |