Skip to content

Deploy to Dev

Deploy to Dev #7

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
steps:
- name: Retrieve PR number
id: pr-number
run: |
REF=$(echo "${{ github.event.ref.ref }}" | sed -n 's#^refs/heads/##p')
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')
echo "::set-output name=pr-number::$PR_NUMBER"
- name: Check if image exists
run: |
IMAGE_NAME=ls1intum/apollon_standalone
IMAGE_TAG=${{ inputs.image-tag }} || "pr-${{ steps.pr-number.outputs.pr-number }}"
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."
echo "::set-output name=image-tag::$IMAGE_TAG"}"
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