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 authored and jjaakola-aiven committed Jan 23, 2025
1 parent b840de3 commit 0702364
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 62 deletions.
1 change: 1 addition & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
15 changes: 13 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 38 additions & 11 deletions container/Dockerfile
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down
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
Expand Up @@ -59,6 +59,7 @@ services:
dockerfile: container/Dockerfile
args:
KARAPACE_VERSION: $KARAPACE_VERSION
PYTHON_VERSION: $PYTHON_VERSION
entrypoint:
- python3
- -m
Expand Down Expand Up @@ -100,6 +101,7 @@ services:
dockerfile: container/Dockerfile
args:
KARAPACE_VERSION: $KARAPACE_VERSION
PYTHON_VERSION: $PYTHON_VERSION
entrypoint:
- python3
- -m
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0702364

Please sign in to comment.