diff --git a/.docker/Dockerfile.alpine b/.docker/Dockerfile.alpine index e8ea913bf..8ad11407f 100644 --- a/.docker/Dockerfile.alpine +++ b/.docker/Dockerfile.alpine @@ -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 @@ -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 diff --git a/.docker/Dockerfile.alpine-arm64 b/.docker/Dockerfile.alpine-arm64 new file mode 100644 index 000000000..0089bb199 --- /dev/null +++ b/.docker/Dockerfile.alpine-arm64 @@ -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"] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ad3719a5..7e5ab2faa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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' @@ -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 .