-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (88 loc) · 2.61 KB
/
build.yaml
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
---
name: Build
on: # yamllint disable-line rule:truthy
pull_request:
push:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
publish-image:
name: Publish image
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Docker buildx
uses: docker/setup-buildx-action@v3
- name: Build list of Docker tags to use
id: tag-types
run: |
if [[ ${{ contains(github.ref, 'tag') }} == true ]]; then
TAGS="
type=semver,pattern={{major}},priority=920
type=semver,pattern={{major}}.{{minor}},priority=910
type=semver,pattern={{version}},priority=900
type=ref,event=branch
type=sha,format=long"
else
TAGS="
type=ref,event=branch
type=sha,format=long"
fi
# https://trstringer.com/github-actions-multiline-strings
{
echo "TAGS<<EOF"
echo "$TAGS"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Set Docker labels and tags
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=${{ github.ref == 'refs/heads/main' }}
tags: ${{ env.TAGS }}
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest git tag
id: get-tag
uses: olegtarasov/get-tag@2.1.3
- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: |
VERSION=${{ steps.get-tag.outputs.tag }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
deploy:
needs: [publish-image]
name: Deploy to production
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Deploy to production
run: |
if [[ ${{ github.ref }} == 'refs/heads/main' || ${{ github.ref }} == 'refs/heads/beta' ]]; then
curl -X GET ${{ secrets.DEPLOY_URL }}
fi