Refactor Dockerfile to use multi-stage builds for PISCAL, separating build and runtime stages.
This commit is contained in:
+59
-38
@@ -1,56 +1,77 @@
|
|||||||
#Download base image
|
# Multi-stage Dockerfile for PISCAL
|
||||||
FROM ubuntu:latest
|
# Stage 1: Build stage - Compile PISCAL executable from Fortran sources
|
||||||
|
FROM ubuntu:latest AS builder
|
||||||
|
|
||||||
# Install and update software
|
# Install build dependencies
|
||||||
RUN set -xe \
|
RUN set -xe \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get upgrade -y \
|
&& apt-get install --no-install-recommends -y \
|
||||||
# SSHD install
|
make \
|
||||||
&& apt-get install --no-install-recommends -y openssh-server sudo \
|
xutils-dev \
|
||||||
# Piscal reqs
|
gfortran \
|
||||||
&& apt-get install make -y \
|
|
||||||
&& apt-get install xutils-dev -y \
|
|
||||||
&& apt-get install gfortran -y \
|
|
||||||
&& apt-get install libopenmpi-dev -y \
|
|
||||||
# utils
|
|
||||||
&& apt-get install iproute2 -y \
|
|
||||||
&& apt-get install vim -y \
|
|
||||||
# cleanup
|
|
||||||
&& apt-get autoclean -y \
|
&& apt-get autoclean -y \
|
||||||
&& apt-get autoremove -y
|
&& apt-get autoremove -y
|
||||||
|
|
||||||
# configure sshd, copied from wataken44/ubuntu-latest-sshd
|
# Copy source files from multiple directories
|
||||||
|
COPY leafres/testarea/ /build/leafres/testarea/
|
||||||
|
COPY dataassim/math/optimization/ /build/dataassim/math/optimization/
|
||||||
|
COPY dataassim/math/othersupmath/ /build/dataassim/math/othersupmath/
|
||||||
|
COPY dataassim/math/algebra/ /build/dataassim/math/algebra/
|
||||||
|
COPY dataassim/math/specialfuncs/ /build/dataassim/math/specialfuncs/
|
||||||
|
COPY dataassim/math/nonlinsystems/ /build/dataassim/math/nonlinsystems/
|
||||||
|
COPY leafres/testrun/Makefile /build/leafres/testrun/Makefile
|
||||||
|
|
||||||
|
# Build the executable
|
||||||
|
WORKDIR /build/leafres/testrun
|
||||||
|
RUN make clean || true
|
||||||
|
RUN make
|
||||||
|
|
||||||
|
# Stage 2: Runtime stage - Create minimal application container
|
||||||
|
FROM ubuntu:latest
|
||||||
|
|
||||||
|
# Install runtime dependencies only
|
||||||
RUN set -xe \
|
RUN set -xe \
|
||||||
&& groupadd launcher \
|
&& apt-get update \
|
||||||
&& useradd -g launcher -G sudo -m -s /bin/bash launcher \
|
&& apt-get upgrade -y \
|
||||||
&& echo 'launcher:launcher' | chpasswd
|
&& apt-get install --no-install-recommends -y \
|
||||||
|
openssh-server \
|
||||||
|
sudo \
|
||||||
|
iproute2 \
|
||||||
|
vim \
|
||||||
|
libgfortran5 \
|
||||||
|
&& apt-get autoclean -y \
|
||||||
|
&& apt-get autoremove -y
|
||||||
|
|
||||||
|
# Configure SSH server
|
||||||
|
RUN set -xe \
|
||||||
|
&& groupadd launcher \
|
||||||
|
&& useradd -g launcher -G sudo -m -s /bin/bash launcher \
|
||||||
|
&& echo 'launcher:launcher' | chpasswd
|
||||||
|
|
||||||
RUN set -xe \
|
RUN set -xe \
|
||||||
&& sed -i -e 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config \
|
&& sed -i -e 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config \
|
||||||
&& sed -i -e 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config \
|
&& sed -i -e 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config \
|
||||||
&& sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
|
&& sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
|
||||||
|
|
||||||
RUN set -xe \
|
RUN set -xe \
|
||||||
&& chown -R launcher:launcher /home/launcher
|
&& chown -R launcher:launcher /home/launcher
|
||||||
|
|
||||||
# fix for SSHD - "Missing privilege separation directory: /run/sshd"
|
# Fix for SSHD - "Missing privilege separation directory: /run/sshd"
|
||||||
RUN set -xe \
|
RUN set -xe \
|
||||||
&& mkdir /run/sshd
|
&& mkdir /run/sshd
|
||||||
|
|
||||||
##### add user l2g
|
# Copy compiled executable from builder stage
|
||||||
# RUN set -xe \
|
COPY --from=builder /build/leafres/testrun/piscal /srv/piscal
|
||||||
# && groupadd l2g \
|
|
||||||
# && useradd -g l2g -G sudo -m -s /bin/bash l2g \
|
# Copy piscal-manager scripts
|
||||||
# && echo 'l2g:pwdpwd' | chpasswd
|
COPY piscal-manager /srv
|
||||||
# RUN set -xe \
|
|
||||||
# && chown -R l2g:l2g /home/l2g
|
# Fix Windows line endings (CRLF -> LF) for scripts and config files, and make scripts executable
|
||||||
# RUN set -xe \
|
RUN set -xe \
|
||||||
# && apt-get install nano
|
&& find /srv -name "*.sh" -type f -exec sed -i 's/\r$//' {} \; \
|
||||||
#####
|
&& find /srv -name "*.cfg" -type f -exec sed -i 's/\r$//' {} \; \
|
||||||
|
&& chmod +x /srv/*.sh || true
|
||||||
|
|
||||||
ADD piscal-manager /srv
|
|
||||||
ADD leafres/testrun/piscal /srv
|
|
||||||
#RUN chmod R +x /srv/*.sh
|
|
||||||
WORKDIR /srv
|
WORKDIR /srv
|
||||||
|
|
||||||
EXPOSE 22
|
EXPOSE 22
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
piscal_executable="/home/piscaladmin/piscal_executable/piscal"
|
piscal_executable="/srv/piscal"
|
||||||
storage_directory="/home/piscaladmin/LeafWeb_storage"
|
storage_directory="/home/piscaladmin/LeafWeb_storage"
|
||||||
|
|||||||
Reference in New Issue
Block a user