-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (83 loc) · 2.84 KB
/
deploy.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Deploy Docker Image
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
branches:
- main
paths:
- '.github/workflows/deploy.yml'
- 'bin/**'
- 'server/**'
- 'Dockerfile'
- '.dockerignore'
jobs:
determine-deployment-config:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.determine-environment.outputs.environment }}
steps:
- name: Determine environment
id: determine-environment
env:
REF_TYPE: ${{ github.ref_type }}
run: |
if [ "${REF_TYPE}" == 'tag' ]; then
echo 'environment=production' >> "${GITHUB_OUTPUT}"
else
echo 'environment=development' >> "${GITHUB_OUTPUT}"
fi
run-deployment:
needs: determine-deployment-config
environment: ${{ needs.determine-deployment-config.outputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Get image parameters
id: image-parameters
env:
IS_RELEASE: ${{ github.ref_type == 'tag' }}
RELEASE_TAG: ${{ github.ref_name }}
SHA: ${{ github.sha }}
run: |
VERSION_TAG=''
LATEST_TAG=''
if [ "${IS_RELEASE}" == 'true' ]; then
VERSION_TAG="${RELEASE_TAG}"
LATEST_TAG='stable'
else
VERSION_TAG="rev-$(echo "${SHA}" | cut -c1-7)"
LATEST_TAG='latest'
fi
echo "latest-tag=${LATEST_TAG}" >> "${GITHUB_OUTPUT}"
echo "version-tag=${VERSION_TAG}" >> "${GITHUB_OUTPUT}"
echo "version-arg=${VERSION_TAG}" >> "${GITHUB_OUTPUT}"
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: docker/build-push-action@v5
with:
pull: true
push: true
platforms: linux/amd64
build-args: |
VERSION=${{ steps.image-parameters.outputs.version-arg }}
tags: |
${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE }}:${{ steps.image-parameters.outputs.version-tag }}
${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE }}:${{ steps.image-parameters.outputs.latest-tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
- uses: fjogeleit/http-request-action@v1
with:
method: POST
url: "${{ secrets.DEPLOYER_URL }}/api/v1/deploy"
bearerToken: ${{ secrets.DEPLOYER_TOKEN }}
timeout: 0
data: |
{
"image": "${{ vars.DOCKER_IMAGE }}",
"tags": [ "${{ steps.image-parameters.outputs.version-tag }}", "${{ steps.image-parameters.outputs.latest-tag }}" ]
}