Skip to content

Commit

Permalink
gha: use docker targets
Browse files Browse the repository at this point in the history
- we drop the `Dockerfile.dev`
  • Loading branch information
nosahama committed Jan 22, 2025
1 parent 0b76ba6 commit 8cfd479
Showing 4 changed files with 52 additions and 61 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -50,11 +50,17 @@ jobs:

- name: Cache docker layers
uses: docker/build-push-action@v4
env:
PYTHON_VERSION: ${{ matrix.python-version }}
KARAPACE_VERSION: ${{ env.KARAPACE_VERSION }}
with:
context: .
cache-to: type=inline
cache-from: type=gha
cache-to: type=gha,mode=max
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

49 changes: 39 additions & 10 deletions container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG PYTHON_VERSION

# Current versions of avro and zstandard don't yet have wheels for 3.11.
FROM python:3.10.11-bullseye AS builder
FROM python:${PYTHON_VERSION}-bullseye AS builder

ARG KARAPACE_VERSION

@@ -35,14 +37,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.
RUN groupadd --system karapace \
&& useradd --system --gid karapace karapace \
&& mkdir /opt/karapace /opt/karapace/runtime /var/log/karapace \
&& chown --recursive karapace:karapace /opt/karapace /var/log/karapace
# Karapace image, i.e. production.
FROM builder AS karapace

# Install protobuf compiler.
ARG PROTOBUF_COMPILER_VERSION="3.12.4-1+deb11u1"
@@ -51,10 +48,42 @@ RUN apt-get update \
protobuf-compiler=$PROTOBUF_COMPILER_VERSION \
&& rm -rf /var/lib/apt/lists/*

# Copy virtualenv from builder and activate it.
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 . .
ENV PYTHONPATH="/opt/karapace/src:$PYTHONPATH"


FROM karapace AS production

# Setup user and directories.
RUN groupadd --system karapace \
&& useradd --system --gid karapace karapace \
&& mkdir /opt/karapace /opt/karapace/runtime /var/log/karapace \
&& chown --recursive karapace:karapace /opt/karapace /var/log/karapace


COPY ./container/healthcheck.py /opt/karapace

WORKDIR /opt/karapace
47 changes: 0 additions & 47 deletions container/Dockerfile.dev

This file was deleted.

7 changes: 5 additions & 2 deletions container/compose.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -171,7 +174,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

0 comments on commit 8cfd479

Please sign in to comment.