Deployment #276
This file contains hidden or 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: Deployment | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: ["Application tests"] | |
| branches: [master] | |
| types: [completed] | |
| release: | |
| types: [published] | |
| env: | |
| REGISTRY: ghcr.io | |
| APP_IMAGE_NAME: ${{ github.repository_owner }}/vd-designer | |
| K8S_NAMESPACE: viewdefinition | |
| jobs: | |
| app-docker: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} | |
| permissions: | |
| contents: read | |
| actions: read | |
| packages: write | |
| id-token: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - uses: docker/setup-buildx-action@v3 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }} | |
| type=raw,value=latest,enable=${{ github.event_name != 'release' }} | |
| - name: Build and push client image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| context: . | |
| file: ./docker/app.dockerfile | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| annotations: ${{ steps.meta.outputs.annotations }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # | |
| dev-deployment: | |
| name: Deploy to dev | |
| needs: | |
| - app-docker | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name != 'schedule' && github.event_name != 'release' }} | |
| # environment: dev | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install SSH Key | |
| uses: shimataro/ssh-key-action@v2 | |
| with: | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| known_hosts: "just-a-placeholder-so-we-dont-get-errors" | |
| - name: Adding Known Hosts | |
| run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
| - name: Upload compose file with rsync | |
| run: | | |
| tee .env <<EOF | |
| ${{ secrets.DEV_ENV_FILE }} | |
| EOF | |
| rsync -avz ./{compose.yml,.env} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/vd_designer | |
| rm .env | |
| - name: Relaunch docker | |
| run: > | |
| ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} | |
| "echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin | |
| docker compose down; docker compose --profile dev up -d" | |
| # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- # | |
| prod-deployment: | |
| name: Deploy to prod | |
| needs: | |
| - app-docker | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'release' }} | |
| # environment: prod | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: olegtarasov/get-tag@v2.1.3 | |
| id: versionTag | |
| with: | |
| tagRegex: "v(.*)" | |
| - name: Authorize Google Account | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: "${{ secrets.GCLOUD_SERVICE_ACCOUNT_KEY }}" | |
| - name: Get the GKE credentials | |
| uses: google-github-actions/get-gke-credentials@v2 | |
| with: | |
| cluster_name: aidbox | |
| location: us-central1-a | |
| - name: Apply resources | |
| run: |- | |
| kubectl apply -n ${{ env.K8S_NAMESPACE }} -f ./k8s/database | |
| kubectl apply -n ${{ env.K8S_NAMESPACE }} -f ./k8s/app | |
| kubectl apply -n ${{ env.K8S_NAMESPACE }} -f ./k8s/ingress.yaml | |
| sed -i 's#{VERSION_TAG}#${{ steps.versionTag.outputs.tag }}#g' k8s/kustomization.yaml | |
| kubectl kustomize ./k8s | kubectl apply -n ${{ env.K8S_NAMESPACE }} -f - | |
| kubectl rollout status statefulset/vd-designer -n ${{ env.K8S_NAMESPACE }} | |
| kubectl get services -n ${{ env.K8S_NAMESPACE }} -o wide |