Skip to content

Commit

Permalink
minimise size of docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
jr200 committed Sep 7, 2024
1 parent fc4384d commit 80e2ff2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ POETRY_VERSION:=1.8.3

DOCKER_REGISTRY:=ghcr.io/jr200
IMAGE_NAME:=vault-actions
IMAGE_TAG:=latest
IMAGE_TAG:=local

VAULT_TOKEN ?= ""

Expand Down
2 changes: 1 addition & 1 deletion charts/vault-actions/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ version: 0.1.0
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.1.0"
appVersion: "v0.1.1"
46 changes: 27 additions & 19 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
FROM vault:1.13.3 AS vault-cli

FROM python:3.12-slim-bullseye
FROM python:3.12-slim-bullseye AS builder

ARG POETRY_VERSION=1.8.3

RUN useradd -d /app -m -s /bin/bash app_user

# Set the working directory in the container
WORKDIR /app

# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY --from=vault-cli /bin/vault /bin/vault

USER app_user

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=${POETRY_VERSION} python3 -
ENV POETRY_VIRTUALENVS_CREATE=true \
POETRY_VIRTUALENVS_IN_PROJECT=true \
PATH="/app/.venv/bin:/app/.local/bin:$PATH"

RUN curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION}

COPY --chown=app_user:app_user pyproject.toml poetry.lock* ./

RUN poetry install --no-interaction --no-root

COPY --chown=app_user:app_user ./vault_actions /app/vault_actions

# Add Poetry to PATH
ENV POETRY_VIRTUALENVS_CREATE="true"
ENV POETRY_VIRTUALENVS_IN_PROJECT="true"
ENV PATH="/app/.venv/bin:/app/.local/bin:${PATH}"
# build slim image

# # Copy the pyproject.toml (and optionally poetry.lock) file into the container
COPY ./docker/docker-entrypoint.sh pyproject.toml poetry.lock* ./
FROM python:3.12-slim-bullseye

RUN useradd -d /app -m -s /bin/bash app_user
WORKDIR /app

COPY --from=vault-cli /bin/vault /bin/vault

USER app_user
ENV PATH="/app/.venv/bin:/app/.local/bin:$PATH"

# Install dependencies using Poetry
RUN poetry install --only main --no-root --no-interaction --no-directory
COPY --from=builder --chown=app_user:app_user /app/vault_actions /app/vault_actions
COPY --from=builder --chown=app_user:app_user /app/.venv /app/.venv
COPY --chown=app_user:app_user ./docker/docker-entrypoint.sh /app/docker-entrypoint.sh

# # Copy the package files into the container
COPY ./vault_actions /app/vault_actions
RUN chmod +x /app/docker-entrypoint.sh

ENTRYPOINT ["/app/docker-entrypoint.sh"]
ENTRYPOINT ["/app/docker-entrypoint.sh"]

0 comments on commit 80e2ff2

Please sign in to comment.