From 5366e0c0d753bafb4c81910f2bc0cb1a1dabf32b Mon Sep 17 00:00:00 2001 From: Yves Lavoie Date: Wed, 23 Aug 2017 21:58:36 -0400 Subject: [PATCH] Bring closer to master-dev-trusty --- .gitignore | 16 ++++++ Dockerfile | 120 +++++++++++++++++++++++++++++++-------------- README.md | 62 +++++++++++++++++++++++ docker-compose.yml | 62 +++++++++++++++++++++++ start.sh | 32 +++++++----- update_ssmtp.sh | 2 +- 6 files changed, 245 insertions(+), 49 deletions(-) create mode 100644 .gitignore mode change 100755 => 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7898840 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# .gitignore for LedgerSMB-Docker +# +# Vim swap files +*.swp +# +# LedgerSMB rebuild flag file +ledgersmb.rebuild + +# /bin/custom/ +/bin/custom/* + +# test output: +/screens/* + +# Patches +/patch/* diff --git a/Dockerfile b/Dockerfile old mode 100755 new mode 100644 index deeb4eb..21ca969 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,14 @@ -FROM debian:jessie +FROM ubuntu:xenial MAINTAINER Freelock john@freelock.com RUN echo -n "APT::Install-Recommends \"0\";\nAPT::Install-Suggests \"0\";\n" >> /etc/apt/apt.conf +RUN apt-get update && \ + apt-get -y install software-properties-common wget && \ + add-apt-repository ppa:ledgersmb/main # Install Perl, Tex, Starman, psql client, and all dependencies -RUN DEBIAN_FRONTENT=noninteractive && \ +RUN DEBIAN_FRONTEND=noninteractive && \ apt-get update && apt-get -y install \ libcgi-emulate-psgi-perl libcgi-simple-perl libconfig-inifiles-perl \ libdbd-pg-perl libdbi-perl libdatetime-perl \ @@ -21,42 +24,25 @@ RUN DEBIAN_FRONTENT=noninteractive && \ libmoosex-nonmoose-perl \ texlive-latex-recommended \ texlive-xetex \ - curl \ + starman \ libopenoffice-oodoc-perl \ postgresql-client libtap-parser-sourcehandler-pgtap-perl pgtap postgresql-pgtap \ - ssmtp \ - git cpanminus make gcc libperl-dev lsb-release + ssmtp sudo \ + git make gcc libperl-dev lsb-release -# Java & Nodejs for doing Dojo build -#RUN DEBIAN_FRONTENT=noninteractive && apt-get install -y openjdk-7-jre-headless -RUN apt-get install -y npm -RUN update-alternatives --install /usr/bin/node nodejs /usr/bin/nodejs 100 - # Build time variables ENV LSMB_VERSION master +ENV NODE_PATH /usr/local/lib/node_modules +ENV DEBIAN_FRONTEND=noninteractive + ARG CACHEBUST -# Install LedgerSMB -RUN cd /srv && \ - git clone --recursive -b $LSMB_VERSION https://github.com/ledgersmb/LedgerSMB.git ledgersmb - -WORKDIR /srv/ledgersmb - -# master requirements -RUN cpanm --quiet --notest \ - --with-develop \ - --with-feature=starman \ - --with-feature=latex-pdf-ps \ - --with-feature=openoffice \ - --installdeps . - +# Java & Nodejs for doing Dojo build # Uglify needs to be installed right before 'make dojo'?! -RUN npm install -g uglify-js@">=2.0 <3.0" -ENV NODE_PATH /usr/local/lib/node_modules - -# Build dojo -RUN make dojo +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 # Configure outgoing mail to use host, other run time variable defaults @@ -74,6 +60,53 @@ ENV POSTGRES_HOST postgres ENV POSTGRES_PORT 5432 ENV DEFAULT_DB lsmb +# Make sure www-data share the uid/gid of the container owner on the host +#RUN groupmod --gid $HOST_GID www-data +#RUN usermod --uid $HOST_UID --gid $HOST_GID www-data +RUN groupmod --gid 1000 www-data +RUN usermod --uid 1000 --gid 1000 www-data + +WORKDIR /srv +RUN git clone --recursive -b $LSMB_VERSION https://github.com/ledgersmb/LedgerSMB.git ledgersmb + +WORKDIR /srv/ledgersmb + +# Burst the Docker cache based on a flag file, +# computed from the SHA of the head of git tree (when bind mounted) +COPY ledgersmb.rebuild /var/www/ledgersmb.rebuild + +# master requirements +RUN curl -L https://cpanmin.us | perl - App::cpanminus && \ + cpanm --quiet --notest \ + --with-feature=starman \ + --with-feature=latex-pdf-ps \ + --with-feature=openoffice \ + --with-feature=latex-pdf-images \ + --with-feature=latex-pdf-ps \ + --with-feature=edi \ + --with-feature=xls \ + --with-feature=debug \ + --with-develop \ + --installdeps . + +# Fix Module::Runtime of old distros +RUN cpanm Moose MooseX::NonMoose Data::Printer \ + Devel::hdb Plack::Middleware::Debug::Log4perl \ + Devel::NYTProf \ + Plack::Middleware::Debug::Profiler::NYTProf \ + Plack::Middleware::InteractiveDebugger + +# Uglify needs to be installed right before 'make dojo'?! +RUN npm install -g uglify-js@">=2.0 <3.0" +RUN make dojo + +COPY start.sh /usr/local/bin/start.sh +COPY update_ssmtp.sh /usr/local/bin/update_ssmtp.sh + +RUN chown www-data /etc/ssmtp /etc/ssmtp/ssmtp.conf && \ + chmod +x /usr/local/bin/update_ssmtp.sh /usr/local/bin/start.sh && \ + mkdir -p /var/www && chown www-data:www-data /var/www + # Work around an aufs bug related to directory permissions: RUN mkdir -p /tmp && \ chmod 1777 /tmp @@ -81,16 +114,31 @@ RUN mkdir -p /tmp && \ # Internal Port Expose EXPOSE 5001 -COPY start.sh /usr/local/bin/start.sh -COPY update_ssmtp.sh /usr/local/bin/update_ssmtp.sh +# Add sudo capability +RUN echo "www-data ALL=NOPASSWD: ALL" >>/etc/sudoers -RUN chown www-data /etc/ssmtp /etc/ssmtp/ssmtp.conf && \ - chmod +x /usr/local/bin/update_ssmtp.sh /usr/local/bin/start.sh && \ - mkdir -p /var/www && chown www-data /var/www +RUN apt-get update && \ + apt install -y mc less bzip2 && \ + rm -rf /var/lib/apt/lists/* -# If ledgersmb.conf does not exist, www-data user needs to be able to create it. -RUN chown www-data /srv/ledgersmb +# Add temporary patches +#COPY patch/patches.tar /tmp +#RUN cd / && tar xvf /tmp/patches.tar && rm /tmp/patches.tar +ENV LANG=C.UTF-8 + +RUN cpanm --quiet --notest --force \ + HTTP::AcceptLanguage Text::PO::Parser Class::Std::Utils \ + Module::Versions Regexp::Debugger PPR \ + MooseX::Constructor::AllErrors TryCatch && \ + rm -r ~/.cpanm +# Text::PO::Parser && \ + +RUN chsh -s /bin/bash www-data USER www-data +WORKDIR /var/www +COPY mcthemes.tar.xz /var/www/mcthemes.tar.xz + +WORKDIR /srv/ledgersmb CMD ["start.sh"] diff --git a/README.md b/README.md index e8376dc..9bbd8b8 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,68 @@ These variables are used to set outgoing SMTP defaults. To set the outgoing emai Use the other environment variables to relay mail through another host. +# Integration with docker-compose + +Here is a suggested file for docker integration + + version: "3" + + services: + postgres: + image: ylavoie/postgres-pgtap + container_name: postgres + networks: + - internal + environment: + - POSTGRES_PASSWORD=test + build: + context: ./postgres-pgtap + + lsmb: + image: ylavoie/ledgersmb + container_name: lsmb + networks: + - default + - internal + environment: + - PGHOST=postgres + volumes: + - /tmp:/tmp + - ./LedgerSMB:/srv/ledgersmb:rw + ports: + - 5001:5001 + depends_on: + - postgres + build: + context: ./ledgersmb-docker + + nginx: + image: ylavoie/nginx + container_name: nginx + hostname: dockerlsmb + volumes: + - ./LedgerSMB/UI:/srv/ledgersmb/UI:ro + ports: + - 5000:5000 + networks: + - default + - internal + depends_on: + - lsmb + build: + context: ./ledgersmb-nginx-docker + + networks: + internal: + driver: bridge + internal: true + default: + driver: bridge + ipam: + driver: default + config: + - subnet: 192.168.35.0/24 + # Troubleshooting/Developing You can connect to a running container using: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6658ebc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,62 @@ +# See the following for docker compose version 3 example +# https://github.com/aanand/compose-file/blob/master/loader/full-example.yml + +version: "3" # version matters, see https://docs.docker.com/compose/networking/ + +networks: + lsmb_internal: + driver: bridge + internal: true + +services: + + postgres: + image: ylavoie/postgres-pgtap + container_name: postgres + networks: + - lsmb_internal + build: + context: ./postgres-pgtap + dockerfile: Dockerfile-alpine + environment: + - POSTGRES_PASSWORD=test +# - PGDATA=/tmp/docker-postgresql +# volumes: +# # We'll mount the 'pgdata' volume into the location Postgres stores it's data: +# - pgdata:/var/lib/postgresql/data + + lsmb: + image: ylavoie/ledgersmb + container_name: lsmb + networks: + - default + - lsmb_internal + build: + context: ./ledgersmb-docker + #dns_opt: # V2 only ;-( + # - ndots:1 + environment: + - PGHOST=postgres + volumes: + - /tmp:/tmp + - ./ledgersmb-docker:/srv/ledgersmb-docker + - ./LedgerSMB:/srv/ledgersmb:rw + ports: + - 5001:5001 + depends_on: + - postgres + + nginx: + image: ylavoie/nginx + container_name: nginx + volumes: + - ./LedgerSMB/UI:/srv/ledgersmb/UI:ro + ports: + - 5000:5000 + networks: + - default + - lsmb_internal + depends_on: + - lsmb + build: + context: ./ledgersmb-nginx-docker diff --git a/start.sh b/start.sh index b09ee13..b33342a 100755 --- a/start.sh +++ b/start.sh @@ -1,8 +1,19 @@ #!/bin/bash +pushd ~ + mkdir -p .config/mc + tar Jxf mcthemes.tar.xz + ./mcthemes/mc_change_theme.sh mcthemes/puthre.theme +popd + update_ssmtp.sh cd /srv/ledgersmb +# Revalidate the required CPAN packages in case the +# source tree is bind mounted and has changed since Docker build. +#cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib) +#cpanm --with-develop HTTP::AcceptLanguage + if [[ ! -f ledgersmb.conf ]]; then cp conf/ledgersmb.conf.default ledgersmb.conf sed -i \ @@ -21,17 +32,14 @@ fi # --postgres_password "$POSTGRES_PASS" #fi -# Needed for modules loaded by cpanm -export PERL5LIB -for PerlLib in /usr/lib/perl5* /usr/local/lib/perl5*/site_perl/* ; do - [[ -d "$PerlLib" ]] && { - PERL5LIB="$PerlLib"; - echo -e "\tmaybe: $PerlLib"; - } -done ; -echo "Selected PERL5LIB=$PERL5LIB"; - # start ledgersmb -exec plackup --port 5001 --server HTTP::Server::PSGI tools/starman.psgi \ - --Reload "lib, old/lib, xt/lib" +if [[ ! -f DEVELOPMENT ]]; then +# exec plackup --port 5001 --server Starman tools/starman.psgi \ + exec plackup --port 5001 --server HTTP::Server::PSGI tools/starman.psgi \ + --Reload "lib, old/lib, xt/lib, /usr/local/share/perl, /usr/share/perl, /usr/share/perl5" +else + exec plackup --port 5001 --server HTTP::Server::PSGI tools/starman-development.psgi \ + --workers 1 --env development \ + --Reload "lib, old/lib, xt/lib, /usr/local/share/perl, /usr/share/perl, /usr/share/perl5" +fi diff --git a/update_ssmtp.sh b/update_ssmtp.sh index af2b44f..9125472 100644 --- a/update_ssmtp.sh +++ b/update_ssmtp.sh @@ -1,6 +1,6 @@ #!/bin/bash ConfiguredComment='# install script update_ssmtp.sh has configured ssmtp' -grep -qc "$ConfiguredComment" /etc/ssmtp.conf && { +grep -qc "$ConfiguredComment" /etc/ssmtp.conf >/dev/null && { echo "smtp configured." exit }