Skip to content

Commit d2b821f

Browse files
committed
chore: update workflows
1 parent ed5dfa4 commit d2b821f

4 files changed

Lines changed: 74 additions & 7 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Push Workshop Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Environment variables available to all jobs and steps in the workflow
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: yeahx/kubeapi-inspector:workshop-apiserver
15+
16+
jobs:
17+
build-and-push-image:
18+
runs-on: ubuntu-latest # Use the latest Ubuntu runner
19+
20+
# Grant permissions for actions to push to ghcr.io
21+
permissions:
22+
contents: read # Needed to check out the repository
23+
packages: write # Needed to push Docker images to ghcr.io
24+
25+
steps:
26+
- name: Get version
27+
id: get_version
28+
run: |
29+
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
30+
31+
- name: Checkout repository
32+
uses: actions/checkout@v3 # Checks out your repository code
33+
34+
- name: Log in to the Container registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }} # Use the GitHub Actions token user
39+
password: ${{ secrets.REGISTRY }} # Use the automatically generated token
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3 # Sets up the buildx builder instance
43+
44+
# - name: Extract metadata (tags, labels) for Docker
45+
# id: meta # Assign an ID to refer to the outputs of this step
46+
# uses: docker/metadata-action@v5
47+
# with:
48+
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # Full image name
49+
# # Generate tags based on the event
50+
# tags: |
51+
# type=ref,event=pr # Example: Add PR number tag (e.g., pr-123)
52+
# type=sha,format=short # Add short git commit SHA as tag (e.g., a1b2c3d)
53+
# type=raw,value=latest,enable={{is_default_branch}}
54+
55+
- name: Build and push Docker image
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: ./workshop # IMPORTANT: Set build context to the workshop directory
59+
file: ./workshop/Dockerfile # IMPORTANT: Specify the Dockerfile path relative to repo root
60+
push: true # Push the image after building
61+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ steps.get_version.outputs.VERSION }} # Use tags generated by the metadata step
62+
# labels: ${{ steps.meta.outputs.labels }} # Add labels generated by the metadata step
63+
cache-from: type=gha # Enable build cache from GitHub Actions cache
64+
cache-to: type=gha,mode=max # Write build cache to GitHub Actions cache (mode=max for potentially better performance)

.github/workflows/release_build.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ jobs:
1212

1313
steps:
1414
- name: Check out code into the Go module directory
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616
with:
1717
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/
1818

19-
- name: Set up Go 1.22
20-
uses: actions/setup-go@v2
19+
- name: Set up Go 1.23
20+
uses: actions/setup-go@v3
2121
with:
22-
go-version: 1.22
22+
go-version: 1.23
2323
id: go
2424

2525
- name: Run GoReleaser
26-
uses: goreleaser/goreleaser-action@master
26+
uses: goreleaser/goreleaser-action@v3
2727
with:
2828
version: latest
29-
args: release --clean
29+
args: release
3030
env:
3131
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: 2
22

33
project_name: KubeAPI-Inspector
44

5+
before:
6+
hooks:
7+
- go mod tidy
58
builds:
69
- env:
710
- CGO_ENABLED=0

workshop/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 as builder
2+
FROM golang:1.23 as builder
33

44
WORKDIR /workspace
55
ARG TARGETOS=linux

0 commit comments

Comments
 (0)