webapp workflow #79
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: webapp-workflow | |
run-name: webapp workflow | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- .github/actions/build-and-push-docker-image-to-github/action.yml | |
- .github/workflows/webapp.yml | |
- webapp/**/* | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
run-workflow: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js 18 | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: Install dependencies | |
working-directory: webapp | |
run: npm ci | |
- name: Build app for dev | |
# Only run on main | |
if: github.ref == 'refs/heads/main' | |
working-directory: webapp | |
env: | |
REACT_APP_ENGINE_URL: https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch | |
REACT_APP_ENGINE_WS_URL: wss://core-engine-swiss-ai-center.kube.isc.heia-fr.ch | |
# So it does not treat warnings as errors | |
CI: false | |
run: npm run build | |
- name: Build app for prod | |
# Only run on prod | |
if: github.ref == 'refs/heads/prod' | |
working-directory: webapp | |
env: | |
# TODO: Change this to the prod engine URL | |
REACT_APP_ENGINE_URL: https://core-engine-swiss-ai-center.kube.isc.heia-fr.ch | |
REACT_APP_ENGINE_WS_URL: wss://core-engine-swiss-ai-center.kube.isc.heia-fr.ch | |
# So it does not treat warnings as errors | |
CI: false | |
run: npm run build | |
- name: Build and push Docker image to GitHub | |
id: build-and-push-docker-image-to-github | |
# Only run on main | |
if: github.ref == 'refs/heads/main' | |
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/webapp | |
docker-image-context: ./webapp | |
- name: Prepare configuration files | |
# Only run on main | |
if: github.ref == 'refs/heads/main' | |
shell: bash | |
working-directory: webapp/kubernetes | |
run: | | |
# Set webapp version | |
docker_image_tags=(${{ steps.build-and-push-docker-image-to-github.outputs.docker-image-tags }}) | |
docker_image_sha_tag="${docker_image_tags[1]}" | |
yq ".spec.template.spec.containers[0].image = \"$docker_image_sha_tag\"" webapp.stateful.yml > new-webapp.stateful.yml && mv new-webapp.stateful.yml webapp.stateful.yml | |
- name: Deploy Webapp on the Kubernetes cluster (dev) | |
# Only run on main | |
if: github.ref == 'refs/heads/main' | |
uses: ./.github/actions/execute-command-on-kubernetes-cluster | |
with: | |
kube-config: ${{ secrets.KUBE_CONFIG_DEV }} | |
kube-namespace: swiss-ai-center-dev | |
kubectl-context: ./webapp/kubernetes | |
kubectl-args: | | |
apply \ | |
-f webapp.stateful.yml \ | |
-f webapp.service.yml \ | |
-f webapp.ingress.yml | |
- name: Deploy Webapp on the Kubernetes cluster (prod) | |
# Only run on prod | |
if: github.ref == 'refs/heads/prod' | |
uses: ./.github/actions/execute-command-on-kubernetes-cluster | |
with: | |
kube-config: ${{ secrets.KUBE_CONFIG_PROD }} | |
kube-namespace: swiss-ai-center-prod | |
kubectl-context: ./webapp/kubernetes | |
kubectl-args: | | |
apply \ | |
-f webapp.stateful.yml \ | |
-f webapp.service.yml \ | |
-f webapp.ingress.yml |