|
| 1 | +name: Build and Deploy to Dev |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + image_tag: |
| 7 | + description: 'Image tag to build and deploy (defaults to branch name)' |
| 8 | + required: false |
| 9 | + default: '' |
| 10 | + |
| 11 | +env: |
| 12 | + app-name: carrot |
| 13 | + repo-owner: health-informatics-uon |
| 14 | + registry: ghcr.io |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + packages: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-and-deploy: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + environment: dev |
| 24 | + steps: |
| 25 | + - name: Check out the repo |
| 26 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 27 | + |
| 28 | + - name: Set up QEMU |
| 29 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
| 30 | + |
| 31 | + - name: Set up Docker Buildx |
| 32 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 33 | + |
| 34 | + - name: Docker Login |
| 35 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 36 | + with: |
| 37 | + registry: ${{ env.registry }} |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Set timestamp env var |
| 42 | + run: echo "RUN_TIMESTAMP=$(TZ="Etc/UTC" date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV |
| 43 | + |
| 44 | + - name: Set default image tag |
| 45 | + run: | |
| 46 | + if [ -z "${{ github.event.inputs.image_tag }}" ]; then |
| 47 | + # Use branch name, replacing slashes with dashes |
| 48 | + BRANCH_TAG=$(echo "${{ github.ref_name }}" | sed 's/\//-/g') |
| 49 | + echo "IMAGE_TAG=$BRANCH_TAG" >> $GITHUB_ENV |
| 50 | + else |
| 51 | + echo "IMAGE_TAG=${{ github.event.inputs.image_tag }}" >> $GITHUB_ENV |
| 52 | + fi |
| 53 | +
|
| 54 | + # Build and push backend |
| 55 | + - name: Extract backend Docker metadata |
| 56 | + id: backend_meta |
| 57 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 58 | + with: |
| 59 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend |
| 60 | + tags: | |
| 61 | + type=raw,value=${{ env.IMAGE_TAG }} |
| 62 | + type=raw,value=${{ github.sha }} |
| 63 | + type=raw,value=${{ env.RUN_TIMESTAMP }} |
| 64 | +
|
| 65 | + - name: Build and push backend image |
| 66 | + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 |
| 67 | + with: |
| 68 | + context: ./app |
| 69 | + file: ./app/api/Dockerfile |
| 70 | + push: true |
| 71 | + platforms: linux/amd64,linux/arm64 |
| 72 | + tags: ${{ steps.backend_meta.outputs.tags }} |
| 73 | + |
| 74 | + # Build and push frontend |
| 75 | + - name: Extract frontend Docker metadata |
| 76 | + id: frontend_meta |
| 77 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 78 | + with: |
| 79 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend |
| 80 | + tags: | |
| 81 | + type=raw,value=${{ env.IMAGE_TAG }} |
| 82 | + type=raw,value=${{ github.sha }} |
| 83 | + type=raw,value=${{ env.RUN_TIMESTAMP }} |
| 84 | +
|
| 85 | + - name: Build and push frontend image |
| 86 | + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 |
| 87 | + with: |
| 88 | + context: ./app/next-client-app |
| 89 | + file: ./app/next-client-app/Dockerfile |
| 90 | + push: true |
| 91 | + platforms: linux/amd64,linux/arm64 |
| 92 | + tags: ${{ steps.frontend_meta.outputs.tags }} |
| 93 | + |
| 94 | + # Build and push Airflow webserver |
| 95 | + - name: Extract Airflow webserver Docker metadata |
| 96 | + id: airflow_webserver_meta |
| 97 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 98 | + with: |
| 99 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-webserver |
| 100 | + tags: | |
| 101 | + type=raw,value=${{ env.IMAGE_TAG }} |
| 102 | + type=raw,value=${{ github.sha }} |
| 103 | + type=raw,value=${{ env.RUN_TIMESTAMP }} |
| 104 | +
|
| 105 | + - name: Build and push Airflow webserver image |
| 106 | + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 |
| 107 | + with: |
| 108 | + context: ./app/airflow |
| 109 | + file: ./app/airflow/Dockerfile |
| 110 | + build-args: AIRFLOW_COMPONENT=webserver |
| 111 | + push: true |
| 112 | + platforms: linux/amd64,linux/arm64 |
| 113 | + tags: ${{ steps.airflow_webserver_meta.outputs.tags }} |
| 114 | + |
| 115 | + # Build and push Airflow scheduler |
| 116 | + - name: Extract Airflow scheduler Docker metadata |
| 117 | + id: airflow_scheduler_meta |
| 118 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 119 | + with: |
| 120 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-scheduler |
| 121 | + tags: | |
| 122 | + type=raw,value=${{ env.IMAGE_TAG }} |
| 123 | + type=raw,value=${{ github.sha }} |
| 124 | + type=raw,value=${{ env.RUN_TIMESTAMP }} |
| 125 | +
|
| 126 | + - name: Build and push Airflow scheduler image |
| 127 | + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0 |
| 128 | + with: |
| 129 | + context: ./app/airflow |
| 130 | + file: ./app/airflow/Dockerfile |
| 131 | + build-args: AIRFLOW_COMPONENT=scheduler |
| 132 | + push: true |
| 133 | + platforms: linux/amd64,linux/arm64 |
| 134 | + tags: ${{ steps.airflow_scheduler_meta.outputs.tags }} |
| 135 | + |
| 136 | + # Deploy to Dev Environment |
| 137 | + - name: Deploy Backend to Dev |
| 138 | + uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2 |
| 139 | + with: |
| 140 | + app-name: ${{ vars.AZURE_WEBAPP_NAME }} |
| 141 | + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} |
| 142 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend:${{ env.IMAGE_TAG }} |
| 143 | + |
| 144 | + - name: Deploy Frontend to Dev |
| 145 | + uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2 |
| 146 | + with: |
| 147 | + app-name: ${{ vars.AZURE_WEBAPP_NEXT_NAME }} |
| 148 | + publish-profile: ${{ secrets.AZURE_WEBAPP_NEXT_PUBLISH_PROFILE }} |
| 149 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend:${{ env.IMAGE_TAG }} |
| 150 | + |
| 151 | + - name: Deploy Airflow Webserver to Dev |
| 152 | + uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2 |
| 153 | + with: |
| 154 | + app-name: ${{ vars.AIRFLOW_WEBSERVER_NAME }} |
| 155 | + publish-profile: ${{ secrets.AIRFLOW_WEBSERVER_PUBLISH_PROFILE }} |
| 156 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-webserver:${{ env.IMAGE_TAG }} |
| 157 | + |
| 158 | + - name: Deploy Airflow Scheduler to Dev |
| 159 | + uses: azure/webapps-deploy@2fdd5c3ebb4e540834e86ecc1f6fdcd5539023ee # v3.0.2 |
| 160 | + with: |
| 161 | + app-name: ${{ vars.AIRFLOW_SCHEDULER_NAME }} |
| 162 | + publish-profile: ${{ secrets.AIRFLOW_SCHEDULER_PUBLISH_PROFILE }} |
| 163 | + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/airflow-scheduler:${{ env.IMAGE_TAG }} |
0 commit comments