-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install python packages for docker image into venv envirounment
- Loading branch information
Showing
1 changed file
with
22 additions
and
10 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 |
---|---|---|
@@ -1,45 +1,57 @@ | ||
# Stage 1: Build the Java application JAR | ||
FROM maven:3-eclipse-temurin-21 as jar_builder | ||
|
||
# Set the working directory in the Maven image | ||
WORKDIR /app | ||
|
||
# Copy the java source files and the pom.xml file into the image | ||
# Copy the Java source files and the pom.xml file into the image | ||
COPY src ./src | ||
COPY pom.xml . | ||
|
||
# Build the application | ||
RUN mvn clean package -DskipTests | ||
|
||
# Stage 2: Prepare the final image | ||
FROM maven:3-eclipse-temurin-21 | ||
|
||
# download system dependencies first to take advantage of docker caching | ||
RUN apt-get update; apt-get install -y --no-install-recommends \ | ||
# Download system dependencies first to take advantage of Docker caching | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
default-mysql-client \ | ||
default-libmysqlclient-dev \ | ||
python3 \ | ||
python3-setuptools \ | ||
python3-venv \ | ||
python3-dev \ | ||
python3-pip \ | ||
unzip \ | ||
perl \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& pip3 install wheel | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Install any needed packages specified in requirements.txt | ||
# Set up a Python virtual environment | ||
RUN python3 -m venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
|
||
# Install Python packages in the virtual environment | ||
COPY requirements.txt ./ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
RUN ln -s $(which python3) /usr/local/bin/python || true | ||
# Link python3 to python for compatibility | ||
RUN ln -s /opt/venv/bin/python /usr/local/bin/python || true | ||
|
||
# Copy the built JAR from the first stage | ||
COPY --from=jar_builder /app/core-*.jar / | ||
|
||
# Copy and set permissions for scripts | ||
COPY scripts/ scripts/ | ||
RUN chmod -R a+x /scripts/ | ||
|
||
# Set the working directory in the container | ||
WORKDIR /scripts/ | ||
|
||
# Environment variable | ||
ENV PORTAL_HOME=/ | ||
|
||
# This file is empty. It has to be overriden by bind mounting the actual application.properties | ||
# Create an empty application.properties file | ||
RUN touch /application.properties | ||
|
||
# Entry command | ||
CMD ["python", "your_script.py"] |