-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
# Base image for building the virtual environment | ||
FROM python:{{cookiecutter.python_version}}-bookworm AS builder | ||
# Base image for building the application | ||
FROM node:{{cookiecutter.node_version}}-bookworm AS builder | ||
|
||
ENV PATH="/root/.cargo/bin:$PATH" \ | ||
UV_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple" \ | ||
PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple" | ||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Install uv and tools | ||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh | ||
# Copy package.json and package-lock.json to the container | ||
COPY package.json yarn.lock ./ | ||
|
||
WORKDIR /app | ||
# Install dependencies | ||
RUN yarn install | ||
|
||
COPY pyproject.toml . | ||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Create and install dependencies in the virtual environment | ||
RUN uv sync | ||
# Build the application | ||
RUN yarn build | ||
|
||
# Separate stage for validation (build and test) | ||
FROM builder AS validator | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
# Run build and test as part of the validation | ||
RUN make build && make test | ||
# Run tests as part of the validation | ||
RUN yarn test | ||
|
||
# Final image for running the application | ||
FROM python:{{cookiecutter.python_version}}-slim-bookworm | ||
FROM node:{{cookiecutter.node_version}}-slim-bookworm | ||
|
||
LABEL author="{{cookiecutter.full_name}}" | ||
|
||
ENV PATH="/app/.venv/bin:$PATH" \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy the virtual environment and application code | ||
COPY --from=builder /app/.venv /app/.venv | ||
COPY src ./src | ||
# Copy built application code and node_modules from builder | ||
COPY --from=builder /app/dist ./dist | ||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY package.json yarn.lock ./ | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 3000 | ||
|
||
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)" | ||
# Define a health check | ||
HEALTHCHECK --start-period=30s CMD curl -f http://localhost:3000 || exit 1 | ||
|
||
CMD ["python", "src/{{cookiecutter.package_name}}/app.py"] | ||
# Start the application | ||
CMD ["node", "dist/index.js"] |