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 a dev target to Dockerfile, add a dev compose file #836

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
38 changes: 36 additions & 2 deletions container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -53,3 +53,37 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Introducing the new stages means we must update the release flow so that we don't start publishing dev images: https://github.com/Aiven-Open/karapace/blob/main/.github/workflows/container.yml.

Similarly, I think if we're to keep the two compose files, target must be specified in the existing one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple solution for this is simply to have the actual production stage come after the dev stage. This way, the default will always be the production one. And by correctly using dependencies, when building for the prod stage (implicitly or not), docker won't run any of the build code for dev.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like the best solution 👍


# 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-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_VERSION \
&& rm -rf /var/lib/apt/lists/*

USER karapace


COPY --from=dev-builder /venv /venv

RUN mkdir /opt/karapace/app
ENV PYTHONPATH="/opt/karapace/app:${PYTHONPATH}"
aiven-anton marked this conversation as resolved.
Show resolved Hide resolved


# Production build stage (keep last so it's the default)
FROM karapace-base AS karapace
18 changes: 18 additions & 0 deletions container/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ services:
build:
context: ..
dockerfile: container/Dockerfile
target: dev
volumes:
- ../:/opt/karapace/app
entrypoint:
- /bin/bash
- /opt/karapace/start.sh
Expand All @@ -84,6 +87,9 @@ services:
build:
context: ..
dockerfile: container/Dockerfile
target: dev
volumes:
- ../:/opt/karapace/app
entrypoint:
- /bin/bash
- /opt/karapace/start.sh
Expand All @@ -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
Loading