From ffc7f8d441fe76006b7065fdb58d31d6f5e9bf71 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Wed, 27 Jan 2016 20:32:47 +1030
Subject: [PATCH 01/14] accept docker build --build-arg LSMB_VERSION=

---
 Dockerfile | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 51a6c19..572e59e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -36,9 +36,15 @@ RUN apt-get install -y \
     PGObject::Type::DateTime \
     App::LedgerSMB::Admin
 
-# Build time variables
-ENV LSMB_VERSION 1.5.0-beta3
+# Set LedgerSMB version (git tag/branch/commit)
+# Change the following line or set arg on docker build commandline;
+# eg:
+# docker build --build-arg LSMB_VERSION=1.4.0 ./
+# docker build --build-arg LSMB_VERSION=1c00d61 ./
+ARG LSMB_VERSION=1.5.0-beta3
+ENV LSMB_VERSION ${LSMB_VERSION}
 
+# Install LedgerSMB
 RUN cd /srv && \
   git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
 

From d1363865735a9d63a7659e389d62fcf1e5753561 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 00:25:49 +1030
Subject: [PATCH 02/14] Let docker cache the initial git clone

It involves a few hacks to assist cachebreaking the docker build process
---
 Dockerfile | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 572e59e..854a583 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,6 +1,8 @@
 FROM        perl:5
 MAINTAINER  Freelock john@freelock.com
 
+ENV 
+
 # Install Perl, Tex, Starman, psql client, and all dependencies
 RUN DEBIAN_FRONTENT=noninteractive && \
   apt-get update && apt-get -y install \
@@ -36,21 +38,34 @@ RUN apt-get install -y \
     PGObject::Type::DateTime \
     App::LedgerSMB::Admin
 
+# Install LedgerSMB
+WORKDIR /srv 
+# update the following label to force docker to cache the latest git clone:
+LABEL lsmb_docker_git_clone_cachebreak=2016-01-28
+RUN git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
+
 # Set LedgerSMB version (git tag/branch/commit)
 # Change the following line or set arg on docker build commandline;
 # eg:
 # docker build --build-arg LSMB_VERSION=1.4.0 ./
 # docker build --build-arg LSMB_VERSION=1c00d61 ./
+# NOTE: if you use a branch name (or a reused tag name) instead of a commit checksum
+#       then docker's caching will see nothing new and you'll end up with stale files
+#       if that branch/tag has already been cached.
+#
+#       As a hack to reliably use a branch (eg, master), try the following:
+#        docker build --build-arg CACHEBREAK=$(date) LSMB_VERSION=master ./
+ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}
 
-# Install LedgerSMB
-RUN cd /srv && \
-  git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
-
 WORKDIR /srv/ledgersmb
-
-RUN git checkout $LSMB_VERSION
+# fetch changes to repo since possibly cached git clone above.
+# checkout specified tag/branch/commit (**NOTE above)
+# merge changes to current checked out branch
+RUN git fetch \
+ && git checkout $LSMB_VERSION
+ && git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch"
 
 #RUN sed -i \
 #  -e "s/short_open_tag = Off/short_open_tag = On/g" \

From e8ccca213f30ddd13106f7a5dfbddada77943141 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 00:27:40 +1030
Subject: [PATCH 03/14] fix error

---
 Dockerfile | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 854a583..c8c4ce2 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,6 @@
 FROM        perl:5
 MAINTAINER  Freelock john@freelock.com
 
-ENV 
-
 # Install Perl, Tex, Starman, psql client, and all dependencies
 RUN DEBIAN_FRONTENT=noninteractive && \
   apt-get update && apt-get -y install \

From 6fe549f92e02bff4ef709ecb08b8f4a4cd71f71f Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 00:30:05 +1030
Subject: [PATCH 04/14] fix error

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index c8c4ce2..ce85229 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -62,7 +62,7 @@ WORKDIR /srv/ledgersmb
 # checkout specified tag/branch/commit (**NOTE above)
 # merge changes to current checked out branch
 RUN git fetch \
- && git checkout $LSMB_VERSION
+ && git checkout $LSMB_VERSION \
  && git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch"
 
 #RUN sed -i \

From 0f916251aa23c16609f77ca324c5af6f19386f5a Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 00:42:26 +1030
Subject: [PATCH 05/14] fix quotes

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index ce85229..656ae5d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -52,7 +52,7 @@ RUN git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
 #       if that branch/tag has already been cached.
 #
 #       As a hack to reliably use a branch (eg, master), try the following:
-#        docker build --build-arg CACHEBREAK=$(date) LSMB_VERSION=master ./
+#        docker build --build-arg CACHEBREAK="$(date)" LSMB_VERSION=master ./
 ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}

From 5c8066757f522daf7511e081b577a8dd364a5076 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 00:45:54 +1030
Subject: [PATCH 06/14] fix example

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 656ae5d..abc0e8a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -52,7 +52,7 @@ RUN git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
 #       if that branch/tag has already been cached.
 #
 #       As a hack to reliably use a branch (eg, master), try the following:
-#        docker build --build-arg CACHEBREAK="$(date)" LSMB_VERSION=master ./
+#        docker build --build-arg CACHEBREAK="$(date)" --build-arg LSMB_VERSION=master ./
 ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}

From 1ac4b71595cb23b7b9a547b76325ca8ff52a3df3 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 13:39:05 +1030
Subject: [PATCH 07/14] remove unnecessary cachebreaking, change comments

---
 Dockerfile | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index abc0e8a..59d322f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -38,21 +38,20 @@ RUN apt-get install -y \
 
 # Install LedgerSMB
 WORKDIR /srv 
-# update the following label to force docker to cache the latest git clone:
-LABEL lsmb_docker_git_clone_cachebreak=2016-01-28
+
 RUN git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
 
 # Set LedgerSMB version (git tag/branch/commit)
-# Change the following line or set arg on docker build commandline;
+# Change LSMB_VERSION or use --build-arg on docker build commandline;
 # eg:
-# docker build --build-arg LSMB_VERSION=1.4.0 ./
-# docker build --build-arg LSMB_VERSION=1c00d61 ./
-# NOTE: if you use a branch name (or a reused tag name) instead of a commit checksum
+# docker build --build-arg LSMB_VERSION=1.5.0-beta3 .
+# docker build --build-arg LSMB_VERSION=1c00d61 .
+# NOTE: If you use a branch name (or a reused tag name) instead of a commit checksum
 #       then docker's caching will see nothing new and you'll end up with stale files
 #       if that branch/tag has already been cached.
 #
-#       As a hack to reliably use a branch (eg, master), try the following:
-#        docker build --build-arg CACHEBREAK="$(date)" --build-arg LSMB_VERSION=master ./
+# As a hack to reliably update a branch (eg, master), --build-arg CACHEBREAK="$(date)":
+#  eg: docker build --build-arg CACHEBREAK="$(date)" --build-arg LSMB_VERSION=master .
 ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}

From 4ed26c274e1eb91c4806145f06149cbbcc27bc42 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 13:43:57 +1030
Subject: [PATCH 08/14] change WORKDIR back into a cd &&

As used in the source of the fork. (WORKDIR is persistent, cd && isn't).
---
 Dockerfile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 59d322f..3087042 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -56,11 +56,11 @@ ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}
 
-WORKDIR /srv/ledgersmb
 # fetch changes to repo since possibly cached git clone above.
 # checkout specified tag/branch/commit (**NOTE above)
 # merge changes to current checked out branch
-RUN git fetch \
+RUN cd /srv/ledgersmb \ 
+ && git fetch \
  && git checkout $LSMB_VERSION \
  && git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch"
 

From c643ee70a73e7198dd631062ca1d79e95fe96baa Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Thu, 28 Jan 2016 14:58:45 +1030
Subject: [PATCH 09/14] operator precedence

---
 Dockerfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 3087042..006011a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -62,7 +62,7 @@ ENV LSMB_VERSION ${LSMB_VERSION}
 RUN cd /srv/ledgersmb \ 
  && git fetch \
  && git checkout $LSMB_VERSION \
- && git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch"
+ && (git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch")
 
 #RUN sed -i \
 #  -e "s/short_open_tag = Off/short_open_tag = On/g" \

From ad5a4eabab772c0e8bc525e3d8675e91af8c15f1 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Fri, 29 Jan 2016 18:44:25 +1030
Subject: [PATCH 10/14] -

---
 Dockerfile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index 006011a..3c6e203 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -36,7 +36,6 @@ RUN apt-get install -y \
     PGObject::Type::DateTime \
     App::LedgerSMB::Admin
 
-# Install LedgerSMB
 WORKDIR /srv 
 
 RUN git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb

From df0c5a29f88043d4b174269d3a46c7a54c356ffd Mon Sep 17 00:00:00 2001
From: maikkeli <michael@Ritas-iMac.gateway>
Date: Fri, 29 Jan 2016 19:09:24 +1030
Subject: [PATCH 11/14] Merge remote-tracking branch 'ledgersmb/master' into
 repo-caching-and-version-build-arg

# Conflicts:
#	Dockerfile
---
 Dockerfile | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 3c6e203..f6ef8d3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -36,9 +36,10 @@ RUN apt-get install -y \
     PGObject::Type::DateTime \
     App::LedgerSMB::Admin
 
-WORKDIR /srv 
+# Install LedgerSMB
 
-RUN git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
+RUN cd /srv && \
+  git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
 
 # Set LedgerSMB version (git tag/branch/commit)
 # Change LSMB_VERSION or use --build-arg on docker build commandline;
@@ -58,8 +59,10 @@ ENV LSMB_VERSION ${LSMB_VERSION}
 # fetch changes to repo since possibly cached git clone above.
 # checkout specified tag/branch/commit (**NOTE above)
 # merge changes to current checked out branch
-RUN cd /srv/ledgersmb \ 
- && git fetch \
+
+WORKDIR /srv/ledgersmb
+
+RUN git fetch \
  && git checkout $LSMB_VERSION \
  && (git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch")
 

From d2cc634b4e9013bc73277ce740ecf5f124ade228 Mon Sep 17 00:00:00 2001
From: maikkeli <mkli@lupini.net>
Date: Fri, 29 Jan 2016 19:38:28 +1030
Subject: [PATCH 12/14] Update Dockerfile

---
 Dockerfile | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index d8774d6..9e616ff 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -36,8 +36,6 @@ RUN apt-get install -y \
     PGObject::Type::DateTime \
     App::LedgerSMB::Admin
 
-# Install LedgerSMB
-
 # Install LedgerSMB
 RUN cd /srv && \
   git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb

From c72c18bc9eb79c177b7213666a8002f776c2ead2 Mon Sep 17 00:00:00 2001
From: maikkeli <maikkeli.github@lupini.net>
Date: Sat, 30 Jan 2016 03:03:12 +1030
Subject: [PATCH 13/14] Accept alternate git url with --build-arg LSMB_REPO=

Also fetch && checkout no longer need to be followed by a merge since checkout is now detached.
---
 Dockerfile | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 9e616ff..931ca00 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -37,8 +37,9 @@ RUN apt-get install -y \
     App::LedgerSMB::Admin
 
 # Install LedgerSMB
+ENV LSMB_REPO_UPSTREAM=https://github.com/ledgersmb/LedgerSMB.git
 RUN cd /srv && \
-  git clone https://github.com/ledgersmb/LedgerSMB.git ledgersmb
+  git clone $LSMB_REPO_UPSTREAM ledgersmb
 
 # Set LedgerSMB version (git tag/branch/commit)
 # Change LSMB_VERSION or use --build-arg on docker build commandline;
@@ -55,15 +56,17 @@ ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}
 
-# fetch changes to repo since possibly cached git clone above.
-# checkout specified tag/branch/commit (**NOTE above)
-# merge changes to current checked out branch
+# Set git remote source, eg: --build-arg LSMB_REPO=https://github.com/ehuelsmann/LedgerSMB.git 
+ARG LSMB_REPO=${LSMB_REPO_UPSTREAM}
 
 WORKDIR /srv/ledgersmb
 
-RUN git fetch \
- && git checkout $LSMB_VERSION \
- && (git merge || echo "git merge failed - this is expected if [$LSMB_VERSION] isn't a branch")
+# add remote repo as alt
+# fetch alt (fetches differences between the initial git clone and current alt remote)
+# checkout specified tag/branch/commit from alt; no need for merge because it's detached
+RUN git remote add alt ${LSMB_REPO} \
+ && git fetch alt \
+ && git checkout alt/$LSMB_VERSION 
 
 #RUN sed -i \
 #  -e "s/short_open_tag = Off/short_open_tag = On/g" \

From cd2beca88c04a2d611686e447d2fee88f9ad1824 Mon Sep 17 00:00:00 2001
From: maikkeli <maikkeli.github@lupini.net>
Date: Sat, 30 Jan 2016 03:03:12 +1030
Subject: [PATCH 14/14] Accept alternate git url with --build-arg LSMB_REPO=

Also fetch && checkout no longer need to be followed by a merge since checkout is now detached.
Some reordering for docker cache optimisation.
---
 Dockerfile | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 931ca00..826f672 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -37,10 +37,19 @@ RUN apt-get install -y \
     App::LedgerSMB::Admin
 
 # Install LedgerSMB
+
+# Clone upstream git repository:
 ENV LSMB_REPO_UPSTREAM=https://github.com/ledgersmb/LedgerSMB.git
 RUN cd /srv && \
   git clone $LSMB_REPO_UPSTREAM ledgersmb
 
+# Set git remote source, eg: --build-arg LSMB_REPO=https://github.com/ehuelsmann/LedgerSMB.git 
+ARG LSMB_REPO=${LSMB_REPO_UPSTREAM}
+WORKDIR /srv/ledgersmb
+# add remote repo as alt
+RUN git remote add alt ${LSMB_REPO} \
+ && git fetch alt
+
 # Set LedgerSMB version (git tag/branch/commit)
 # Change LSMB_VERSION or use --build-arg on docker build commandline;
 # eg:
@@ -50,22 +59,16 @@ RUN cd /srv && \
 #       then docker's caching will see nothing new and you'll end up with stale files
 #       if that branch/tag has already been cached.
 #
-# As a hack to reliably update a branch (eg, master), --build-arg CACHEBREAK="$(date)":
-#  eg: docker build --build-arg CACHEBREAK="$(date)" --build-arg LSMB_VERSION=master .
-ARG CACHEBREAK
 ARG LSMB_VERSION=1.5.0-beta3
 ENV LSMB_VERSION ${LSMB_VERSION}
 
-# Set git remote source, eg: --build-arg LSMB_REPO=https://github.com/ehuelsmann/LedgerSMB.git 
-ARG LSMB_REPO=${LSMB_REPO_UPSTREAM}
+# As a hack to reliably update a branch (eg, master), --build-arg CACHEBREAK="$(date)":
+#  eg: docker build --build-arg CACHEBREAK="$(date)" --build-arg LSMB_VERSION=master .
+ARG CACHEBREAK
 
-WORKDIR /srv/ledgersmb
-
-# add remote repo as alt
-# fetch alt (fetches differences between the initial git clone and current alt remote)
+# fetch alt (fetches changes since the last fetch)
 # checkout specified tag/branch/commit from alt; no need for merge because it's detached
-RUN git remote add alt ${LSMB_REPO} \
- && git fetch alt \
+RUN git fetch alt \
  && git checkout alt/$LSMB_VERSION 
 
 #RUN sed -i \