-
-
Notifications
You must be signed in to change notification settings - Fork 1
106 lines (90 loc) · 3.18 KB
/
docker-package.yml
File metadata and controls
106 lines (90 loc) · 3.18 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
name: Docker Package
on:
push:
branches:
- master
- main
tags:
- "v*.*.*"
workflow_dispatch:
permissions:
contents: read
packages: write
concurrency:
group: docker-package-${{ github.ref }}
cancel-in-progress: false
jobs:
publish-ghcr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Resolve image and package version
id: vars
shell: bash
run: |
set -euo pipefail
OWNER="$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')"
IMAGE="$(basename "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
VERSION="$(node -p "require('./package.json').version")"
VERSION="$(echo "$VERSION" | xargs)"
if [ -z "$VERSION" ]; then
echo "::error::package.json version is empty."
exit 1
fi
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Invalid package.json version: '$VERSION'"
exit 1
fi
echo "owner=$OWNER" >> "$GITHUB_OUTPUT"
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
echo "version_tag=v${VERSION}" >> "$GITHUB_OUTPUT"
- 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: ${{ github.token }}
- name: Generate image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ steps.vars.outputs.owner }}/${{ steps.vars.outputs.image }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ steps.vars.outputs.version_tag }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
- name: Build and push image package
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
RUN_TESTS=false
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Show package location
env:
IMAGE_OWNER: ${{ steps.vars.outputs.owner }}
IMAGE_NAME: ${{ steps.vars.outputs.image }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
shell: bash
run: |
set -euo pipefail
echo "Package: ghcr.io/${IMAGE_OWNER}/${IMAGE_NAME}"
echo "Org packages page: https://github.com/orgs/${REPOSITORY_OWNER}/packages?repo_name=${REPOSITORY_NAME}"