-
Notifications
You must be signed in to change notification settings - Fork 2
67 lines (58 loc) · 2.35 KB
/
deploy-dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 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.retrieve-image-tag.outputs.image-tag }}
env-vars: |
DEPLOYMENT_URL=${{ vars.DEPLOYMENT_URL }}
APOLLON_REDIS_DIAGRAM_TTL=${{ vars.APOLLON_REDIS_DIAGRAM_TTL }}
secrets: inherit