Skip to content

Commit 5404807

Browse files
add conditional build environment
Signed-off-by: Jonathan Irvin <djfoxyslpr@gmail.com>
1 parent 0b5c453 commit 5404807

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.github/workflows/docker-build-publish.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ jobs:
3131
context: .
3232
file: ./Dockerfile
3333
push: true
34-
tags: ghcr.io/offendingcommit/bingo:latest
34+
tags: ghcr.io/offendingcommit/bingo:latest
35+
build-args: BUILD_ENVIRONMENT=production

Dockerfile

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
FROM python:3.12-slim
33

44
# Set environment variables for Python and prevent the creation of .pyc files
5-
ENV PYTHONDONTWRITEBYTECODE=1
6-
ENV PYTHONUNBUFFERED=1
5+
ARG BUILD_ENVIRONMENT
6+
7+
ENV BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT} \
8+
PYTHONDONTWRITEBYTECODE=1 \
9+
PYTHONFAULTHANDLER=1 \
10+
PYTHONUNBUFFERED=1 \
11+
PYTHONHASHSEED=random \
12+
PIP_NO_CACHE_DIR=off \
13+
PIP_DISABLE_PIP_VERSION_CHECK=on \
14+
PIP_DEFAULT_TIMEOUT=100 \
15+
# Poetry's configuration:
16+
POETRY_NO_INTERACTION=1 \
17+
POETRY_VIRTUALENVS_CREATE=false \
18+
POETRY_CACHE_DIR='/var/cache/pypoetry' \
19+
POETRY_HOME='/usr/local' \
20+
POETRY_VERSION=1.8.3
721

822
# Install OS dependencies required for building some Python packages
923
RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -12,7 +26,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1226
&& rm -rf /var/lib/apt/lists/*
1327

1428
# Install Poetry
15-
RUN pip install --upgrade pip && pip install poetry
29+
RUN pip install --upgrade pip && curl -sSL https://install.python-poetry.org | python3 -
1630

1731
# Set working directory
1832
WORKDIR /app
@@ -21,8 +35,7 @@ WORKDIR /app
2135
COPY pyproject.toml poetry.lock* /app/
2236

2337
# Configure Poetry to not create a virtual environment and install dependencies
24-
RUN poetry config virtualenvs.create false && \
25-
poetry install --no-interaction --no-ansi --no-dev
38+
RUN poetry install $(test "$BUILD_ENVIRONMENT" == production && echo "--only=main")
2639

2740
# Copy the rest of the project
2841
COPY . /app

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ nicegui = "^2.11.0"
1212

1313

1414
[build-system]
15-
requires = ["poetry-core"]
15+
requires = ["poetry-core>=1.8"]
1616
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)