From 1fdfa02a889016f2f9bf05076e82a2655e56c5b8 Mon Sep 17 00:00:00 2001
From: Lennart Kramer <lennart.kramer@stud.uni-goettingen.de>
Date: Fri, 10 Jul 2020 18:45:55 +0200
Subject: [PATCH] Slightly reduce Dockerfile

---
 .gitlab-ci.yml |  2 ++
 Dockerfile     | 23 +++++++----------------
 buildimage.sh  |  2 +-
 src/web/web.go |  2 +-
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fe25e61..1d83627 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -29,6 +29,8 @@ build_webservice:
   stage: build_webservice
   tags:
     - docker
+  before_script:
+    - docker login -u mathinstitut -p "$DOCKERHUB_PASS"
   script:
     - ./build.sh "$REGISTRY" "$CI_COMMIT_TAG"
 
diff --git a/Dockerfile b/Dockerfile
index 6a8321e..235aa1c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,9 +5,6 @@ ARG MAXIMA_VERSION
 # e.g. 2.0.22.0.2
 ARG SBCL_VERSION
 
-RUN echo ${MAXIMA_VERSION?Error \$MAXIMA_VERSION is not defined} \
-	 ${SBCL_VERSION?Error \$SBCL_VERSION is not defined}
-
 ENV SRC=/opt/src \
     LIB=/opt/maxima/lib \
     LOG=/opt/maxima/log \
@@ -15,6 +12,9 @@ ENV SRC=/opt/src \
     PLOT=/opt/maxima/plot \
     ASSETS=/opt/maxima/assets \
     BIN=/opt/maxima/bin
+
+RUN echo ${MAXIMA_VERSION?Error \$MAXIMA_VERSION is not defined} \
+	 ${SBCL_VERSION?Error \$SBCL_VERSION is not defined}
   
 RUN SBCL_ARCH=$(dpkg --print-architecture); if [ $SBCL_ARCH = amd64 ]; then SBCL_ARCH=x86-64; fi; echo $SBCL_ARCH > /SBCL_ARCH
 
@@ -26,8 +26,6 @@ RUN apt-get update \
     wget \
     python3 \
     gcc \
-#    ca-certificates \
-#    curl \
     texinfo
 
 RUN mkdir -p ${SRC}
@@ -59,11 +57,8 @@ RUN apt-get install -y gnuplot gettext-base sudo psmisc libbsd-dev tini
 COPY ./src/maxima_fork.c ${SRC}
 
 RUN cd ${SRC} && gcc -shared maxima_fork.c -lbsd -fPIC -Wall -Wextra -o libmaximafork.so \
-    && mv libmaximafork.so /usr/lib
-
-RUN rm -r ${SRC} /SBCL_ARCH
-
-RUN mkdir -p ${LIB} ${LOG} ${TMP} ${PLOT} ${ASSETS} ${BIN}
+    && mv libmaximafork.so /usr/lib \
+    && rm -r ${SRC} /SBCL_ARCH && mkdir -p ${LIB} ${LOG} ${TMP} ${PLOT} ${ASSETS} ${BIN}
 
 
 # e.g. assStackQuestion/classes/stack/maxima
@@ -82,11 +77,8 @@ RUN grep stackmaximaversion ${LIB}/stackmaxima.mac | grep -oP "\d+" >> /opt/maxi
     && cat ${ASSETS}/maximalocal.mac && cat ${ASSETS}/optimize.mac \
     && cd ${ASSETS} \
     && maxima -b optimize.mac \
-    && mv maxima-optimised ${BIN}/maxima-optimised
-
-RUN apt-get purge -y wget python3 make bzip2 texinfo gcc
-
-RUN for i in $(seq 16); do \
+    && mv maxima-optimised ${BIN}/maxima-optimised \
+    && for i in $(seq 16); do \
            useradd -M "maxima-$i"; \
     done
 
@@ -97,4 +89,3 @@ ARG MAX_LIB_PATH=''
 ENV GOEMAXIMA_LIB_PATH=$MAX_LIB_PATH
 
 CMD rm /dev/tty && cd /tmp && rm --one-file-system -rf * && exec tini ${BIN}/goweb ${BIN}/maxima-optimised
-
diff --git a/buildimage.sh b/buildimage.sh
index a602072..36a8eb5 100755
--- a/buildimage.sh
+++ b/buildimage.sh
@@ -11,6 +11,7 @@ echo "sbcl: $1"
 echo "maxima: $2"
 echo "stack: $3"
 IMAGENAME="goemaxima:$3"
+docker pull "$5/$IMAGENAME-dev"
 # build it
 if [ "$3" = "2017121800" ]; then
 	docker build -t "${IMAGENAME}" --build-arg MAXIMA_VERSION="$2" --build-arg SBCL_VERSION="$1" --build-arg LIB_PATH="$4" --build-arg "MAX_LIB_PATH=/opt/maxima/assets/maximalocal.mac" . || exit 1
@@ -19,7 +20,6 @@ else
 fi
 echo "${IMAGENAME} wurde erfolgreich gebaut."
 # push the image
-docker login -u mathinstitut -p "$DOCKERHUB_PASS"
 docker tag "$IMAGENAME" "$5/$IMAGENAME-dev"
 docker push "$5/$IMAGENAME-dev"
 if [ -n "$6" ]; then
diff --git a/src/web/web.go b/src/web/web.go
index dd0a7ec..2151cec 100644
--- a/src/web/web.go
+++ b/src/web/web.go
@@ -239,7 +239,7 @@ func process_cleanup(user *User, user_queue chan<- *User, tmp_dir string) {
 func handler(w http.ResponseWriter, r *http.Request, queue <-chan *ChildProcess, user_queue chan<- *User, metrics *Metrics) {
 	if r.Method == "GET" && r.FormValue("input") == "" {
 		hostname, _ := os.Hostname()
-		fmt.Fprintf(w, "Hostname: %s, version: 1.0.0\n", hostname)
+		fmt.Fprintf(w, "Hostname: %s, version: 1.0.1\n", hostname)
 		return
 	}
 	// the maxima input to be evaluated
-- 
GitLab