Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Docker and GHA CD via Dockerhub #70

Merged
merged 16 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
paths:
ocrd-resources
- run: make test
resource_class: large


workflows:
Expand All @@ -27,5 +28,5 @@ workflows:
- build-python:
matrix:
parameters:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']

47 changes: 47 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Image CD

on:
push:
branches: [ "master" ]
workflow_dispatch:
inputs:
docker-tagname:
description: Tag name of the Docker image
default: 'ocrd/sbb_binarization'

env:
DOCKER_TAGNAME: ${{ github.evenv.inputs.docker-tagname || 'ocrd/sbb_binarization' }}

jobs:

build:

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

steps:
- uses: actions/checkout@v4
- # 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_TAGNAME }}
- 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_TAGNAME }}
- name: Alias the Docker image for GHCR
run: docker tag ${{ env.DOCKER_TAGNAME }} ghcr.io/${{ github.repository }}
- 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/${{ github.repository }}
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

name: CLI Tests

on: [push, pull_request]
on:
push:
pull_request:
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ARG DOCKER_BASE_IMAGE
FROM $DOCKER_BASE_IMAGE
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/qurator-spk/sbb_binarization" \
org.label-schema.build-date=$BUILD_DATE

WORKDIR /build/sbb_binarization
COPY pyproject.toml .
COPY ocrd-tool.json .
bertsky marked this conversation as resolved.
Show resolved Hide resolved
COPY sbb_binarize ./sbb_binarize
COPY requirements.txt .
COPY README.md .
COPY Makefile .
RUN make install
RUN rm -rf /build/sbb_binarization

WORKDIR /data
VOLUME ["/data"]
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# BEGIN-EVAL makefile-parser --make-help Makefile

# should really be core-cuda-tf2, but not as long as we must restrict TF2 minor version
DOCKER_BASE_IMAGE = docker.io/ocrd/core-cuda:v2.69.0
DOCKER_TAG = ocrd/sbb_binarization

.PHONY: help install
help:
@echo ""
Expand All @@ -10,13 +14,18 @@ help:
@echo " test Run tests"
@echo " clean Remove copies/results in test/assets"
@echo ""
@echo " docker Build a Docker image $(DOCKER_TAG) from $(DOCKER_BASE_IMAGE)"
@echo ""
@echo " Variables"
@echo ""
@echo " PYTHON"
@echo " DOCKER_TAG Docker image tag of result for the docker target"

# END-EVAL

# Install with pip
install:
pip install -U setuptools pip
pip install .

# Downloads the pre-trained models from qurator-data.de
Expand All @@ -40,6 +49,15 @@ test: test/assets models
ocrd-sbb-binarize -m test/assets/kant_aufklaerung_1784-page-region/data/mets.xml -g phys_0001 -I OCR-D-GT-SEG-REGION -O BIN -P model default -P operation_level region
ocrd-sbb-binarize -m test/assets/kant_aufklaerung_1784-page-region/data/mets.xml -g phys_0001 -I OCR-D-GT-SEG-REGION -O BIN2 -P model default-2021-03-09 -P operation_level region

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


.PHONY: clean
clean:
-$(RM) -fr test/assets
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
> Document Image Binarization

[![pip release](https://img.shields.io/pypi/v/sbb-binarization.svg)](https://pypi.org/project/sbb-binarization/)
[![GHActions Tests](https://github.com/qurator-spk/sbb_binarization/actions/workflows/test.yml/badge.svg)](https://github.com/qurator-spk/sbb_binarization/actions/workflows/test.yml)
[![GHActions CI](https://github.com/qurator-spk/sbb_binarization/actions/workflows/test.yml/badge.svg)](https://github.com/qurator-spk/sbb_binarization/actions/workflows/test.yml)
[![GHActions CD](https://github.com/qurator-spk/sbb_binarization/actions/workflows/docker-image.yml/badge.svg)](https://github.com/qurator-spk/sbb_binarization/actions/workflows/docker-image.yml)

<img src="https://user-images.githubusercontent.com/952378/63592437-e433e400-c5b1-11e9-9c2d-889c6e93d748.jpg" width="180"><img src="https://user-images.githubusercontent.com/952378/63592435-e433e400-c5b1-11e9-88e4-3e441b61fa67.jpg" width="180"><img src="https://user-images.githubusercontent.com/952378/63592440-e4cc7a80-c5b1-11e9-8964-2cd1b22c87be.jpg" width="220"><img src="https://user-images.githubusercontent.com/952378/63592438-e4cc7a80-c5b1-11e9-86dc-a9e9f8555422.jpg" width="220">

Expand All @@ -13,16 +14,19 @@ Python `3.7-3.10` with Tensorflow `<=2.11.1` are currently supported. While newe

You can either install from PyPI via

```
pip install sbb-binarization
```
pip install sbb-binarization


or clone the repository, enter it and install (editable) with

```
git clone git@github.com:qurator-spk/sbb_binarization.git
cd sbb_binarization; pip install -e .
```
git clone git@github.com:qurator-spk/sbb_binarization.git
cd sbb_binarization; pip install -e .


Alternatively, download the prebuilt image from Dockerhub:

docker pull ocrd/sbb_binarization


### Models

Expand Down
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[build-system]
requires = ["setuptools>=61.0", "wheel", "setuptools-ocrd"]

[project]
name = "sbb_binarization"
authors = [
{name = "Vahid Rezanezhad"},
{name = "Staatsbibliothek zu Berlin - Preußischer Kulturbesitz"},
]
description = "Pixelwise binarization with selectional auto-encoders in Keras"
readme = "README.md"
license.file = "LICENSE"
requires-python = ">=3.8"

dynamic = ["dependencies", "version"]

classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Scientific/Engineering :: Image Processing",
]

[project.scripts]
sbb_binarize = "sbb_binarize.cli:main"
ocrd-sbb-binarize = "sbb_binarize.ocrd_cli:cli"

[project.urls]
Homepage = "https://github.com/qurator-spk/sbb_binarization"
Repository = "https://github.com/qurator-spk/sbb_binarization.git"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.setuptools.packages.find]
where = ["."]
include = ["sbb_binarize"]
namespaces = false

[tool.setuptools]
include-package-data = true

[tool.setuptools.package-data]
"*" = ["*.json"]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ numpy
setuptools >= 41
opencv-python-headless
ocrd >= 2.38.0
tensorflow <= 2.11.1
tensorflow <= 2.12.1
30 changes: 0 additions & 30 deletions setup.py

This file was deleted.

Loading