GHA Docker: build docker.io first, then tag ghcr.io #160
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: | |
push: | |
branches: [ "master" ] | |
workflow_dispatch: # run manually | |
env: | |
GHCRIO_DOCKER_TAG: ghcr.io/ocr-d/core | |
DOCKERIO_DOCKER_TAG: docker.io/ocrd/core | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# we need tags for docker version tagging | |
fetch-tags: true | |
fetch-depth: 0 | |
- # Activate cache export feature to reduce build time of images | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build the Docker image | |
run: make docker | |
- name: Build the Docker image with GPU support | |
run: make docker-cuda | |
- name: Alias Docker images | |
# default tag uses docker.io, so tag post-hoc | |
run: | | |
docker tag ocrd/core ${{ env.GHCRIO_DOCKER_TAG }} | |
docker tag ocrd/core-cuda ${{ env.GHCRIO_DOCKER_TAG }}-cuda | |
- name: Smoke Test that ocrd --help works | |
run: | | |
docker run --rm ${{ env.GHCRIO_DOCKER_TAG }} ocrd --version | |
docker run --rm ${{ env.GHCRIO_DOCKER_TAG }}-cuda ocrd --version | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERIO_USERNAME }} | |
password: ${{ secrets.DOCKERIO_PASSWORD }} | |
- name: Push images to Github Container Registry | |
run: | | |
docker push ${{ env.GHCRIO_DOCKER_TAG }}:latest | |
docker push ${{ env.GHCRIO_DOCKER_TAG }}-cuda:latest | |
- name: Push images to Docker Hub | |
run: | | |
docker tag ${{ env.GHCRIO_DOCKER_TAG }} ${{ env.DOCKERIO_DOCKER_TAG }} | |
docker tag ${{ env.GHCRIO_DOCKER_TAG }}-cuda ${{ env.DOCKERIO_DOCKER_TAG }}-cuda | |
docker push ${{ env.DOCKERIO_DOCKER_TAG }}:latest | |
docker push ${{ env.DOCKERIO_DOCKER_TAG }}-cuda:latest | |
docker push ${{ env.DOCKERIO_DOCKER_TAG }}:latest | |
docker push ${{ env.DOCKERIO_DOCKER_TAG }}-cuda:latest | |
docker tag ${{ env.DOCKERIO_DOCKER_TAG }} ${{ env.DOCKERIO_DOCKER_TAG }}:$(git describe --tags --abbrev=0) | |
docker tag ${{ env.DOCKERIO_DOCKER_TAG }}-cuda ${{ env.DOCKERIO_DOCKER_TAG }}-cuda:$(git describe --tags --abbrev=0) | |
docker push ${{ env.DOCKERIO_DOCKER_TAG }}:$(git describe --tags --abbrev=0) | |
docker push ${{ env.DOCKERIO_DOCKER_TAG }}-cuda:$(git describe --tags --abbrev=0) | |