Skip to content

Commit 50340b0

Browse files
committed
ci: move image to gcr
Signed-off-by: Sn0rt <wangguohao.2009@gmail.com>
1 parent b932c77 commit 50340b0

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

.github/workflows/release.yaml

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,75 @@ on:
44
push:
55
tags:
66
- 'v*'
7-
branches:
8-
- release/*
9-
10-
env:
11-
DOCKER_REPO: wangguohao
12-
IMAGE_NAME: secret2es
13-
GO_VERSION: '1.22.5'
147

158
jobs:
16-
build-and-push:
9+
docker:
1710
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
security-events: write
1815
steps:
19-
- name: Check out code
20-
uses: actions/checkout@v2
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set build variables
22+
id: vars
23+
run: |
24+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
25+
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
26+
echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
2127
2228
- name: Set up QEMU
23-
uses: docker/setup-qemu-action@v1
29+
uses: docker/setup-qemu-action@v2
2430

2531
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v1
27-
28-
- name: Set build time
29-
run: echo "BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
32+
uses: docker/setup-buildx-action@v2
3033

31-
- name: Login to DockerHub
32-
uses: docker/login-action@v1
34+
- name: Login to GitHub Container Registry
35+
uses: docker/login-action@v2
3336
with:
34-
username: ${{ secrets.DOCKERHUB_USERNAME }}
35-
password: ${{ secrets.DOCKERHUB_TOKEN }}
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
3640

37-
- name: Extract metadata for Docker
41+
- name: Extract metadata (tags, labels) for Docker
3842
id: meta
39-
uses: docker/metadata-action@v3
43+
uses: docker/metadata-action@v4
4044
with:
41-
images: ${{ env.DOCKER_REPO }}/${{ env.IMAGE_NAME }}
45+
images: ghcr.io/${{ github.repository }}
4246
tags: |
43-
type=semver,pattern={{version}}
44-
type=semver,pattern={{major}}.{{minor}}
45-
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
47+
type=semver,pattern=v{{version}}
48+
type=semver,pattern=v{{major}}.{{minor}}
49+
type=raw,value=latest
4650
4751
- name: Build and push Docker image
48-
uses: docker/build-push-action@v2
52+
id: docker_build
53+
uses: docker/build-push-action@v4
4954
with:
5055
context: .
51-
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
56+
push: true
57+
platforms: linux/amd64
5258
tags: ${{ steps.meta.outputs.tags }}
5359
labels: ${{ steps.meta.outputs.labels }}
5460
build-args: |
55-
VERSION=${{ steps.meta.outputs.version }}
56-
BUILD_TIME=${{ env.BUILD_TIME }}
61+
VERSION=${{ steps.vars.outputs.VERSION }}
62+
BUILD_DATE=${{ steps.vars.outputs.BUILD_DATE }}
63+
GIT_COMMIT=${{ steps.vars.outputs.GIT_COMMIT }}
64+
65+
- name: Image digest
66+
run: echo ${{ steps.docker_build.outputs.digest }}
5767

5868
release-binaries:
5969
permissions:
6070
contents: write
6171
runs-on: ubuntu-latest
62-
needs: build-and-push
72+
needs: docker
6373
strategy:
6474
matrix:
6575
include:
66-
- os: darwin
67-
arch: arm64
6876
- os: linux
6977
arch: arm64
7078
- os: linux
@@ -73,30 +81,29 @@ jobs:
7381
- name: Check out code
7482
uses: actions/checkout@v2
7583
with:
76-
fetch-depth: 0 # Fetch all history for all tags and branches
84+
fetch-depth: 0
7785

7886
- name: Set up Go
7987
uses: actions/setup-go@v2
8088
with:
81-
go-version: ${{ env.GO_VERSION }}
89+
go-version: '1.22.5'
8290

8391
- name: Get BINARY_NAME from Makefile
84-
run: echo "BINARY_NAME=$(make -s print-binary-name)" >> $GITHUB_ENV
92+
run: echo "BINARY_NAME=secret2es" >> $GITHUB_ENV
8593

8694
- name: Build binary
8795
env:
8896
GOOS: ${{ matrix.os }}
8997
GOARCH: ${{ matrix.arch }}
9098
run: |
9199
make build
92-
mv ${{ env.BINARY_NAME }} ${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
100+
mv secret2es secret2es-${{ matrix.os }}-${{ matrix.arch }}
93101
94102
- name: Upload binary to release
95103
uses: svenstaro/upload-release-action@v2
96-
if: startsWith(github.ref, 'refs/tags/v')
97104
with:
98105
repo_token: ${{ secrets.GITHUB_TOKEN }}
99-
file: ${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
100-
asset_name: ${{ env.BINARY_NAME }}-${{ matrix.os }}-${{ matrix.arch }}
106+
file: secret2es-${{ matrix.os }}-${{ matrix.arch }}
107+
asset_name: secret2es-${{ matrix.os }}-${{ matrix.arch }}
101108
tag: ${{ github.ref }}
102-
overwrite: true
109+
overwrite: true

0 commit comments

Comments
 (0)