Skip to content

Commit

Permalink
Install python packages for docker image into venv envirounment
Browse files Browse the repository at this point in the history
  • Loading branch information
forus committed Nov 1, 2024
1 parent 3e8e2a7 commit e4ea9c9
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Dockerfile
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"]

0 comments on commit e4ea9c9

Please sign in to comment.