Skip to content

Commit

Permalink
Setup GitHub action to build contiainer
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Hocutt <[email protected]>
  • Loading branch information
jaredhocutt committed Feb 12, 2024
1 parent 65faac9 commit ccfdd8e
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions .github/workflows/build_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ on:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
name: Build container image
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
Expand All @@ -16,24 +20,31 @@ jobs:
- name: Clone the repository
uses: actions/checkout@v4

- name: Use Buildah to create container image
id: build-image
uses: redhat-actions/buildah-build@v2
- name: Log in to the container registry
uses: docker/login-action@v3
with:
image: ocp4-disconnected
tags: latest ${{ github.sha }}
containerfiles: |
./Containerfile
- name: Push container image to registry
id: push-to-ghcr
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ghcr.io/${{ github.repository_owner }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Output image URL
run: echo "Image pushed to ${{ steps.push-to-ghcr.outputs.registry-paths }}"
- name: Extract container metadata
uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{ is_default_branch }}
type=sha,format=long
- name: Build and push container image
uses: docker/build-push-action@v5
id: build-and-push
with:
context: .
file: ./Containerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Output image metadata
run: echo "${{ steps.build-and-push.outputs.metadata }}"

0 comments on commit ccfdd8e

Please sign in to comment.