forked from liveblocks/liveblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (116 loc) · 4.24 KB
/
docker-image.yml
File metadata and controls
127 lines (116 loc) · 4.24 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Reusable workflow: build and publish a Docker image to GHCR.
name: "[reusable] Build Docker image"
on:
workflow_call:
inputs:
image:
required: true
type: string
description: "Image name (e.g. liveblocks/cli)"
dockerfile:
required: false
type: string
default: "Dockerfile"
description: "Dockerfile path relative to context"
context:
required: false
type: string
default: "tools/liveblocks-cli"
build-args:
required: false
type: string
is_release:
required: true
type: string
description:
"'true' for release builds (tag push or workflow_dispatch with
version), 'false' otherwise. Controls whether latest tag and version
tags are applied."
release_version:
required: true
type: string
description:
"Explicit semver for tagging (e.g. 1.0.6, without v prefix). Non-empty
only for workflow_dispatch triggers where there is no git tag for
type=semver to derive from. Pass empty string for tag-push and
non-release builds."
outputs:
tags:
value: ${{ jobs.build.outputs.tags }}
digest:
value: ${{ jobs.build.outputs.digest }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.meta.outputs.tags }}
digest: ${{ steps.build.outputs.digest }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute major.minor version
id: version-parts
if: inputs.release_version != ''
run: |
VERSION="${{ inputs.release_version }}"
MAJOR_MINOR="${VERSION%.*}"
echo "major_minor=${MAJOR_MINOR}" >> "$GITHUB_OUTPUT"
# Tags applied per trigger type:
#
# Tag push (e.g. v1.0.6):
# - 1.0.6, 1.0, latest (from type=semver + type=raw)
# - main (from type=ref,event=branch)
# - sha-abc1234 (from type=sha)
#
# workflow_dispatch with release_version=1.0.6:
# - 1.0.6, 1.0, latest (from type=raw with explicit version)
# - main (from type=ref,event=branch)
# - sha-abc1234 (from type=sha)
#
# Branch push (non-release):
# - main (from type=ref,event=branch)
# - sha-abc1234 (from type=sha)
#
# Pull request:
# - pr-123 (from type=ref,event=pr)
# - sha-abc1234 (from type=sha)
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ inputs.image }}
tags: |
type=semver,pattern={{version}},enable=${{ inputs.is_release == 'true' && inputs.release_version == '' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ inputs.is_release == 'true' && inputs.release_version == '' }}
type=raw,value=${{ inputs.release_version }},enable=${{ inputs.release_version != '' }}
type=raw,value=${{ steps.version-parts.outputs.major_minor }},enable=${{ inputs.release_version != '' }}
type=raw,value=latest,enable=${{ inputs.is_release == 'true' }}
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Build and push
id: build
uses: docker/build-push-action@v6
with:
context: ${{ inputs.context }}
file: ${{ inputs.context }}/${{ inputs.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ inputs.build-args }}
cache-from: type=gha,scope=${{ inputs.image }}
cache-to: type=gha,mode=max,scope=${{ inputs.image }}