-
Notifications
You must be signed in to change notification settings - Fork 9
105 lines (90 loc) · 3.59 KB
/
deploy-release.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
# Inspired by: https://github.com/github/super-linter/blob/main/.github/workflows/deploy-release.yml
name: Deploy Release
on:
release:
types: [ published ]
workflow_dispatch:
inputs:
release_version:
description: 'version to release. Ex: v4.3.2'
required: true
default: 'v'
env:
REGISTRY: ghcr.io
permissions:
contents: read
jobs:
build:
name: Deploy Docker Image - Release
runs-on: ubuntu-latest
permissions:
deployments: write
packages: write
strategy:
fail-fast: false
matrix:
images:
- container-image-id-prefix: ""
deployment-environment-identifier: Release
image-id: standard
timeout-minutes: 60
steps:
- name: Repository checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get current date
run: |
echo "Appending the build date contents to GITHUB_ENV..."
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "${GITHUB_ENV}"
- name: Setup BuildX
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get current Release number
# shellcheck disable=SC2062
run: |
RELEASE_VERSION=$(echo ${{ github.event.release.name }} \
| grep -E -o "v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
if [ -z "${RELEASE_VERSION}" ]; then
echo "No release version found in environment, using input..."
echo "RELEASE_VERSION=${{ github.event.inputs.release_version }}" \
>> "${GITHUB_ENV}"
fi
echo "MAJOR_VERSION=${RELEASE_VERSION%%.*}" >> "${GITHUB_ENV}"
- name: Start deployment
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ matrix.images.deployment-environment-identifier }}
- name: Build Docker image - ${{ matrix.images.image-id }}
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
file: ./Dockerfile
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_REVISION=${{ github.sha }}
BUILD_VERSION=${{ github.sha }}
load: false
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository }}:${{ matrix.images.container-image-id-prefix }}latest
${{ env.REGISTRY }}/${{ github.repository }}:${{ matrix.images.container-image-id-prefix }}${{ env.MAJOR_VERSION }}
${{ env.REGISTRY }}/${{ github.repository }}:${{ matrix.images.container-image-id-prefix }}${{ env.RELEASE_VERSION }}
- name: Update deployment status
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ steps.deployment.outputs.env }}
env_url: https://github.com/${{ github.repository }}/releases/tag/${{ env.RELEASE_VERSION }}