Skip to content

Commit

Permalink
Update Docker config and testing for src-layout
Browse files Browse the repository at this point in the history
Fix syntax warning in dockerfile

Update dockerfile for src-layout

Rejig dev api container to accommodate src-layout and add dev container
healthcheck

Fix docker build

Disable fail fast

Combine dev docker builds into one job
  • Loading branch information
ml-evs committed Oct 8, 2024
1 parent 5fb4411 commit d06c8f8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .docker/app_dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM node:20-bullseye as base
FROM node:20-bullseye AS base
SHELL ["/bin/bash", "--login", "-c"]

WORKDIR /app
Expand Down
31 changes: 18 additions & 13 deletions .docker/server_dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM python:3.10 as base
FROM python:3.10 AS base
SHELL ["/bin/bash", "--login", "-c"]

# Useful for installing deps from git, preventing big downloads and bandwith quotas
Expand All @@ -16,24 +16,29 @@ FROM base as app

WORKDIR /app

# Set up uv venv in /opt/.venv to avoid polluting the mounted /app dir
RUN pip install uv
COPY --from=ghcr.io/astral-sh/uv:0.4 /uv /usr/local/bin/uv
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PROJECT_ENVIRONMENT=/opt/.venv \
UV_PYTHON=python3.10

WORKDIR /opt
COPY pydatalab/pyproject.toml /_lock/
COPY pydatalab/uv.lock /_lock/
COPY pydatalab/requirements/requirements-all.txt /_lock/
RUN uv venv
RUN uv pip install -r /_lock/requirements-all.txt

COPY pydatalab/requirements/requirements-all.txt .
RUN uv pip install -r requirements-all.txt

WORKDIR /app
COPY pydatalab/pyproject.toml .
# Create development image using flask's dev server with hot-reload
FROM app as development

ENV FLASK_APP "pydatalab.main:create_app()"

WORKDIR /app
ENV FLASK_APP "pydatalab.main"
ENV FLASK_ENV "development"
ENV PORT=5001

CMD ["/bin/bash", "-c", "/opt/.venv/bin/python -m flask run --reload --port ${PORT} --host 0.0.0.0"]
CMD [ "/bin/bash", "-c", "source /opt/.venv/bin/activate && exec flask run --reload --port ${PORT} --host 0.0.0.0" ]

# Create production image using gunicorn and minimal dependencies
FROM app as production
Expand All @@ -54,8 +59,8 @@ ENV PORT=${PORT}

# Install the local version of the package and mount the repository data to get version info
RUN git config --global --add safe.directory /
RUN --mount=type=bind,target=/.git,source=./.git ["uv", "pip", "install", "--python", "/opt/.venv/bin/python", "."]
RUN --mount=type=bind,target=/.git,source=./.git ["uv", "pip", "install", "--python", "/opt/.venv/bin/python", "--no-deps", "."]

CMD ["/bin/bash", "-c", "/opt/.venv/bin/python -m gunicorn --preload -w ${WEB_CONCURRENCY} --error-logfile /logs/pydatalab_error.log --access-logfile - -b 0.0.0.0:${PORT} 'pydatalab.main:create_app()'"]

HEALTHCHECK --interval=30s --timeout=30s --start-interval=5s --start-period=30s --retries=3 CMD curl --fail http://localhost:${PORT}/healthcheck/is_ready || exit 1
HEALTHCHECK --interval=30s --timeout=30s --start-interval=15s --start-period=30s --retries=3 CMD curl --fail http://localhost:${PORT}/healthcheck/is_ready || exit 1
22 changes: 14 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ jobs:
docker:
name: Test dev Docker builds
runs-on: ubuntu-latest
strategy:
matrix:
target:
- "app_dev"
- "api_dev"
- "database_dev"

steps:
- uses: actions/checkout@v4
Expand All @@ -143,8 +137,20 @@ jobs:
load: true
targets: ${{ matrix.target }}
set: |
*.cache-to=type=gha,scope=build-${{ matrix.target }},mode=max
*.cache-from=type=gha,scope=build-${{ matrix.target }}
app_dev.cache-to=type=gha,scope=build-app_dev,mode=max
app_dev.cache-from=type=gha,scope=build-app_dev
app_dev.tags=datalab-app_dev:latest
api_dev.cache-to=type=gha,scope=build-api_dev,mode=max
api_dev.cache-from=type=gha,scope=build-api_dev
api_dev.tags=datalab-api_dev:latest
database_dev.cache-to=type=gha,scope=build-database-dev,mode=max
database_dev.cache-from=type=gha,scope=build-database_dev
database_dev.tags=datalab-database_dev:latest
- name: Start services
run: |
# Launch dev container profiles and wait for them to come up with healthchecks
docker compose up app_dev api_dev database_dev --wait --no-build --force-recreate -d
e2e:
name: e2e tests
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
volumes:
- ./logs:/logs
- ./.git:/.git
- ./pydatalab:/app
- ./pydatalab/src:/app
ports:
- "5001:5001"
networks:
Expand Down

0 comments on commit d06c8f8

Please sign in to comment.