-
Notifications
You must be signed in to change notification settings - Fork 14
executable file
·150 lines (127 loc) · 4.37 KB
/
Copy pathdocker.yml
File metadata and controls
executable file
·150 lines (127 loc) · 4.37 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright 2025 RustFS Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Publish Docker Image
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Release version to publish, e.g. 1.0.0 or v1.0.0"
required: true
default: "1.0.0"
type: string
push_latest:
description: "Also push the latest tag"
required: false
default: true
type: boolean
permissions:
contents: read
packages: write
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: false
env:
DOCKERHUB_IMAGE: rustfs/operator
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/operator
DOCKER_PLATFORMS: linux/amd64,linux/arm64
jobs:
push-operator-images:
name: Build and Push Operator Image
runs-on: operator-sm-standard-2
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Normalize version and tags
id: version
shell: bash
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
RAW="${{ github.event.inputs.version }}"
CREATE_LATEST="${{ github.event.inputs.push_latest }}"
IS_PRERELEASE=false
else
RAW="${{ github.event.release.tag_name }}"
IS_PRERELEASE="${{ github.event.release.prerelease }}"
if [ "$IS_PRERELEASE" = "true" ]; then
CREATE_LATEST=false
else
CREATE_LATEST=true
fi
fi
RAW_TAG="${RAW#refs/tags/}"
VERSION="${RAW_TAG#v}"
if [ -z "$VERSION" ]; then
echo "Version is empty"
exit 1
fi
# For manually triggered builds, infer prerelease from version name.
case "$VERSION" in
*alpha*|*beta*|*rc*)
IS_PRERELEASE=true
CREATE_LATEST=false
;;
esac
{
echo "version=$VERSION"
echo "is_prerelease=$IS_PRERELEASE"
echo "create_latest=$CREATE_LATEST"
} >> "$GITHUB_OUTPUT"
{
echo "tags<<EOF"
echo "${DOCKERHUB_IMAGE}:${VERSION}"
echo "${GHCR_IMAGE}:${VERSION}"
if [ "$CREATE_LATEST" = "true" ]; then
echo "${DOCKERHUB_IMAGE}:latest"
echo "${GHCR_IMAGE}:latest"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "Docker version: $VERSION"
echo "Prerelease: $IS_PRERELEASE"
echo "Create latest: $CREATE_LATEST"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: ${{ steps.version.outputs.tags }}
labels: |
org.opencontainers.image.title=RustFS Operator
org.opencontainers.image.description=RustFS Kubernetes Operator
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ steps.version.outputs.version }}