|
| 1 | +name: 'Build and deploy application containers' |
| 2 | +on: |
| 3 | + push: |
| 4 | +jobs: |
| 5 | + build-tag-push-deploy: |
| 6 | + runs-on: ubuntu-latest |
| 7 | + # CI will run for these branches |
| 8 | + if: > |
| 9 | + github.ref == 'refs/heads/main' || |
| 10 | + github.ref == 'refs/heads/develop' || |
| 11 | + github.ref == 'refs/heads/set-up-deployment' |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + # Specify the docker-compose services to build images from |
| 15 | + service: [sdwebapp, sdnginx] |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v3 |
| 19 | + - name: Login to GitHub container registry |
| 20 | + uses: docker/login-action@v1 |
| 21 | + with: |
| 22 | + registry: ghcr.io |
| 23 | + username: cmu-delphi-deploy-machine |
| 24 | + password: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }} |
| 25 | + - name: Create container image tags |
| 26 | + id: image-tag |
| 27 | + run: | |
| 28 | + baseRef="${GITHUB_REF#*/}" |
| 29 | + baseRef="${baseRef#*/}" |
| 30 | + case "${baseRef}" in |
| 31 | + main) |
| 32 | + image_tag="latest" |
| 33 | + ;; |
| 34 | + *) |
| 35 | + image_tag="${baseRef//\//_}" # replace `/` with `_` in branch name |
| 36 | + ;; |
| 37 | + esac |
| 38 | + echo "IMAGE_TAG=${image_tag}" >> $GITHUB_OUTPUT |
| 39 | + - name: Copy env file |
| 40 | + run: | |
| 41 | + cp ./.ci.env ./.env |
| 42 | + - name: Set up docker-compose |
| 43 | + |
| 44 | + - name: docker-compose build --push |
| 45 | + run: | |
| 46 | + docker-compose build --push ${{ matrix.service }} |
| 47 | + env: |
| 48 | + TAG: ":${{ steps.image-tag.outputs.IMAGE_TAG }}" |
| 49 | + REGISTRY: "ghcr.io/${{ github.repository_owner }}/" |
| 50 | + - name: docker-compose down |
| 51 | + run: | |
| 52 | + docker-compose down |
| 53 | + - name: Trigger smee.io webhook to pull new container images |
| 54 | + run: | |
| 55 | + curl -H "Authorization: Bearer ${{ secrets.DELPHI_DEPLOY_WEBHOOK_TOKEN }}" \ |
| 56 | + -X POST ${{ secrets.DELPHI_DEPLOY_WEBHOOK_URL }} \ |
| 57 | + -H "Content-Type: application/x-www-form-urlencoded" \ |
| 58 | + -d "repository=ghcr.io/${{ github.repository }}-${{ matrix.service }}&tag=${{ steps.image-tag.outputs.IMAGE_TAG }}" |
0 commit comments