From 6f7d49536aca5607c4b65ac84098c63deeb8cb7e Mon Sep 17 00:00:00 2001 From: Guilherme Caminha Date: Mon, 11 Mar 2024 17:54:34 +0100 Subject: [PATCH 1/3] Add a dev target to Dockerfile, add a dev compose file - Add a dev target to Dockerfile which will install dev and static-check dependencies - Set up a volume that syncs local changes into the running containers - Create a new compose service for barebones development and running tests --- container/Dockerfile | 18 ++++++++++++++++++ container/compose-dev.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 container/compose-dev.yml diff --git a/container/Dockerfile b/container/Dockerfile index 61ad142b8..66d511ebf 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -53,3 +53,21 @@ USER karapace HEALTHCHECK --interval=10s --timeout=30s --retries=3 --start-period=60s \ CMD python3 healthcheck.py http://localhost:$KARAPACE_PORT/_health || exit 1 + + +FROM builder AS dev-builder + +# Install dev dependencies. +COPY ./requirements/requirements-dev.txt /build/ +COPY ./requirements/requirements-typing.txt /build/ +RUN --mount=type=cache,target=/root/.cache/pip \ + python3 -m pip install -r /build/requirements-dev.txt -r /build/requirements-typing.txt + + +# Dev build stage +FROM karapace AS dev + +COPY --from=dev-builder /venv /venv + +RUN mkdir /opt/karapace/app +ENV PYTHONPATH="/opt/karapace/app:${PYTHONPATH}" diff --git a/container/compose-dev.yml b/container/compose-dev.yml new file mode 100644 index 000000000..eb0e4aa59 --- /dev/null +++ b/container/compose-dev.yml @@ -0,0 +1,29 @@ +--- +version: '3' +services: + karapace-registry: + build: + context: .. + dockerfile: container/Dockerfile + target: dev + volumes: + - ../:/opt/karapace/app + + karapace-rest: + build: + context: .. + dockerfile: container/Dockerfile + target: dev + volumes: + - ../:/opt/karapace/app + + karapace-dev: + build: + context: .. + dockerfile: container/Dockerfile + target: dev + volumes: + - ../:/opt/karapace/app + working_dir: /opt/karapace/app + depends_on: + - kafka From 6802f1d67e107a883fa19c786c467ddf518c959e Mon Sep 17 00:00:00 2001 From: Guilherme Caminha Date: Tue, 12 Mar 2024 11:51:17 +0100 Subject: [PATCH 2/3] Install Java sdk dependency on dev container --- container/Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/container/Dockerfile b/container/Dockerfile index 66d511ebf..e3627f00e 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -67,6 +67,17 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # Dev build stage FROM karapace AS dev +# Install linux dependencies +USER root + +RUN apt-get update \ + && apt-get install --assume-yes --no-install-recommends \ + openjdk-11-jdk \ + && rm -rf /var/lib/apt/lists/* + +USER karapace + + COPY --from=dev-builder /venv /venv RUN mkdir /opt/karapace/app From e8d17af39edc401ea3aaf94bc167ef2423267673 Mon Sep 17 00:00:00 2001 From: Guilherme Caminha Date: Tue, 12 Mar 2024 15:49:51 +0100 Subject: [PATCH 3/3] Set compose into a single file. Fix docker build stage orders so that prod is default. --- container/Dockerfile | 13 +++++++++---- container/compose-dev.yml | 29 ----------------------------- container/compose.yml | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 33 deletions(-) delete mode 100644 container/compose-dev.yml diff --git a/container/Dockerfile b/container/Dockerfile index e3627f00e..513b774c9 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -22,8 +22,8 @@ COPY . /build/karapace-repo RUN --mount=type=cache,target=/root/.cache/pip \ python3 -m pip install /build/karapace-repo -# Karapace image, i.e. production. -FROM python:3.10.11-slim-bullseye AS karapace + +FROM python:3.10.11-slim-bullseye AS karapace-base # Setup user and directories. RUN groupadd --system karapace \ @@ -65,14 +65,15 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # Dev build stage -FROM karapace AS dev +FROM karapace-base AS dev # Install linux dependencies USER root +ARG OPENJDK_VERSION="11.0.22+7-1~deb11u1" RUN apt-get update \ && apt-get install --assume-yes --no-install-recommends \ - openjdk-11-jdk \ + openjdk-11-jdk=$OPENJDK_VERSION \ && rm -rf /var/lib/apt/lists/* USER karapace @@ -82,3 +83,7 @@ COPY --from=dev-builder /venv /venv RUN mkdir /opt/karapace/app ENV PYTHONPATH="/opt/karapace/app:${PYTHONPATH}" + + +# Production build stage (keep last so it's the default) +FROM karapace-base AS karapace diff --git a/container/compose-dev.yml b/container/compose-dev.yml deleted file mode 100644 index eb0e4aa59..000000000 --- a/container/compose-dev.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -version: '3' -services: - karapace-registry: - build: - context: .. - dockerfile: container/Dockerfile - target: dev - volumes: - - ../:/opt/karapace/app - - karapace-rest: - build: - context: .. - dockerfile: container/Dockerfile - target: dev - volumes: - - ../:/opt/karapace/app - - karapace-dev: - build: - context: .. - dockerfile: container/Dockerfile - target: dev - volumes: - - ../:/opt/karapace/app - working_dir: /opt/karapace/app - depends_on: - - kafka diff --git a/container/compose.yml b/container/compose.yml index f1328afef..edc0c5b7a 100644 --- a/container/compose.yml +++ b/container/compose.yml @@ -59,6 +59,9 @@ services: build: context: .. dockerfile: container/Dockerfile + target: dev + volumes: + - ../:/opt/karapace/app entrypoint: - /bin/bash - /opt/karapace/start.sh @@ -84,6 +87,9 @@ services: build: context: .. dockerfile: container/Dockerfile + target: dev + volumes: + - ../:/opt/karapace/app entrypoint: - /bin/bash - /opt/karapace/start.sh @@ -102,3 +108,15 @@ services: KARAPACE_REGISTRY_PORT: 8081 KARAPACE_ADMIN_METADATA_MAX_AGE: 0 KARAPACE_LOG_LEVEL: WARNING + + karapace-dev: + image: karapace:latest + build: + context: .. + dockerfile: container/Dockerfile + target: dev + volumes: + - ../:/opt/karapace/app + working_dir: /opt/karapace/app + depends_on: + - kafka