Skip to content

Commit

Permalink
Attempt to setup alpine-arm64 image
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed May 21, 2024
1 parent d5ff7f7 commit 0f3e880
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 20 deletions.
18 changes: 1 addition & 17 deletions .docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0

FROM alpine:3.19 as base
FROM alpine:3.19.1 as base

ENV LANG=C.UTF-8
ENV TZ=UTC
Expand All @@ -18,22 +18,6 @@ RUN apk add --no-cache \
python3-dev \
py3-pip

# On arm64, we need to build cffi from source.
ARG TARGETPLATFORM

RUN if [ "${TARGETPLATFORM}" == "linux/arm64" ]; then \
apk add --no-cache \
build-base \
autoconf \
automake \
libtool \
zlib-dev \
libffi-dev \
cairo-dev \
pkgconfig \
; \
fi

COPY . /app

WORKDIR /app
Expand Down
80 changes: 80 additions & 0 deletions .docker/Dockerfile.alpine-arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0

FROM arm64v8/alpine:3.19.1 as base

ENV LANG=C.UTF-8
ENV TZ=UTC

RUN apk add --no-cache \
python3 \
zlib

FROM base as builder

RUN apk add --no-cache \
ca-certificates \
git \
python3-dev \
py3-pip

# On arm64, we need to build cffi from source.
RUN apk add --no-cache \
build-base \
autoconf \
automake \
libtool \
zlib-dev \
libffi-dev \
cairo-dev \
pkgconfig \
; \
fi

COPY . /app

WORKDIR /app

RUN python3 -m venv .venv

RUN source .venv/bin/activate \
&& python3 -m pip install --no-cache-dir --upgrade pip \
&& python3 -m pip install --no-cache-dir wheel \
&& python3 -m pip install --no-cache-dir .[test,webservice,watcher]

FROM base

RUN apk add --no-cache \
ghostscript \
jbig2dec \
jbig2enc \
pngquant \
tesseract-ocr \
tesseract-ocr-data-chi_sim \
tesseract-ocr-data-deu \
tesseract-ocr-data-eng \
tesseract-ocr-data-fra \
tesseract-ocr-data-osd \
tesseract-ocr-data-por \
tesseract-ocr-data-spa \
ttf-droid \
unpaper \
&& rm -rf /var/cache/apk/*

WORKDIR /app

COPY --from=builder /usr/local/lib/ /usr/local/lib/
COPY --from=builder /usr/local/bin/ /usr/local/bin/

COPY --from=builder /app/.venv/ /app/.venv/

COPY --from=builder /app/misc/webservice.py /app/
COPY --from=builder /app/misc/watcher.py /app/

# Copy minimal project files to get the test suite.
COPY --from=builder /app/pyproject.toml /app/README.md /app/
COPY --from=builder /app/tests /app/tests

ENV PATH="/app/.venv/bin:${PATH}"

ENTRYPOINT ["/app/.venv/bin/ocrmypdf"]
50 changes: 47 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,52 @@ jobs:
--tag "${DOCKER_REPOSITORY}/${DOCKER_IMAGE_NAME}-ubuntu:${DOCKER_IMAGE_TAG}" \
--file .docker/Dockerfile .
docker_alpine:
name: Build Alpine-based Docker images
docker_alpine_x64:
name: Build Alpine-based Docker images x64
needs: [wheel_sdist_linux, test_linux, test_macos, test_windows]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Set image tag to release or branch
run: echo "DOCKER_IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: If main, set to latest
run: echo 'DOCKER_IMAGE_TAG=latest' >> $GITHUB_ENV
if: env.DOCKER_IMAGE_TAG == 'main'

- name: Set Docker Hub repository to username
run: echo "DOCKER_REPOSITORY=jbarlow83" >> $GITHUB_ENV

- name: Set image name
run: echo "DOCKER_IMAGE_NAME=ocrmypdf-alpine" >> $GITHUB_ENV

- uses: actions/checkout@v4
with:
fetch-depth: "0" # 0=all, needed for setuptools-scm to resolve version tags

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: jbarlow83
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Print image tag
run: echo "Building image ${DOCKER_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"

- name: Build
run: |
docker buildx build \
--push \
--platform linux/amd64 \
--tag "${DOCKER_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
--file .docker/Dockerfile.alpine .
docker_alpine_arm64:
name: Build Alpine-based Docker images arm64
needs: [wheel_sdist_linux, test_linux, test_macos, test_windows]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -372,6 +416,6 @@ jobs:
run: |
docker buildx build \
--push \
--platform linux/amd64 \
--platform linux/arm64 \
--tag "${DOCKER_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}" \
--file .docker/Dockerfile.alpine .

0 comments on commit 0f3e880

Please sign in to comment.