add github action workflow to build container #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Build Container | |
on: | |
push: | |
branches: [main] | |
tags: ["*"] | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
REPO: ${{ github.repository }} | |
jobs: | |
build-container: | |
name: Build Container | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Generate image name for docker | |
run: | | |
echo "IMAGE_NAME=${REPO,,}" >> ${GITHUB_ENV} | |
- name: Login to container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Extract metadata | |
id: metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=tag | |
type=raw,value=latest | |
type=sha | |
- name: Build/push container image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
labels: ${{ steps.metadata.outputs.labels }} | |
tags: ${{ steps.metadata.outputs.tags }} |