Skip to content

Commit c026a09

Browse files
committed
refactored GitHub workflow Release GHCR Image
1 parent 527604a commit c026a09

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed
Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1-
name: GHCR Image
1+
name: Release GHCR Image
2+
23
on:
34
push:
45
tags:
56
- v*
7+
68
jobs:
79
build_ghcr_image:
810
runs-on: ubuntu-latest
911
permissions:
1012
contents: read
1113
packages: write
14+
1215
steps:
1316
- uses: actions/checkout@v5
14-
- name: Build and push Docker image
15-
env:
16-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
with:
18+
fetch-depth: 0 # Récupère tous les tags
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Login to GHCR
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Extract version
31+
id: version
1732
run: |
18-
export GIT_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
19-
export IMAGE_TAG=$(echo $GIT_TAG | sed 's/v//')
20-
docker build . --file Dockerfile --tag ghcr.io/realopslabs/kubeledger:$IMAGE_TAG
21-
docker tag ghcr.io/realopslabs/kubeledger:$IMAGE_TAG ghcr.io/realopslabs/kubeledger:latest
22-
echo "$GH_TOKEN" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
23-
docker push ghcr.io/realopslabs/kubeledger:$IMAGE_TAG
24-
docker push ghcr.io/realopslabs/kubeledger:latest
33+
GIT_TAG=${GITHUB_REF#refs/tags/}
34+
IMAGE_TAG=${GIT_TAG#v}
35+
echo "tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
36+
echo "git_tag=${GIT_TAG}" >> $GITHUB_OUTPUT
37+
38+
- name: Build and push
39+
uses: docker/build-push-action@v5
40+
with:
41+
context: .
42+
push: true
43+
tags: |
44+
ghcr.io/realopslabs/kubeledger:${{ steps.version.outputs.tag }}
45+
ghcr.io/realopslabs/kubeledger:latest
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)