-
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
10 changed files
with
59 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"project_name": "My Awesome Project", | ||
"project_slug": "{{ cookiecutter.project_name | slugify }}", | ||
"package_name": "{{ cookiecutter.project_slug | replace('-', '_') }}", | ||
"project_desc": "A nice python project", | ||
"project_desc": "A nice rust project", | ||
"project_version": "0.0.1", | ||
"email": "[email protected]", | ||
"full_name": "Firstname Lastname", | ||
|
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,33 @@ | ||
# Base image for building the virtual environment | ||
FROM python:{{cookiecutter.python_version}}-bookworm AS builder | ||
# Stage 1: Build the Rust project using the official Rust image | ||
FROM rust:1-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" | ||
|
||
# Install uv and tools | ||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh | ||
# Install required dependencies for building | ||
RUN apt-get update && apt-get install -y \ | ||
pkg-config \ | ||
libssl-dev \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
COPY pyproject.toml . | ||
|
||
# Create and install dependencies in the virtual environment | ||
RUN uv sync | ||
|
||
# Separate stage for validation (build and test) | ||
FROM builder AS validator | ||
|
||
WORKDIR /app | ||
# Copy the project files into the container | ||
COPY . . | ||
|
||
# Run build and test as part of the validation | ||
RUN make build && make test | ||
|
||
# Final image for running the application | ||
FROM python:{{cookiecutter.python_version}}-slim-bookworm | ||
|
||
LABEL author="{{cookiecutter.full_name}}" | ||
# Build the project in release mode | ||
RUN cargo build --release | ||
|
||
ENV PATH="/app/.venv/bin:$PATH" \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
# Stage 2: Create a minimal image using distroless for running the app | ||
FROM gcr.io/distroless/cc-debian12 | ||
|
||
# Create app directory | ||
WORKDIR /app | ||
|
||
# Copy the virtual environment and application code | ||
COPY --from=builder /app/.venv /app/.venv | ||
COPY src ./src | ||
# Copy the built executable from the builder stage | ||
COPY --from=builder /app/target/release/{{ cookiecutter.project_slug }} /app/ | ||
|
||
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)" | ||
# Expose the port (for example, 8080) | ||
EXPOSE 8080 | ||
|
||
CMD ["python", "src/{{cookiecutter.package_name}}/app.py"] | ||
# Run the binary | ||
CMD ["./{{ cookiecutter.project_slug }}"] |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pub fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
8 changes: 0 additions & 8 deletions
8
template/rs/{{cookiecutter.project_slug}}/src/{{cookiecutter.package_name}}/__init__.py
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
template/rs/{{cookiecutter.project_slug}}/src/{{cookiecutter.package_name}}/app.py
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
template/rs/{{cookiecutter.project_slug}}/src/{{cookiecutter.package_name}}/example.py
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
template/rs/{{cookiecutter.project_slug}}/tests/test_example.py
This file was deleted.
Oops, something went wrong.