Skip to content

Commit

Permalink
build docker images with pip
Browse files Browse the repository at this point in the history
  • Loading branch information
Der-Henning committed Jul 28, 2023
1 parent c6c8c2d commit e1fde61
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ repos:
hooks:
- id: markdownlint
args: [--fix]

- repo: https://github.com/python-poetry/poetry
rev: 1.5.1 # add version here
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
args: [-f, requirements.txt, -o, ./docker/requirements.txt]
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
images:
poetry export -f requirements.txt --output ./docker/requirements.txt
docker build -f ./docker/Dockerfile -t tgtg-scanner:latest .
docker build -f ./docker/Dockerfile.alpine -t tgtg-scanner:latest-alpine .

Expand Down
35 changes: 13 additions & 22 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
FROM python:3-slim as base
FROM python:3.10-slim

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"
PIP_NO_WARN_SCRIPT_LOCATION=0
ENV TGTG_TOKEN_PATH=/tokens
ENV LOGS_PATH=/logs
ENV DOCKER=true
ENV POETRY_VERSION=1.5.1
ENV UID=1000
ENV GID=1000

RUN addgroup --gid $GID tgtg && \
adduser --shell /bin/false --disabled-password --uid $UID --gid $GID tgtg
adduser --shell /bin/false \
--disabled-password \
--uid $UID \
--gid $GID \
tgtg
RUN mkdir -p /logs
RUN mkdir -p /tokens
RUN chown tgtg:tgtg /tokens
RUN chown tgtg:tgtg /logs
VOLUME /tokens
RUN apt-get update && apt-get upgrade -y
WORKDIR $PYSETUP_PATH
COPY . .

# Build dependencies
FROM base as builder
RUN apt-get install -y build-essential libssl-dev libffi-dev python3-dev cargo pkg-config
RUN pip install --upgrade pip setuptools wheel && \
pip install "poetry==$POETRY_VERSION"
RUN poetry install --without test,build
RUN --mount=type=bind,target=/context \
pip install -r /context/docker/requirements.txt && \
pip install /context

# Create Production Image
FROM base as production
ENV PATH="$VENV_PATH/bin:$PATH"
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY --from=builder $VENV_PATH $VENV_PATH

RUN python -m tgtg_scanner -v

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "python", "-m", "tgtg_scanner" ]
38 changes: 15 additions & 23 deletions docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
FROM python:3-alpine as base
FROM python:3.10-alpine as base

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1 \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
PYSETUP_PATH="/opt/pysetup" \
VENV_PATH="/opt/pysetup/.venv"
PIP_NO_WARN_SCRIPT_LOCATION=0
ENV TGTG_TOKEN_PATH=/tokens
ENV LOGS_PATH=/logs
ENV DOCKER=true
ENV POETRY_VERSION=1.5.1
ENV UID=1000
ENV GID=1000

RUN addgroup --gid $GID --system tgtg && \
adduser --shell /bin/false --disabled-password --uid $UID --system --ingroup tgtg tgtg
adduser --shell /bin/false \
--disabled-password \
--uid $UID \
--system \
--ingroup tgtg \
tgtg
RUN mkdir -p /logs
RUN mkdir -p /tokens
RUN chown tgtg:tgtg /tokens
RUN chown tgtg:tgtg /logs
VOLUME /tokens
RUN apk update
WORKDIR $PYSETUP_PATH
COPY . .

# Build dependencies
FROM base as builder
RUN apk add --no-cache alpine-sdk libffi-dev gcc musl-dev python3-dev openssl-dev cargo pkgconfig
RUN pip install --upgrade pip setuptools wheel && \
pip install "poetry==$POETRY_VERSION"
RUN poetry install --without test,build
RUN apk update && apk add --no-cache shadow runuser
RUN --mount=type=bind,target=/context \
pip install -r /context/docker/requirements.txt && \
pip install /context

# Create Production Image
FROM base as production
ENV PATH="$VENV_PATH/bin:$PATH"
RUN apk add --no-cache shadow runuser
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY --from=builder $VENV_PATH $VENV_PATH

RUN python -m tgtg_scanner -v

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "python", "-m", "tgtg_scanner" ]
Loading

0 comments on commit e1fde61

Please sign in to comment.