diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index faf309aba..f86986e0e 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -78,5 +78,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: | KARAPACE_VERSION=${{ steps.ctx.outputs.version }} + PYTHON_VERSION=3.10.11 file: container/Dockerfile platforms: "linux/amd64,linux/arm64" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 45a5bb454..167bef347 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -48,13 +48,24 @@ jobs: - run: echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV - run: echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Cache docker layers uses: docker/build-push-action@v4 + env: + PYTHON_VERSION: ${{ matrix.python-version }} + KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }} + PR_TAG: aiven-open/karapace-pr:${{ env.KARAPACE_VERSION }} with: context: . - cache-to: type=inline + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ env.PR_TAG }} push: false - build-args: KARAPACE_VERSION=${{ env.KARAPACE_VERSION }} + build-args: | + KARAPACE_VERSION=${{ env.KARAPACE_VERSION }} + PYTHON_VERSION=${{ matrix.python-version }} file: container/Dockerfile platforms: linux/amd64 diff --git a/container/Dockerfile b/container/Dockerfile index 1bcd9ccce..1822bc3ef 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -1,6 +1,7 @@ -# Current versions of avro and zstandard don't yet have wheels for 3.11. -FROM python:3.10.11-bullseye AS builder +ARG PYTHON_VERSION=3.10.11 +# Current versions of avro and zstandard don't yet have wheels for 3.11. +FROM python:${PYTHON_VERSION}-bullseye AS builder ARG KARAPACE_VERSION # Create, activate, and enforce usage of virtualenv. @@ -35,16 +36,9 @@ RUN --mount=type=cache,target=/root/.cache/pip \ fi; \ SETUPTOOLS_SCM_PRETEND_VERSION=$PRETEND_VERSION python3 -m pip install --no-deps . -# Karapace image, i.e. production. -FROM python:3.10.11-slim-bullseye AS karapace - -# Setup user and directories. -# https://docs.redhat.com/en/documentation/openshift_container_platform/4.17/html/images/creating-images#use-uid_create-images -RUN useradd --system --gid 0 karapace \ - && mkdir /opt/karapace /opt/karapace/runtime /var/log/karapace \ - && chgrp -R 0 /opt/karapace /opt/karapace/runtime /var/log/karapace \ - && chmod -R g+rwX /opt/karapace +# Karapace image, i.e. production. +FROM builder AS karapace # Install protobuf compiler. ARG PROTOBUF_COMPILER_VERSION="3.12.4-1+deb11u1" RUN apt-get update \ @@ -56,6 +50,39 @@ RUN apt-get update \ COPY --from=builder /venv /venv ENV PATH="/venv/bin:$PATH" + +FROM karapace AS cli +ARG RUNNER_UID +ARG RUNNER_GID + +# Setup files and directories. +RUN mkdir /opt/karapace /opt/karapace/runtime /var/log/karapace /opt/karapace/coverage \ +&& touch /opt/karapace/coverage/.coverage.3.10 /opt/karapace/coverage/.coverage.3.11 /opt/karapace/coverage/.coverage.3.12 \ +&& chown --recursive "$RUNNER_UID:$RUNNER_GID" /opt/karapace /opt/karapace/coverage /var/log/karapace + +# Install Java via openjdk-11 +COPY --from=openjdk:11 /usr/local/openjdk-11 /usr/local/openjdk-11 +ENV JAVA_HOME /usr/local/openjdk-11 +RUN update-alternatives --install /usr/bin/java java /usr/local/openjdk-11/bin/java 1 + +WORKDIR /opt/karapace + +COPY ./requirements /opt/karapace/requirements +RUN python3 -m pip install -r /opt/karapace/requirements/requirements-dev.txt -r /opt/karapace/requirements/requirements-typing.txt + +COPY . . +RUN SETUPTOOLS_SCM_PRETEND_VERSION=$KARAPACE_VERSION python3 -m pip install . +ENV PYTHONPATH="/opt/karapace/src:$PYTHONPATH" + + +FROM karapace AS production +# Setup user and directories. +# https://docs.redhat.com/en/documentation/openshift_container_platform/4.17/html/images/creating-images#use-uid_create-images +RUN useradd --system --gid 0 karapace \ + && mkdir /opt/karapace /opt/karapace/runtime /var/log/karapace \ + && chgrp -R 0 /opt/karapace /opt/karapace/runtime /var/log/karapace \ + && chmod -R g+rwX /opt/karapace + COPY ./container/healthcheck.py /opt/karapace WORKDIR /opt/karapace diff --git a/container/Dockerfile.dev b/container/Dockerfile.dev deleted file mode 100644 index 826931969..000000000 --- a/container/Dockerfile.dev +++ /dev/null @@ -1,47 +0,0 @@ -ARG PYTHON_VERSION - -# Current versions of avro and zstandard don't yet have wheels for 3.11. -FROM python:${PYTHON_VERSION}-bullseye AS builder - -ARG KARAPACE_VERSION -ARG RUNNER_UID -ARG RUNNER_GID - -# Setup files and directories. -RUN mkdir /opt/karapace /opt/karapace/runtime /var/log/karapace /opt/karapace/coverage \ -&& touch /opt/karapace/coverage/.coverage.3.10 /opt/karapace/coverage/.coverage.3.11 /opt/karapace/coverage/.coverage.3.12 \ -&& chown --recursive "$RUNNER_UID:$RUNNER_GID" /opt/karapace /opt/karapace/coverage /var/log/karapace - -# Create, activate, and enforce usage of virtualenv. -RUN python3 -m venv /opt/karapace/venv -ENV PATH="/opt/karapace/venv/bin:$PATH" -ENV PIP_REQUIRE_VIRTUALENV=true - -# Install golang needed by extensions -ENV GO_VERSION=1.21.0 -ENV PATH="/usr/local/go/bin:${PATH}" -RUN wget --progress=dot:giga "https://go.dev/dl/go${GO_VERSION}.linux-$(dpkg --print-architecture).tar.gz" \ - && tar -C /usr/local -xzf "go${GO_VERSION}.linux-$(dpkg --print-architecture).tar.gz" \ - && rm "go${GO_VERSION}.linux-$(dpkg --print-architecture).tar.gz" - -# Install protobuf compiler. -ARG PROTOBUF_COMPILER_VERSION="3.12.4-1+deb11u1" -RUN apt-get update \ - && apt-get install --assume-yes --no-install-recommends \ - protobuf-compiler=$PROTOBUF_COMPILER_VERSION \ - && rm -rf /var/lib/apt/lists/* - -# Install Java via openjdk-11 -COPY --from=openjdk:11 /usr/local/openjdk-11 /usr/local/openjdk-11 -ENV JAVA_HOME /usr/local/openjdk-11 -RUN update-alternatives --install /usr/bin/java java /usr/local/openjdk-11/bin/java 1 - -WORKDIR /opt/karapace - -COPY ./requirements /opt/karapace/requirements -RUN python3 -m pip install -r /opt/karapace/requirements/requirements.txt -r /opt/karapace/requirements/requirements-dev.txt -r /opt/karapace/requirements/requirements-typing.txt - -COPY . . -RUN SETUPTOOLS_SCM_PRETEND_VERSION=$KARAPACE_VERSION python3 -m pip install . - -ENV PYTHONPATH="/opt/karapace/src:$PYTHONPATH" diff --git a/container/compose.yml b/container/compose.yml index 39fb14393..bf85eb9c7 100644 --- a/container/compose.yml +++ b/container/compose.yml @@ -59,6 +59,7 @@ services: dockerfile: container/Dockerfile args: KARAPACE_VERSION: $KARAPACE_VERSION + PYTHON_VERSION: $PYTHON_VERSION entrypoint: - python3 - -m @@ -100,6 +101,7 @@ services: dockerfile: container/Dockerfile args: KARAPACE_VERSION: $KARAPACE_VERSION + PYTHON_VERSION: $PYTHON_VERSION entrypoint: - python3 - -m @@ -128,7 +130,8 @@ services: image: ghcr.io/aiven-open/karapace:cli build: context: .. - dockerfile: container/Dockerfile.dev + target: cli + dockerfile: container/Dockerfile args: KARAPACE_VERSION: $KARAPACE_VERSION PYTHON_VERSION: $PYTHON_VERSION @@ -176,7 +179,7 @@ services: GF_SECURITY_ADMIN_PASSWORD: karapace GF_PATHS_PROVISIONING: /grafana/provisioning ports: - - 3000:3000 + - 9091:3000 volumes: - ./grafana/dashboards:/grafana/dashboards - ./grafana/provisioning:/grafana/provisioning