From ccf8eed41041a18e1ada269ec12c6b3eb56ced6f Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 16:52:30 -0700
Subject: [PATCH 01/14] Simple scraper that makes it muuuuch cleaner to scrape
 github for the latest release URL

---
 git-compiler-helper/go.mod  | 21 ++++++++++++++++
 git-compiler-helper/go.sum  | 49 +++++++++++++++++++++++++++++++++++++
 git-compiler-helper/main.go | 26 ++++++++++++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 git-compiler-helper/go.mod
 create mode 100644 git-compiler-helper/go.sum
 create mode 100644 git-compiler-helper/main.go

diff --git a/git-compiler-helper/go.mod b/git-compiler-helper/go.mod
new file mode 100644
index 000000000..33e2585aa
--- /dev/null
+++ b/git-compiler-helper/go.mod
@@ -0,0 +1,21 @@
+module git-compiler-helper
+
+go 1.13
+
+require (
+	github.com/PuerkitoBio/goquery v1.5.0 // indirect
+	github.com/andybalholm/cascadia v1.1.0 // indirect
+	github.com/antchfx/htmlquery v1.2.0 // indirect
+	github.com/antchfx/xmlquery v1.2.1 // indirect
+	github.com/antchfx/xpath v1.1.2 // indirect
+	github.com/gobwas/glob v0.2.3 // indirect
+	github.com/gocolly/colly v1.2.0
+	github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
+	github.com/golang/protobuf v1.3.2 // indirect
+	github.com/jawher/mow.cli v1.1.0 // indirect
+	github.com/kennygrant/sanitize v1.2.4 // indirect
+	github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
+	github.com/temoto/robotstxt v1.1.1 // indirect
+	golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 // indirect
+	google.golang.org/appengine v1.6.5 // indirect
+)
diff --git a/git-compiler-helper/go.sum b/git-compiler-helper/go.sum
new file mode 100644
index 000000000..c262edf26
--- /dev/null
+++ b/git-compiler-helper/go.sum
@@ -0,0 +1,49 @@
+github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
+github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
+github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
+github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
+github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
+github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
+github.com/antchfx/htmlquery v1.2.0 h1:oKShnsGlnOHX6t4uj5OHgLKkABcJoqnXpqnscoi9Lpw=
+github.com/antchfx/htmlquery v1.2.0/go.mod h1:MS9yksVSQXls00iXkiMqXr0J+umL/AmxXKuP28SUJM8=
+github.com/antchfx/xmlquery v1.2.1 h1:wE4xjHrqOScP440wdv23Xkg0Gr8JryW0ptqodPH+y2U=
+github.com/antchfx/xmlquery v1.2.1/go.mod h1:/+CnyD/DzHRnv2eRxrVbieRU/FIF6N0C+7oTtyUtCKk=
+github.com/antchfx/xpath v1.1.2 h1:YziPrtM0gEJBnhdUGxYcIVYXZ8FXbtbovxOi+UW/yWQ=
+github.com/antchfx/xpath v1.1.2/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
+github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
+github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI=
+github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA=
+github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE=
+github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
+github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/jawher/mow.cli v1.1.0 h1:NdtHXRc0CwZQ507wMvQ/IS+Q3W3x2fycn973/b8Zuk8=
+github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg=
+github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
+github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI=
+github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/temoto/robotstxt v1.1.1 h1:Gh8RCs8ouX3hRSxxK7B1mO5RFByQ4CmJZDwgom++JaA=
+github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
+golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk=
+golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
+google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
diff --git a/git-compiler-helper/main.go b/git-compiler-helper/main.go
new file mode 100644
index 000000000..e4d15ebf8
--- /dev/null
+++ b/git-compiler-helper/main.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"sort"
+	"strings"
+
+	"github.com/gocolly/colly"
+)
+
+func main() {
+	c := colly.NewCollector()
+	var versions []string
+	c.OnHTML(`div.commit .commit-title a`, func(e *colly.HTMLElement) {
+		if versionString := e.Attr("href"); !strings.Contains(versionString, "-rc") {
+			versions = append(versions, versionString)
+		}
+	})
+	c.Visit("https://github.com/git/git/tags")
+	sort.Strings(versions)
+	if len(versions) == 0 {
+		log.Fatalln("no versions were found when scraping github")
+	}
+	fmt.Println(versions[len(versions)-1])
+}

From 3934695bd6fdab5ab5aa1b2fb76815b97eacddf6 Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 16:53:50 -0700
Subject: [PATCH 02/14] Full URL, not relative from github

---
 git-compiler-helper/main.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-compiler-helper/main.go b/git-compiler-helper/main.go
index e4d15ebf8..48d5dec98 100644
--- a/git-compiler-helper/main.go
+++ b/git-compiler-helper/main.go
@@ -22,5 +22,5 @@ func main() {
 	if len(versions) == 0 {
 		log.Fatalln("no versions were found when scraping github")
 	}
-	fmt.Println(versions[len(versions)-1])
+	fmt.Printf("https://www.github.com%s\n", versions[len(versions)-1])
 }

From 26d29bb48977029a6f0f57430a2d83d7db011c1e Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 17:06:13 -0700
Subject: [PATCH 03/14] No end-line after URL, because it breaks curl

---
 git-compiler-helper/main.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git-compiler-helper/main.go b/git-compiler-helper/main.go
index 48d5dec98..3fd63269c 100644
--- a/git-compiler-helper/main.go
+++ b/git-compiler-helper/main.go
@@ -22,5 +22,5 @@ func main() {
 	if len(versions) == 0 {
 		log.Fatalln("no versions were found when scraping github")
 	}
-	fmt.Printf("https://www.github.com%s\n", versions[len(versions)-1])
+	fmt.Printf("https://www.github.com%s", versions[len(versions)-1])
 }

From 28bfba9ee1139d3341784306f919d676aeb4ab2b Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 17:06:40 -0700
Subject: [PATCH 04/14] 90% there, need to iron out some kinks

---
 Dockerfile | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Dockerfile

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..baa006464
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,23 @@
+FROM golang:1.13.4 as git-compiler-helper
+ADD ./git-compiler-helper /root/git-compiler-helper
+WORKDIR /root/git-compiler-helper
+RUN go get -d ./...
+RUN go build -o /root/git-latest-url-finder.run .
+
+FROM ubuntu:latest as git-compiler
+ARG DEBIAN_FRONTEND=noninteractive
+RUN apt-get update
+RUN apt-get install build-essential autoconf dh-autoreconf -y
+RUN apt-get install libcurl4-openssl-dev tcl-dev gettext \
+  asciidoc libexpat1-dev libz-dev -y
+RUN apt-get install curl -y
+COPY --from=git-compiler-helper \
+  /root/git-latest-url-finder.run \
+  /bin/git-latest-url-finder.run
+RUN curl -L --retry 5 --url "$(/bin/git-latest-url-finder.run)" --output "git-source.tar.gz" && \
+  tar -xf "git-source.tar.gz" --strip 1
+RUN make configure
+RUN ./configure --with-openssl
+RUN make
+COPY ./git /bin/git
+ENTRYPOINT [ "git" ]
\ No newline at end of file

From 8a6566cc87c5fe0e4fed47859475cd49edd2c5fe Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 22:03:55 -0700
Subject: [PATCH 05/14] Fixed it

---
 git-compiler-helper/main.go | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/git-compiler-helper/main.go b/git-compiler-helper/main.go
index 3fd63269c..272a420e2 100644
--- a/git-compiler-helper/main.go
+++ b/git-compiler-helper/main.go
@@ -3,6 +3,7 @@ package main
 import (
 	"fmt"
 	"log"
+	"os"
 	"sort"
 	"strings"
 
@@ -12,15 +13,25 @@ import (
 func main() {
 	c := colly.NewCollector()
 	var versions []string
-	c.OnHTML(`div.commit .commit-title a`, func(e *colly.HTMLElement) {
-		if versionString := e.Attr("href"); !strings.Contains(versionString, "-rc") {
-			versions = append(versions, versionString)
+	c.OnHTML(`div.commit a.muted-link`, func(e *colly.HTMLElement) {
+		href := e.Attr("href")
+		debug("found href: %s", href)
+		if strings.HasSuffix(href, ".tar.gz") {
+			debug("saving: %s", href)
+			versions = append(versions, href)
 		}
 	})
 	c.Visit("https://github.com/git/git/tags")
 	sort.Strings(versions)
+	debug("sorted versions: %v", versions)
 	if len(versions) == 0 {
 		log.Fatalln("no versions were found when scraping github")
 	}
 	fmt.Printf("https://www.github.com%s", versions[len(versions)-1])
 }
+
+func debug(s string, args ...interface{}) {
+	if debug := os.Getenv("DEBUG"); debug != "" {
+		log.Printf(s, args...)
+	}
+}

From e2328c673ac2c4e76243f6fb7e276d768a5bc58d Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 22:35:56 -0700
Subject: [PATCH 06/14] Builds a _maybe_ static binary

---
 Dockerfile | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index baa006464..480ea54d0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,13 +11,19 @@ RUN apt-get install build-essential autoconf dh-autoreconf -y
 RUN apt-get install libcurl4-openssl-dev tcl-dev gettext \
   asciidoc libexpat1-dev libz-dev -y
 RUN apt-get install curl -y
+RUN mkdir -p /root/src
+WORKDIR /root/src
 COPY --from=git-compiler-helper \
   /root/git-latest-url-finder.run \
-  /bin/git-latest-url-finder.run
-RUN curl -L --retry 5 --url "$(/bin/git-latest-url-finder.run)" --output "git-source.tar.gz" && \
+  /root/git-latest-url-finder.run
+RUN /root/git-latest-url-finder.run > git-tar-url.txt && \
+  echo "$(cat git-tar-url.txt)" && \
+  curl -L --retry 5 --url "$(cat git-tar-url.txt)" --output "git-source.tar.gz" && \
+  # curl -o "git-source.tar.gz" && \
   tar -xf "git-source.tar.gz" --strip 1
 RUN make configure
-RUN ./configure --with-openssl
+RUN CFLAGS="-static" ./configure --with-openssl
 RUN make
-COPY ./git /bin/git
+RUN ls ./*
+RUN cp ./git /bin/git
 ENTRYPOINT [ "git" ]
\ No newline at end of file

From 67e8d32dd2872878350ae5876d8d3ed24b820d6b Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Wed, 27 Nov 2019 22:48:34 -0700
Subject: [PATCH 07/14] Cleaning a little

---
 Dockerfile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 480ea54d0..e18758929 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -19,11 +19,9 @@ COPY --from=git-compiler-helper \
 RUN /root/git-latest-url-finder.run > git-tar-url.txt && \
   echo "$(cat git-tar-url.txt)" && \
   curl -L --retry 5 --url "$(cat git-tar-url.txt)" --output "git-source.tar.gz" && \
-  # curl -o "git-source.tar.gz" && \
   tar -xf "git-source.tar.gz" --strip 1
 RUN make configure
 RUN CFLAGS="-static" ./configure --with-openssl
 RUN make
-RUN ls ./*
-RUN cp ./git /bin/git
+RUN make install
 ENTRYPOINT [ "git" ]
\ No newline at end of file

From 638a151b4798cffab8ae6fd602e711fad47b42fa Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Mon, 2 Dec 2019 10:20:54 -0700
Subject: [PATCH 08/14] Script to build docker image and test the git static
 binary

---
 build-release-image.sh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 build-release-image.sh

diff --git a/build-release-image.sh b/build-release-image.sh
new file mode 100755
index 000000000..9d38940c6
--- /dev/null
+++ b/build-release-image.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+set -e
+
+repository='paulnelsonbaker'
+name='git-static-binary'
+test_clone_url="https://github.com/paul-nelson-baker/git-openssl-shellscript.git"
+
+set -x
+docker build . -t "${name}:latest"
+
+clone_directory="${HOME}/$(basename $(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'))"
+mkdir -p "${clone_directory}"
+docker run -v "${clone_directory}:/clone" -w '/clone' "${name}:latest" clone "${test_clone_url}"
+
+git_version=$(docker run "${name}:latest" --version | awk '{ print $3 }')
+docker tag "${name}:latest" "${repository}/${name}:${git_version}"
+docker push "${repository}/${name}:${git_version}"

From 72f438443c63b9cc103ae6552846513c1b7abc87 Mon Sep 17 00:00:00 2001
From: Paul Baker <paul.nelson.baker@gmail.com>
Date: Mon, 2 Dec 2019 10:33:13 -0700
Subject: [PATCH 09/14] Adding a note to self

---
 build-release-image.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/build-release-image.sh b/build-release-image.sh
index 9d38940c6..2ce221992 100755
--- a/build-release-image.sh
+++ b/build-release-image.sh
@@ -15,3 +15,6 @@ docker run -v "${clone_directory}:/clone" -w '/clone' "${name}:latest" clone "${
 git_version=$(docker run "${name}:latest" --version | awk '{ print $3 }')
 docker tag "${name}:latest" "${repository}/${name}:${git_version}"
 docker push "${repository}/${name}:${git_version}"
+
+# Notes, still can't get curl to statically compile into git....
+# Might need something like this? https://scripter.co/nim-deploying-static-binaries/
\ No newline at end of file

From af0358c79379a48da59a7edc4564ef54d6cc2d47 Mon Sep 17 00:00:00 2001
From: Gregor <gregor-j@users.noreply.github.com>
Date: Fri, 27 Nov 2020 19:22:01 +0100
Subject: [PATCH 10/14] rewrite Dockerfile to compile an installable git
 package

---
 Dockerfile | 74 ++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 25 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index e18758929..96ba3f0b4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,27 +1,51 @@
-FROM golang:1.13.4 as git-compiler-helper
-ADD ./git-compiler-helper /root/git-compiler-helper
-WORKDIR /root/git-compiler-helper
-RUN go get -d ./...
-RUN go build -o /root/git-latest-url-finder.run .
-
 FROM ubuntu:latest as git-compiler
-ARG DEBIAN_FRONTEND=noninteractive
-RUN apt-get update
-RUN apt-get install build-essential autoconf dh-autoreconf -y
-RUN apt-get install libcurl4-openssl-dev tcl-dev gettext \
-  asciidoc libexpat1-dev libz-dev -y
-RUN apt-get install curl -y
-RUN mkdir -p /root/src
+# Optional curl options like --insecure in case you're behind a corporate proxy.
+ARG CURL_OPTIONS=''
+# no interactions with apt possible
+ENV DEBIAN_FRONTEND=noninteractive
+# update apt
+RUN apt-get update -qq -y --fix-missing;
+# install required packages
+RUN apt-get install -qq -y --no-install-recommends \
+    build-essential \
+    autoconf \
+    dh-autoreconf \
+    libcurl4-openssl-dev \
+    tcl-dev \
+    gettext \
+    asciidoc \
+    libexpat1-dev \
+    libz-dev \
+    # @see https://help.ubuntu.com/community/CheckInstall
+    checkinstall \
+    # install curl and jq for downloading
+    curl \
+    # @see https://stedolan.github.io/jq/tutorial/
+    jq;
+# prepare source dir
+RUN mkdir -p /root/src;
 WORKDIR /root/src
-COPY --from=git-compiler-helper \
-  /root/git-latest-url-finder.run \
-  /root/git-latest-url-finder.run
-RUN /root/git-latest-url-finder.run > git-tar-url.txt && \
-  echo "$(cat git-tar-url.txt)" && \
-  curl -L --retry 5 --url "$(cat git-tar-url.txt)" --output "git-source.tar.gz" && \
-  tar -xf "git-source.tar.gz" --strip 1
-RUN make configure
-RUN CFLAGS="-static" ./configure --with-openssl
-RUN make
-RUN make install
-ENTRYPOINT [ "git" ]
\ No newline at end of file
+# download & extract source tar
+RUN curl ${CURL_OPTIONS} \
+        --location \
+        --fail \
+        $(curl ${CURL_OPTIONS} --silent --fail 'https://api.github.com/repos/git/git/tags' | jq '.[0].tarball_url' | tr -d '"') \
+    | tar xz --strip 1;
+# configure & compile git with OpenSSL
+RUN make configure; \
+    CFLAGS="-static" ./configure --with-openssl; \
+    make;
+# create debian package
+RUN checkinstall \
+        --type=debian \
+        --pkgname=git-openssl \
+        --pkgversion=$(./git --version | cut -d " " -f 3);
+# move created .deb file to a more scriptable filename
+RUN mv -v ./git-openssl_$(./git --version | cut -d " " -f 3)-1_amd64.deb ./git-openssl.deb;
+
+# install package on plain ubuntu
+FROM ubuntu:latest
+COPY --from=git-compiler \
+    /root/src/git-openssl.deb \
+    /root/git-openssl.deb
+RUN dpkg -i /root/git-openssl.deb

From 2c04e25642899155176eea6dbfce5e4b626b4344 Mon Sep 17 00:00:00 2001
From: Gregor <gregor-j@users.noreply.github.com>
Date: Mon, 30 Nov 2020 12:53:29 +0100
Subject: [PATCH 11/14] don't build static binaries, add support for https, add
 package requirements to checkinstall and install git in clean ubuntu image
 with dependencies

---
 Dockerfile | 51 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 96ba3f0b4..3014ecc56 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,24 +4,35 @@ ARG CURL_OPTIONS=''
 # no interactions with apt possible
 ENV DEBIAN_FRONTEND=noninteractive
 # update apt
-RUN apt-get update -qq -y --fix-missing;
-# install required packages
+RUN apt-get update -qq -y;
+# Install stuff for git itself
+RUN apt-get install -qq -y --no-install-recommends \
+    zlib1g \
+    libcurl4 \
+    perl \
+    libpcre3 \
+    libexpat1 \
+    liberror-perl \
+    libc6;
+# Install meta-things for building on the end-user's machine
 RUN apt-get install -qq -y --no-install-recommends \
     build-essential \
     autoconf \
     dh-autoreconf \
+    # @see https://help.ubuntu.com/community/CheckInstall
+    checkinstall \
+    curl \
+    # @see https://stedolan.github.io/jq/tutorial/
+    jq;
+# Install dev stuff for git
+RUN apt-get install -qq -y --no-install-recommends \
     libcurl4-openssl-dev \
     tcl-dev \
     gettext \
     asciidoc \
     libexpat1-dev \
     libz-dev \
-    # @see https://help.ubuntu.com/community/CheckInstall
-    checkinstall \
-    # install curl and jq for downloading
-    curl \
-    # @see https://stedolan.github.io/jq/tutorial/
-    jq;
+    libssl-dev;
 # prepare source dir
 RUN mkdir -p /root/src;
 WORKDIR /root/src
@@ -29,23 +40,39 @@ WORKDIR /root/src
 RUN curl ${CURL_OPTIONS} \
         --location \
         --fail \
+        # assuming the top-most tag is the most recent version
         $(curl ${CURL_OPTIONS} --silent --fail 'https://api.github.com/repos/git/git/tags' | jq '.[0].tarball_url' | tr -d '"') \
     | tar xz --strip 1;
 # configure & compile git with OpenSSL
 RUN make configure; \
-    CFLAGS="-static" ./configure --with-openssl; \
+    ./configure --prefix=/usr --with-openssl; \
     make;
 # create debian package
 RUN checkinstall \
+        --default \
         --type=debian \
         --pkgname=git-openssl \
-        --pkgversion=$(./git --version | cut -d " " -f 3);
+        --pkgversion=$(./git --version | cut -d " " -f 3) \
+        --pkgarch=$(dpkg --print-architecture) \
+        --conflicts=git \
+        --requires="libcurl4,zlib1g \(\>= 1:1.2.0\),perl,libpcre3,libexpat1 \(\>= 2.0.1\),liberror-perl,libc6" \
+        --recommends="less,patch,ssh-client,ca-certificates" \
+        make install;
 # move created .deb file to a more scriptable filename
-RUN mv -v ./git-openssl_$(./git --version | cut -d " " -f 3)-1_amd64.deb ./git-openssl.deb;
+RUN cp -v ./git-openssl_$(./git --version | cut -d " " -f 3)-1_$(dpkg --print-architecture).deb /root/git-openssl.deb;
 
 # install package on plain ubuntu
 FROM ubuntu:latest
 COPY --from=git-compiler \
-    /root/src/git-openssl.deb \
+    /root/git-openssl.deb \
     /root/git-openssl.deb
+RUN apt-get update -qq -y; \
+    apt-get install -qq -y --no-install-recommends \
+        libcurl4 \
+        perl \
+        libexpat1 \
+        liberror-perl \
+        ca-certificates; \
+    apt-get clean;
 RUN dpkg -i /root/git-openssl.deb
+ENTRYPOINT [ "git" ]

From 80f608a1a54546daa530bc5e5dd36090fac9616e Mon Sep 17 00:00:00 2001
From: Gregor <gregor-j@users.noreply.github.com>
Date: Mon, 30 Nov 2020 18:23:31 +0100
Subject: [PATCH 12/14] fix spacing

---
 Dockerfile | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 3014ecc56..ba15cb1af 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -49,15 +49,15 @@ RUN make configure; \
     make;
 # create debian package
 RUN checkinstall \
-        --default \
-        --type=debian \
-        --pkgname=git-openssl \
-        --pkgversion=$(./git --version | cut -d " " -f 3) \
-        --pkgarch=$(dpkg --print-architecture) \
-        --conflicts=git \
-        --requires="libcurl4,zlib1g \(\>= 1:1.2.0\),perl,libpcre3,libexpat1 \(\>= 2.0.1\),liberror-perl,libc6" \
-        --recommends="less,patch,ssh-client,ca-certificates" \
-        make install;
+    --default \
+    --type=debian \
+    --pkgname=git-openssl \
+    --pkgversion=$(./git --version | cut -d " " -f 3) \
+    --pkgarch=$(dpkg --print-architecture) \
+    --conflicts=git \
+    --requires="libcurl4,zlib1g \(\>= 1:1.2.0\),perl,libpcre3,libexpat1 \(\>= 2.0.1\),liberror-perl,libc6" \
+    --recommends="less,patch,ssh-client,ca-certificates" \
+    make install;
 # move created .deb file to a more scriptable filename
 RUN cp -v ./git-openssl_$(./git --version | cut -d " " -f 3)-1_$(dpkg --print-architecture).deb /root/git-openssl.deb;
 

From d4c8a686b30669b26aebd73f6bf15321e7a259aa Mon Sep 17 00:00:00 2001
From: Gregor <gregor-j@users.noreply.github.com>
Date: Mon, 30 Nov 2020 18:30:08 +0100
Subject: [PATCH 13/14] add git config files and create 10 user- and group-IDs
 in case this image is run without privileges

---
 Dockerfile | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index ba15cb1af..6d0836acc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -63,16 +63,26 @@ RUN cp -v ./git-openssl_$(./git --version | cut -d " " -f 3)-1_$(dpkg --print-ar
 
 # install package on plain ubuntu
 FROM ubuntu:latest
+# copy package from temporary image
 COPY --from=git-compiler \
     /root/git-openssl.deb \
     /root/git-openssl.deb
+# install package dependencies
 RUN apt-get update -qq -y; \
     apt-get install -qq -y --no-install-recommends \
         libcurl4 \
         perl \
         libexpat1 \
         liberror-perl \
-        ca-certificates; \
-    apt-get clean;
-RUN dpkg -i /root/git-openssl.deb
+        ca-certificates \
+        less \
+        patch \
+        ssh-client; \
+    apt-get clean; \
+    # install package
+    dpkg -i /root/git-openssl.deb; \
+    # create git config files
+    touch /root/.gitconfig /root/.git-credentials /etc/skel/.gitconfig /etc/skel/.git-credentials; \
+    # create 10 user- and group-IDs in case this image is run without privileges
+    bash -c 'for i in {1000..1010}; do groupadd -g ${i} -o "group${i}"; useradd -m -u ${i} -g ${i} -s /usr/bin/bash "user${i}"; done'
 ENTRYPOINT [ "git" ]

From bcd3a9898bf8e16f910f095ba8d215ec8796a915 Mon Sep 17 00:00:00 2001
From: Gregor <gregor-j@users.noreply.github.com>
Date: Mon, 30 Nov 2020 18:32:04 +0100
Subject: [PATCH 14/14] quit docker run commands in case of error and display
 commands

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

diff --git a/Dockerfile b/Dockerfile
index 6d0836acc..14b064846 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -68,7 +68,8 @@ COPY --from=git-compiler \
     /root/git-openssl.deb \
     /root/git-openssl.deb
 # install package dependencies
-RUN apt-get update -qq -y; \
+RUN set -xe; \
+    apt-get update -qq -y; \
     apt-get install -qq -y --no-install-recommends \
         libcurl4 \
         perl \
