Docker Image CI #29
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: Docker Image CI | |
on: | |
workflow_dispatch: | |
# push: | |
# branches: [ main ] | |
# pull_request: | |
# branches: [ main ] | |
env: | |
# IMAGE_NAME: ${{ github.repository }} | |
IMAGE_NAME: ${{ github.repository_owner }}/calibre-web | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# Checkout the repository | |
# https://github.com/actions/checkout | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Login to Docker Hub registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: docker.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Get the image info | |
- name: Get the image version | |
id: image | |
run: | | |
echo "version=$(grep 'ARG IMAGE_VERSION=' Dockerfile|cut -d'=' -f2|cut -d' ' -f1)" >> $GITHUB_OUTPUT | |
# Prepare Docker tags | |
# https://github.com/docker/metadata-action | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
docker.io/${{ env.IMAGE_NAME }} | |
ghcr.io/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=latest | |
type=raw,value=${{ steps.image.outputs.version }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} |