Skip to content

Instantly share code, notes, and snippets.

@derkweijers
Last active May 9, 2024 07:56
Show Gist options
  • Save derkweijers/30f67f6d0dfd180d99942dc5a00dea7e to your computer and use it in GitHub Desktop.
Save derkweijers/30f67f6d0dfd180d99942dc5a00dea7e to your computer and use it in GitHub Desktop.
FROM gcr.io/distroless/java17
COPY target/mvn-distroless-0.1.jar /opt/app/mvn-distroless-0.1.jar
WORKDIR /opt/app
CMD ["mvn-distroless-0.1.jar"]
FROM eclipse-temurin:17
RUN mkdir /opt/app
COPY target/mvn-fat-0.1.jar /opt/app/mvn-fat-0.1.jar
CMD ["java", "-jar", "/opt/app/mvn-fat-0.1.jar"]
# Stage 1: Build and install dependencies
FROM python:3.11-slim as builder
# Set a working directory
WORKDIR /app
# Copy pyproject.toml and optionally poetry.lock files
COPY pyproject.toml poetry.lock* /app/
# Install Poetry
RUN pip install poetry
# Configure poetry: This avoids creating virtual environments inside the Docker container
RUN poetry config virtualenvs.create false
# Install dependencies using poetry
RUN poetry install --no-dev
# Copy your application files into the Docker image
COPY demotje_python/ /app/demotje_python/
# Stage 2: Build the distroless image
FROM gcr.io/distroless/python3-debian12
# Copy the installed Python packages and application files from the builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /app /app
# Set the working directory in the distroless image
WORKDIR /app
# Set the Python path environment variable
ENV PYTHONPATH=/usr/local/lib/python3.11/site-packages
# Set the command to run your application
ENTRYPOINT ["python", "demotje_python/main.py"]
FROM python:3.11-slim
WORKDIR /app
# Install Poetry
RUN pip install poetry
# Set the location of the virtual environment
RUN poetry config virtualenvs.in-project true
# Copy the poetry files
COPY pyproject.toml poetry.lock ./
RUN poetry install
# Update the PATH to include the virtual environment
ENV PATH="/app/.venv/bin:$PATH"
# Copy the application code
COPY demotje_python ./demotje_python
# Run the application
CMD ["python", "demotje_python/main.py"]
FROM rust:1.77 as build
WORKDIR /usr/src/demotje
COPY . .
RUN cargo build --release
# Now copy it into our base image.
FROM gcr.io/distroless/cc-debian12
COPY --from=build /usr/src/demotje/target/release/demotje /usr/local/bin/demotje
CMD ["demotje"]
FROM rust:1.77
WORKDIR /usr/src/demotje
COPY . .
RUN cargo install --path .
CMD ["demotje"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment