Skip to content

Build and Push Docker Image to GHCR #78

Build and Push Docker Image to GHCR

Build and Push Docker Image to GHCR #78

name: Build and Push Docker Image to GHCR
on:
push:
branches: [ main, dev ] # Trigger the workflow on push to the main branch
pull_request:
branches: [ main, dev ] # Trigger the workflow on pull requests targeting the main branch
workflow_dispatch: # Allow manual trigger of the workflow
env:
REGISTRY: ghcr.io
IMAGE_NAME: on_demand
jobs:
build_and_push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Load env variables from secrets on github
run: |
echo "SERVER_NAME=${{ secrets.SERVER_NAME }}" >> $GITHUB_ENV
echo "OIDC_CLIENT_ID=${{ secrets.OIDC_CLIENT_ID }}" >> $GITHUB_ENV
echo "OIDC_CLIENT_SECRET=${{ secrets.OIDC_CLIENT_SECRET }}" >> $GITHUB_ENV
echo "OIDC_LOGOUT_REDIRECT=${{ secrets.OIDC_LOGOUT_REDIRECT }}" >> $GITHUB_ENV
- name: Set lowercase repo name
run: echo "REPO_NAME_LOWER=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build the Docker image using docker-compose
run: |
docker compose -f docker-compose.yaml build
- name: Push the Docker image to GitHub Container Registry
run: |
docker compose -f docker-compose.yaml push on_demand
- name: Verify the image
run: |
docker pull ${{ env.REGISTRY }}/${{ env.REPO_NAME_LOWER }}/${{ env.IMAGE_NAME }}:latest