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)
0 commit comments