Skip to content

Deploy to Dev

Deploy to Dev #14

Workflow file for this run

name: Deploy to Dev
on:
workflow_dispatch:
inputs:
image-tag:
type: string
description: "The tag of the docker images to deploy (default: pr-<number> of branch or latest)"
jobs:
check-if-image-exists:
runs-on: ubuntu-latest
environment: Dev
outputs:
image-tag: ${{ steps.retrieve-image-tag.outputs.image-tag }}
steps:
- name: Debug Environment Variables
run: |
echo "DEPLOYMENT_URL=${{ vars.DEPLOYMENT_URL }}"
echo "APOLLON_REDIS_DIAGRAM_TTL=${{ vars.APOLLON_REDIS_DIAGRAM_TTL }}"
- name: Retrieve Image Tag
id: retrieve-image-tag
run: |
if [ -n "${{ inputs.image-tag }}" ]; then
echo "image-tag=${{ inputs.image-tag }}" >> $GITHUB_OUTPUT
exit 0
fi
REF=$(echo "${{ github.event.ref }}" | sed -n 's#^refs/heads/##p')
# If ref = main
if [ "$REF" = "main" ]; then
echo "image-tag=latest" >> $GITHUB_OUTPUT
fi
PULLS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${REF}")
PR_NUMBER=$(echo "$PULLS" | jq -r '.[0].number')
if [ -z "$PR_NUMBER" ]; then
echo "No PR found for branch $REF."
exit 1
else
echo "PR #$PR_NUMBER found for branch $REF."
echo "image-tag=pr-$PR_NUMBER" >> $GITHUB_OUTPUT
fi
- name: Check if image exists
run: |
IMAGE_NAME=ls1intum/apollon_standalone
IMAGE_TAG="${{ steps.retrieve-image-tag.outputs.image-tag }}"
ENCODED_TOKEN=$(echo -n "${{ secrets.GITHUB_TOKEN }}" | base64)
TAG_EXISTS=$(curl -s -H "Authorization: Bearer ${ENCODED_TOKEN}" \
https://ghcr.io/v2/${IMAGE_NAME}/tags/list \
| jq -r --arg TAG "${IMAGE_TAG}" '.tags[] | select(. == $TAG)')
if [ -z "$TAG_EXISTS" ]; then
echo "Image ${IMAGE_NAME}:${IMAGE_TAG} does not exist."
exit 1
else
echo "Image ${IMAGE_NAME}:${IMAGE_TAG} exists."
fi
deploy:
needs: check-if-image-exists
# TODO: uses: ls1intum/.github/.github/workflows/deploy-docker-compose.yml@main
uses: ./.github/workflows/deploy-docker-compose-shared.yml
with:
environment: Dev
docker-compose-file: "./docker-compose.prod.yml"
image-tag: ${{ needs.check-if-image-exists.outputs.image-tag }}
env-vars: |
DEPLOYMENT_URL=${{ vars.DEPLOYMENT_URL }}
APOLLON_REDIS_DIAGRAM_TTL=${{ vars.APOLLON_REDIS_DIAGRAM_TTL }}
secrets: inherit