[skip ci]Refactoring in Docker image building, see also section dockerizing in doc/dev_notes.md to handle one Dockerfile for different builds

This commit is contained in:
Mirco 2024-07-11 21:35:08 +02:00
parent 38edbbfb94
commit ae34bec4df
2 changed files with 62 additions and 43 deletions

View file

@ -1,24 +1,39 @@
#Build Stage
#if npm is needed for development purposes, switch to node
#FROM node:22-bookworm-slim as build-env
FROM ubuntu:latest as build-env
#buildJar-stage
FROM openjdk:22-jdk-slim as build-jar-stage
RUN \
--mount=type=cache,target=/var/cache/apt \
apt-get update && apt-get -qqy upgrade &&\
apt-get -qqy install git &&\
git clone --single-branch --branch main https://repo.prod.meissa.de/meissa/ModeratorElection.git /usr/local/src/ModeratorElection
WORKDIR /usr/local/src/ModeratorElection/
RUN ./gradlew build -Pvaadin.productionMode
# Run jar stage
FROM build-jar-stage AS run-jar-stage
EXPOSE 8080
WORKDIR /usr/local/src/ModeratorElection/build/libs/
RUN chmod 0740 ./ModeratorElection.jar
ENTRYPOINT ["java", "-jar", "./ModeratorElection.jar"]
#build-native-stage
FROM ubuntu:latest as build-native-stage
ADD resources /tmp
RUN /tmp/install.sh
RUN \
--mount=type=cache,target=/var/cache/apt \
/tmp/install.sh
ENV LANG=en_US.UTF-8 \
JAVA_HOME=/usr/lib/jvm/graalvm
JAVA_HOME=/usr/lib/jvm/graalvm/bin
# Run stage
FROM ubuntu:latest
RUN apt-get update
RUN apt-get -qqy upgrade
# Run native binary stage
FROM build-native-stage AS run-native-stage
EXPOSE 8080
CMD ["mkdir /usr/local/src/ModeratorElection"]
WORKDIR /usr/local/src/ModeratorElection/
#copy graalvm binary
COPY --from=build-env /usr/local/src/ModeratorElection/build/native/nativeCompile/ /usr/local/src/ModeratorElection/
#CMD ["mkdir /usr/local/src/ModeratorElection"]
WORKDIR /usr/local/src/ModeratorElection/build/native/nativeCompile/
##copy native binary
#COPY --from=buildNative-stage /usr/local/src/ModeratorElection/build/native/nativeCompile/ .
RUN chmod 0740 ./ModeratorElection
ENTRYPOINT ["./ModeratorElection"]

View file

@ -4,10 +4,9 @@ set -exo pipefail
function main()
{
upgradeSystem
#unzpip only necessary for gradle installation within main()
#upgradeSystem
apt-get update && apt-get -qqy upgrade
apt-get -qqy install curl git build-essential libz-dev zlib1g-dev
mkdir /usr/local/src/ModeratorElection
#change to main branch for production
#change to MEapp-development branch for development
@ -21,8 +20,8 @@ function main()
#download graalvm
#graalvm-community-jdk, v22.0.1 2024-04-16
graalvm_jdk_version="22.0.1"
curl -SsLo /tmp/graalvm-community-jdk.tar.gz https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-${graalvm_jdk_version}/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz
curl -SsLo /tmp/graalvm-checksum https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-${graalvm_jdk_version}/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz.sha256
curl -SsLo /tmp/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-22.0.1/graalvm-community-jdk-22.0.1_linux-x64_bin.tar.gz
curl -SsLo /tmp/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz.sha256 https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-${graalvm_jdk_version}/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz.sha256
#checksum graalvm
checksum
@ -33,40 +32,45 @@ function main()
#nativeCompile
buildproc
cleanupDocker
#cleanupDocker
rm -f /root/.ssh/authorized_keys
rm -f /root/.ssh/authorized_keys2
apt-get clean
apt-get -qqy autoremove --purge
apt-get -qqy autoclean
rm -rf /var/lib/apt/lists/
rm -rf /tmp/*
find /var/cache -type f -exec rm -rf {} \;
find /var/log/ -name '*.log' -exec rm -f {} \;
} > /dev/null
function checksum() {
#graalvm
echo " /tmp/graalvm-jdk-${graalvm_JDK_version}_linux-x64_bin.tar.gz"|tee -a /tmp/graalvm-jdk-${graalvm_JDK_version}_linux-x64_bin.tar.gz.sha256
sha256sum -c --status /tmp/graalvm-jdk-${graalvm_JDK_version}_linux-x64_bin.tar.gz.sha256
echo " /tmp/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz"|tee -a /tmp/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz.sha256
sha256sum -c --status /tmp/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz.sha256
}
function graalvm_inst(){
mkdir /usr/lib/jvm/
tar -C /usr/lib/jvm/ -xzf /tmp/graalvm-jdk-${graalvm_JDK_version}_linux-x64_bin.tar.gz
tar -C /usr/lib/jvm/ -xzf /tmp/graalvm-community-jdk-${graalvm_jdk_version}_linux-x64_bin.tar.gz
dirname_graalvm=$(ls /usr/lib/jvm/|grep -e graa)
ln -s /usr/lib/jvm/$dirname_graalvm /usr/lib/jvm/graalvm
ln -s /usr/lib/jvm/graalvm/bin/gu /usr/local/bin
mkdir /usr/lib/jvm/graalvm/
ln -s /usr/lib/jvm/$dirname_graalvm/bin/ /usr/lib/jvm/graalvm/
update-alternatives --install /usr/bin/java java /usr/lib/jvm/graalvm/bin/java 0
echo "export PATH=$PATH:/usr/lib/jvm/graalvm/bin"| tee -a ~/.bashrc
}
function buildproc() {
cd /usr/local/src/ModeratorElection/
#for dev
#npm install -g npm@latest
#npm audit fix
#npm ci --omit=dev
#build jar
#./gradlew clean build -Pvaadin.productionMode -x processTestAot
#cp -r doc/META-INF src/main/resources
#build graalvm binary
./gradlew nativeCompile -Dvaadin.productionMode=true
./gradlew nativeCompile -Dvaadin.productionMode=true -x processTestAot
}
source /tmp/install_functions_debian.sh
#source /tmp/install_functions_debian.sh
DEBIAN_FRONTEND=noninteractive DEBCONF_NOWARNINGS=yes main