Skip to content

Commit

Permalink
Merge pull request #4 from surajssd/add-gh-action-to-build-image
Browse files Browse the repository at this point in the history
Add github action to build the docker image
  • Loading branch information
surajssd authored Oct 16, 2024
2 parents fcf5135 + 56a5336 commit 902f91f
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build & Push

on:
push:
branches:
- main

env:
REGISTRY: ghcr.io

jobs:
build_and_push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
# Download code.
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor}}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Tag
id: tag
run: |
# Generate a tag based on the commit hash and current timestamp.
# The format is <branch>-<commit hash>-<timestamp>.
echo "image_tag=$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)-$(date '+%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
- name: Extract metadata labels for image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/surajssd/kubecon-na24-workshop
tags: |
type=raw,value=${{ steps.tag.outputs.image_tag }}
type=raw,value=latest
- name: Base image
uses: docker/build-push-action@v6
with:
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 902f91f

Please sign in to comment.