From fa4aa9dae03c04aab71dbf1fe65fcbef5e32e8d4 Mon Sep 17 00:00:00 2001 From: sbts Date: Sat, 8 Jul 2017 01:57:43 +0800 Subject: [PATCH 1/8] stop setting debian frontend it's against docker best practice --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e75cc8b..efb131a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,7 @@ RUN echo -n "APT::Install-Recommends \"0\";\nAPT::Install-Suggests \"0\";\n" >> # Install Perl, Tex, Starman, psql client, and all dependencies -RUN DEBIAN_FRONTEND=noninteractive && \ - apt-get update && apt-get -y install \ +RUN apt-get update && apt-get -y install \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ libdatetime-format-strptime-perl libdigest-md5-perl \ @@ -31,7 +30,6 @@ RUN DEBIAN_FRONTEND=noninteractive && \ # Build time variables ENV LSMB_VERSION master ENV NODE_PATH /usr/local/lib/node_modules -ENV DEBIAN_FRONTEND=noninteractive ARG CACHEBUST From dbf99f981d421b0fcfc579d85d9c524e7ab571d1 Mon Sep 17 00:00:00 2001 From: sbts Date: Sat, 8 Jul 2017 03:36:27 +0800 Subject: [PATCH 2/8] improve apt handling to bring it inline with docker best practice --- Dockerfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index efb131a..713f879 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,9 @@ FROM debian:jessie MAINTAINER Freelock john@freelock.com -RUN echo -n "APT::Install-Recommends \"0\";\nAPT::Install-Suggests \"0\";\n" >> /etc/apt/apt.conf - - # Install Perl, Tex, Starman, psql client, and all dependencies -RUN apt-get update && apt-get -y install \ +RUN echo -n "APT::Install-Recommends \"0\";\nAPT::Install-Suggests \"0\";\n" >> /etc/apt/apt.conf && \ + apt-get update && apt-get -y install \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ libdatetime-format-strptime-perl libdigest-md5-perl \ @@ -24,7 +22,8 @@ RUN apt-get update && apt-get -y install \ libopenoffice-oodoc-perl \ postgresql-client \ ssmtp \ - lsb-release + lsb-release \ + && rm -rf /var/lib/apt/lists/* # Build time variables @@ -36,8 +35,10 @@ ARG CACHEBUST # Java & Nodejs for doing Dojo build # Uglify needs to be installed right before 'make dojo'?! -RUN apt-get -y install git make gcc libperl-dev npm curl && \ +RUN apt-get update && \ + apt-get -y install git make gcc libperl-dev npm curl && \ update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100 && \ + rm -rf /var/lib/apt/lists/* && \ cd /srv && \ git clone --recursive -b $LSMB_VERSION https://github.com/ledgersmb/LedgerSMB.git ledgersmb && \ cd ledgersmb && \ @@ -53,7 +54,8 @@ RUN apt-get -y install git make gcc libperl-dev npm curl && \ rm -rf /usr/local/lib/node_modules && \ apt-get autoremove -y && \ apt-get autoclean && \ - rm -rf ~/.cpanm + rm -rf ~/.cpanm && \ + rm -rf /var/lib/apt/lists/* # Configure outgoing mail to use host, other run time variable defaults From 364cf01203cbeecc51573d6ed7b9ffe4fa0ec588 Mon Sep 17 00:00:00 2001 From: sbts Date: Sun, 9 Jul 2017 14:07:33 +0800 Subject: [PATCH 3/8] remove stray script that was accidentally committed --- start-lsmb-and-postgres-containers.sh | 105 -------------------------- 1 file changed, 105 deletions(-) delete mode 100755 start-lsmb-and-postgres-containers.sh diff --git a/start-lsmb-and-postgres-containers.sh b/start-lsmb-and-postgres-containers.sh deleted file mode 100755 index ef2be9b..0000000 --- a/start-lsmb-and-postgres-containers.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash - -clear - -PGuser='postgres' -PGpass='password' - -PGcontainerName='lsmb-postgres' -LSMBcontainerName='myledger' - - -export POSTGRES_HOST='postgres' -export POSTGRES_PORT='5432' -export DEFAULT_DB='lsmb' - -CheckWhatIsRunning() { - isrunning_pg=false; - isrunning_lsmb=false; - while read -t10 line || { echo; false; } do - if [[ $line =~ $PGcontainerName ]]; then isrunning_pg=true; fi - if [[ $line =~ $LSMBcontainerName ]]; then isrunning_lsmb=true; fi - done < <( docker ps ) -} - -StartPostgres() { - if $isrunning_pg; then - echo "Postgres container $PGcontainerName is already running"; - else - echo "Starting Postgres container $PGcontainerName" - if docker inspect $PGcontainerName &>/dev/null; then # container exists so start it - docker start $PGcontainerName - else # container doesn't exist so run it - docker run --name $PGcontainerName -e POSTGRES_PASSWORD="$PGpass" -d postgres - fi - fi -} - -StartLedgerSMB() { - if $isrunning_lsmb; then - echo "LedgerSMB container $LSMBcontainerName is already running"; - else - echo "Starting LedgerSMB container $LSMBcontainerName" - if docker inspect $LSMBcontainerName &>/dev/null; then # container exists so start it - docker start $LSMBcontainerName >/dev/null - else # container doesn't exist so run it - docker run --name $LSMBcontainerName --link lsmb-postgres:postgres -d ledgersmb/ledgersmb - fi - fi -} - -GetIPs() { - containerIPlsmbPostgres=`docker inspect -f '{{ .NetworkSettings.IPAddress }}' lsmb-postgres` - containerIPlsmb=`docker inspect -f '{{ .NetworkSettings.IPAddress }}' myledger` -} - -PrintInfo() { - printf " %32s: IP %s\n" "$PGcontainerName" "$containerIPlsmbPostgres" - printf " %32s: IP %s\n" "$LSMBcontainerName" "$containerIPlsmb" - - echo -} - -TestLSMB() { # If any arg is passed then don't echo anything - if wget --tries=1 --timeout=2 -O /dev/null -q http://$containerIPlsmb:5762/setup.pl; then - [[ -z $1 ]] && echo "LSMB server accessible" - return 0 - else - [[ -z $1 ]] && echo "Failed to connect to LSMB server" - return 1 - fi -} - -timestamp() { - date "+%s" -} - -WaitForContainers() { - timer=60 - read -st10 timeoutAt < <( timestamp ) - (( timeoutAt = timeoutAt + timer )) - (( now = `timestamp` )) - (( lasttimestamp = now )) - echo - echo "wait at least $timer seconds for containers to start" - echo -en "\r$(( timeoutAt - now )) " - while { now=`timestamp`; (( now < timeoutAt )); } do - echo -en "\r$(( timeoutAt - now )) " - if (( now <= lasttimestamp )); then continue; fi - (( lasttimestamp = now )) - if [[ -z $containerIPlsmb ]]; then GetIPs &>/dev/null; fi - echo -en "\r$(( timeoutAt - now )) " - TestLSMB -s - if (( $? == 0 )); then echo; break; fi - echo -en "\r$(( timeoutAt - now )) " - done - echo -} - -CheckWhatIsRunning -StartPostgres -StartLedgerSMB -WaitForContainers -TestLSMB - -PrintInfo From 98a5696570e55f7060406be25243e715e55220b4 Mon Sep 17 00:00:00 2001 From: sbts Date: Sun, 9 Jul 2017 15:29:20 +0800 Subject: [PATCH 4/8] Paramaterise dojo build dep packages - Readd DEBIAN_FRONTEND=interactive. - Paramaterise dojo build dep packages --- Dockerfile | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 713f879..084a7a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM debian:jessie MAINTAINER Freelock john@freelock.com # Install Perl, Tex, Starman, psql client, and all dependencies -RUN echo -n "APT::Install-Recommends \"0\";\nAPT::Install-Suggests \"0\";\n" >> /etc/apt/apt.conf && \ - apt-get update && apt-get -y install \ +RUN echo -e "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\";\n" > /etc/apt/apt.conf && \ + apt-get update DEBIAN_FRONTEND="noninteractive" apt-get -y install && \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ libdatetime-format-strptime-perl libdigest-md5-perl \ @@ -23,6 +23,8 @@ RUN echo -n "APT::Install-Recommends \"0\";\nAPT::Install-Suggests \"0\";\n" >> postgresql-client \ ssmtp \ lsb-release \ + && apt-get autoremove -y \ + && apt-get autoclean \ && rm -rf /var/lib/apt/lists/* @@ -33,12 +35,18 @@ ENV NODE_PATH /usr/local/lib/node_modules ARG CACHEBUST +########################################################### # Java & Nodejs for doing Dojo build # Uglify needs to be installed right before 'make dojo'?! + +# These packages are only needed during the dojo build +ENV DOJO_Build_Deps git make gcc libperl-dev npm curl +# These packages can be removed after the dojo build +ENV DOJO_Build_Deps_removal ${DOJO_Build_Deps} nodejs + RUN apt-get update && \ - apt-get -y install git make gcc libperl-dev npm curl && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y install ${DOJO_Build_Deps} && \ update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100 && \ - rm -rf /var/lib/apt/lists/* && \ cd /srv && \ git clone --recursive -b $LSMB_VERSION https://github.com/ledgersmb/LedgerSMB.git ledgersmb && \ cd ledgersmb && \ @@ -50,13 +58,14 @@ RUN apt-get update && \ --installdeps . && \ npm install -g uglify-js@">=2.0 <3.0" && \ make dojo && \ - apt-get purge -y npm git make gcc libperl-dev nodejs curl && \ + apt-get purge -y ${DOJO_Build_Deps_removal} && \ rm -rf /usr/local/lib/node_modules && \ apt-get autoremove -y && \ apt-get autoclean && \ rm -rf ~/.cpanm && \ rm -rf /var/lib/apt/lists/* +ENV DOJO_Build_Deps # Configure outgoing mail to use host, other run time variable defaults ## sSMTP From fafaea715e65a31d8fe7dd0f8405a8996475600e Mon Sep 17 00:00:00 2001 From: sbts Date: Sun, 9 Jul 2017 16:43:53 +0800 Subject: [PATCH 5/8] Make sure DEBIAN_FRONTEND is set for all apt-get commands Do that by parameterising the apt-get --- Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a9becb..2f6ab01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,12 @@ FROM debian:jessie MAINTAINER Freelock john@freelock.com +ENV APT_cmd DEBIAN_FRONTEND="noninteractive" apt-get -y + # Install Perl, Tex, Starman, psql client, and all dependencies RUN echo -e "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\";\n" > /etc/apt/apt.conf.d/00recommends && \ - apt-get update DEBIAN_FRONTEND="noninteractive" apt-get -y install && \ + ${APT_cmd} update && \ + ${APT_cmd} install && \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ libdatetime-format-strptime-perl libdigest-md5-perl \ @@ -23,8 +26,8 @@ RUN echo -e "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\" postgresql-client \ ssmtp \ lsb-release \ - && apt-get autoremove -y \ - && apt-get autoclean \ + && ${APT_cmd} autoremove \ + && ${APT_cmd} autoclean \ && rm -rf /var/lib/apt/lists/* @@ -44,8 +47,8 @@ ENV DOJO_Build_Deps git make gcc libperl-dev npm curl # These packages can be removed after the dojo build ENV DOJO_Build_Deps_removal ${DOJO_Build_Deps} nodejs -RUN apt-get update && \ - DEBIAN_FRONTEND="noninteractive" apt-get -y install ${DOJO_Build_Deps} && \ +RUN ${APT_cmd} update && \ + ${APT_cmd} install ${DOJO_Build_Deps} && \ update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100 && \ cd /srv && \ git clone --recursive -b $LSMB_VERSION https://github.com/ledgersmb/LedgerSMB.git ledgersmb && \ @@ -58,10 +61,10 @@ RUN apt-get update && \ --installdeps . && \ npm install -g uglify-js@">=2.0 <3.0" && \ make dojo && \ - apt-get purge -y ${DOJO_Build_Deps_removal} && \ + ${APT_cmd} purge ${DOJO_Build_Deps_removal} && \ rm -rf /usr/local/lib/node_modules && \ - apt-get autoremove -y && \ - apt-get autoclean && \ + ${APT_cmd} autoremove && \ + ${APT_cmd} autoclean && \ rm -rf ~/.cpanm && \ rm -rf /var/lib/apt/lists/* @@ -96,4 +99,5 @@ RUN mkdir -p /tmp && \ # Internal Port Expose EXPOSE 5762 +USER www-data CMD ["start.sh"] From 4dbd5a2a26c22f5e2606c42abd468939fedd1fa5 Mon Sep 17 00:00:00 2001 From: sbts Date: Sun, 9 Jul 2017 18:24:01 +0800 Subject: [PATCH 6/8] revert to explicit setting of DEBIAN_FRONTEND. Nothing else works correctly. Presumably as dash is the processing shell --- Dockerfile | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2f6ab01..14e329c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,10 @@ FROM debian:jessie MAINTAINER Freelock john@freelock.com -ENV APT_cmd DEBIAN_FRONTEND="noninteractive" apt-get -y - # Install Perl, Tex, Starman, psql client, and all dependencies -RUN echo -e "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\";\n" > /etc/apt/apt.conf.d/00recommends && \ - ${APT_cmd} update && \ - ${APT_cmd} install && \ +RUN echo "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\";" > /etc/apt/apt.conf.d/00recommends && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y update && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y install && \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ libdatetime-format-strptime-perl libdigest-md5-perl \ @@ -26,8 +24,8 @@ RUN echo -e "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\" postgresql-client \ ssmtp \ lsb-release \ - && ${APT_cmd} autoremove \ - && ${APT_cmd} autoclean \ + && DEBIAN_FRONTEND="noninteractive" apt-get -y autoremove \ + && DEBIAN_FRONTEND="noninteractive" apt-get -y autoclean \ && rm -rf /var/lib/apt/lists/* @@ -47,8 +45,8 @@ ENV DOJO_Build_Deps git make gcc libperl-dev npm curl # These packages can be removed after the dojo build ENV DOJO_Build_Deps_removal ${DOJO_Build_Deps} nodejs -RUN ${APT_cmd} update && \ - ${APT_cmd} install ${DOJO_Build_Deps} && \ +RUN DEBIAN_FRONTEND="noninteractive" apt-get -y update && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y install ${DOJO_Build_Deps} && \ update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100 && \ cd /srv && \ git clone --recursive -b $LSMB_VERSION https://github.com/ledgersmb/LedgerSMB.git ledgersmb && \ @@ -61,14 +59,18 @@ RUN ${APT_cmd} update && \ --installdeps . && \ npm install -g uglify-js@">=2.0 <3.0" && \ make dojo && \ - ${APT_cmd} purge ${DOJO_Build_Deps_removal} && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y purge ${DOJO_Build_Deps_removal} && \ rm -rf /usr/local/lib/node_modules && \ - ${APT_cmd} autoremove && \ - ${APT_cmd} autoclean && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y autoremove && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y autoclean && \ rm -rf ~/.cpanm && \ rm -rf /var/lib/apt/lists/* -ENV DOJO_Build_Deps +# Cleanup args that are for internal use +ENV DOJO_Build_Deps= +ENV DOJO_Build_Deps_removal= +ENV NODE_PATH= + # Configure outgoing mail to use host, other run time variable defaults ## sSMTP From e0338aa303b4b73ad311b16707408903c85d2b9e Mon Sep 17 00:00:00 2001 From: sbts Date: Sun, 9 Jul 2017 18:32:33 +0800 Subject: [PATCH 7/8] remove spurious && from `apt-get install` --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 14e329c..5400e0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER Freelock john@freelock.com # Install Perl, Tex, Starman, psql client, and all dependencies RUN echo "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\";" > /etc/apt/apt.conf.d/00recommends && \ DEBIAN_FRONTEND="noninteractive" apt-get -y update && \ - DEBIAN_FRONTEND="noninteractive" apt-get -y install && \ + DEBIAN_FRONTEND="noninteractive" apt-get -y install \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ libdatetime-format-strptime-perl libdigest-md5-perl \ From c7da8194cbb890ba0c1b84559bff535b0a0bfd37 Mon Sep 17 00:00:00 2001 From: sbts Date: Sun, 9 Jul 2017 18:48:59 +0800 Subject: [PATCH 8/8] remove `ARG CACHEBUST` as it does not do anything unless CACHEBUST is actually used. Which it is not --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5400e0d..1f07544 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,8 +33,6 @@ RUN echo "APT::Install-Recommends \"false\";\nAPT::Install-Suggests \"false\";" ENV LSMB_VERSION master ENV NODE_PATH /usr/local/lib/node_modules -ARG CACHEBUST - ########################################################### # Java & Nodejs for doing Dojo build