Skip to content

Commit

Permalink
add Dockerfile and GH Action to publish at Dockerhub and GHCR
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky committed Mar 25, 2023
1 parent 04bf4c6 commit ed1237e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Docker Image CI

on:
push:
branches: [ "master" ]
workflow_dispatch: # run manually

jobs:

build:

runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: Replace underscores in tag name
run: NAME="$GITHUB.REPOSITORY"; echo DOCKER_TAG=${NAME//_//} >> $GITHUB_ENV
- uses: actions/checkout@v3
- # Activate cache export feature to reduce build time of image
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build the Docker image
run: make docker DOCKER_TAG=${{ env.DOCKER_TAG }}
- name: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push image to Dockerhub
run: docker push ${{ env.DOCKER_TAG }}
- name: Alias the Docker image for GHCR
run: docker tag ${{ env.DOCKER_TAG }} ghcr.io/${{ env.DOCKER_TAG }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to Github Container Registry
run: docker push ghcr.io/${{ env.DOCKER_TAG }}
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ocrd/core-cuda
ARG VCS_REF
ARG BUILD_DATE
LABEL \
maintainer="https://ocr-d.de/kontakt" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/bertsky/detectron2" \
org.label-schema.build-date=$BUILD_DATE

ENV DEBIAN_FRONTEND noninteractive
ENV PYTHONIOENCODING utf8

# avoid HOME/.local/share (hard to predict USER here)
# so let XDG_DATA_HOME coincide with fixed system location
# (can still be overridden by derived stages or at runtime)
# should be combined with a bind-mount at runtime
ENV XDG_DATA_HOME /usr/local/share

WORKDIR /build-ocrd
COPY setup.py .
COPY ocrd_detectron2/ocrd-tool.json .
COPY README.md .
COPY requirements.txt .
COPY requirements-test.txt .
COPY ocrd_detectron2 ./ocrd_detectron2
COPY Makefile .
RUN apt-get install -y --no-install-recommends g++ && \
make deps && \
make install && \
rm -rf /build-ocrd && \
apt-get -y remove --auto-remove g++

WORKDIR /data
VOLUME /data

# override Nvidia entrypoint
ENTRYPOINT []
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ PIP = pip3
PYTHONIOENCODING=utf8
SHELL = /bin/bash

# Docker container tag
DOCKER_TAG = 'bertsky/detectron2'

help:
@echo
@echo " Targets"
Expand All @@ -12,10 +15,12 @@ help:
@echo " deps-test Install Python dependencies for tests via pip and models via resmgr"
@echo " test Run regression tests"
@echo " clean Remove symlinks in test/assets"
@echo " docker Build Docker image"
@echo
@echo " Variables"
@echo " PYTHON"
@echo " CUDA_VERSION override detection of CUDA runtime version (e.g. '11.3' or 'CPU')"
@echo " DOCKER_TAG Docker image tag of result for the docker target"

# Install Python deps via pip
# There is no prebuilt for detectron2 on PyPI, and the wheels depend on CUDA and Torch version.
Expand Down Expand Up @@ -81,6 +86,13 @@ test/assets: repo/assets
clean:
-$(RM) -r test/assets

# Build docker image
docker:
docker build \
--build-arg VCS_REF=$$(git rev-parse --short HEAD) \
--build-arg BUILD_DATE=$$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t $(DOCKER_TAG) .

#MODELDIR := $(or $(XDG_DATA_HOME),$(HOME)/.local/share)/ocrd-resources/ocrd-detectron2-segment

TESTMODEL := TableBank_X152_Psarpei
Expand Down Expand Up @@ -124,4 +136,4 @@ count-regions := python -c "import sys; from ocrd_models.ocrd_page import parse;
# make cannot delete directories, so keep them
.PRECIOUS .SECONDARY: %/OCR-D-BIN %/OCR-D-SEG-$(MODEL)

.PHONY: help deps install deps-test models-test test clean
.PHONY: help deps install deps-test models-test test clean docker

0 comments on commit ed1237e

Please sign in to comment.