Build and Push Docker Image to GHCR #78
This file contains hidden or 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 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 |