Skip to content
Permalink
Browse files

Refactor dist/build and Dockerfiles to use newer --build-arg feature.…

… Get builds working again.
  • Loading branch information...
Aaron Hopkins
Aaron Hopkins committed Dec 30, 2018
1 parent 4e79205 commit 5fe6644c1e6834f7a5d64ae938305de20a14f4a9
@@ -2,5 +2,5 @@
.gitignore
fotomat
*~
*.rpm
*.dpkg
fotomat-*.rpm
fotomat-*.dpkg
@@ -20,8 +20,8 @@ _cgo_export.*
_testmain.go

*.exe
*.rpm
*.deb
fotomat-*.rpm
fotomat-*.deb
/fotomat
/cmd/fotomat/fotomat
*~
@@ -12,11 +12,6 @@

FROM debian:stretch as builder

# Set up an /export/ directory with a tmp/ and etc/passwd
RUN mkdir -p -m 1777 /export/tmp
RUN useradd -r fotomat
RUN install -D /etc/passwd /export/etc/passwd

# Apt-get our dependencies, download, build, and install VIPS, and download and install Go.
ADD preinstall.sh /app/src/github.com/die-net/fotomat/
RUN DEBIAN_FRONTEND=noninteractive CFLAGS="-O2 -ftree-vectorize -msse2 -ffast-math" \
@@ -27,11 +22,31 @@ RUN DEBIAN_FRONTEND=noninteractive CFLAGS="-O2 -ftree-vectorize -msse2 -ffast-ma
ADD . /app/src/github.com/die-net/fotomat/

# Build and install Fotomat
RUN GOPATH=/app /usr/local/go/bin/go get -t github.com/die-net/fotomat/...
RUN GOPATH=/app /usr/local/go/bin/go get -ldflags="-s -w" -t github.com/die-net/fotomat/...

# Test fotomat
RUN GOPATH=/app /usr/local/go/bin/go test -v github.com/die-net/fotomat/...

# Set up an /export/ directory with the very basics of a system
RUN mkdir -m 0755 -p /export/etc /export/home /export/bin /export/usr/bin /export/sbin /export/usr/sbin && \
mkdir -m 0700 -p /export/root /export/proc /export/dev && \
mkdir -p -m 1777 /export/tmp
RUN useradd -r fotomat
RUN cp -a --parents \
/etc/nsswitch.conf \
/etc/passwd \
/etc/group \
/etc/shadow \
/etc/localtime \
/usr/share/zoneinfo/UTC \
/etc/ssl/certs/ca-certificates.crt \
/export/

# Install busybox and all of its dependencies into /export.
RUN apt-get install -y -q --no-install-recommends busybox
RUN install -sD /bin/busybox /export/bin/busybox
RUN ldd /bin/busybox | awk '($2=="=>"){print $3};(substr($1,1,1)=="/"){print $1}' | xargs -i{} install -D {} /export{}

# Install Fotomat and all of its dependencies into /export.
RUN install -sD /app/bin/fotomat /export/app/bin/fotomat
RUN ldd /app/bin/fotomat | awk '($2=="=>"){print $3};(substr($1,1,1)=="/"){print $1}' | xargs -i{} install -D {} /export{}
@@ -47,6 +62,11 @@ EXPOSE 3520

COPY --from=builder /export/ /

VOLUME /tmp

# Expand busybox
RUN ["/bin/busybox", "--install"]

USER fotomat

# Make sure the app runs at all.
@@ -1,10 +1,11 @@
# Build Fotomat RPM for Debian buster using Docker.
# Build Fotomat dpkg for Debian or Ubuntu using Docker
#
# Run: dist/build dpkg-buster
# Run: dist/build dpkg-debian:buster
#
# And you'll end up with a fotomat*.dpkg in the current directory.

FROM debian:buster
ARG BASE
FROM $BASE

# Apt-get our dependencies, download, build, and install VIPS, and download and install Go.
ADD preinstall.sh /app/src/github.com/die-net/fotomat/
@@ -22,7 +23,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -q --no-install-recommends
ADD . /app/src/github.com/die-net/fotomat/

# Build and install Fotomat
RUN GOPATH=/app CGO_LDFLAGS_ALLOW="-Wl,--export-dynamic" /usr/local/go/bin/go get -tags vips_static -t github.com/die-net/fotomat/...
RUN GOPATH=/app CGO_LDFLAGS_ALLOW="-Wl,--export-dynamic" /usr/local/go/bin/go get -ldflags="-s -w" -tags vips_static -t github.com/die-net/fotomat/...

# Test fotomat
RUN GOPATH=/app CGO_LDFLAGS_ALLOW="-Wl,--export-dynamic" /usr/local/go/bin/go test -tags vips_static -v github.com/die-net/fotomat/...

This file was deleted.

This file was deleted.

@@ -1,10 +1,11 @@
# Build Fotomat RPM for CentOS 7 using Docker.
# Build Fotomat RPM for CentOS/RHEL based distros using Docker.
#
# Run: dist/build rpm-centos7
# Run: dist/build rpm-centos:6
#
# And you'll end up with a fotomat*.rpm in the current directory.

FROM centos:7
ARG BASE
FROM $BASE

# Apt-get our dependencies, download, build, and install VIPS, and download and install Go.
ADD preinstall.sh /app/src/github.com/die-net/fotomat/
@@ -20,7 +21,7 @@ ADD . /app/src/github.com/die-net/fotomat/

# Build and install Fotomat
RUN PKG_CONFIG_PATH=/usr/local/lib/pkgconfig GOPATH=/app CGO_LDFLAGS_ALLOW="-Wl,--export-dynamic" \
/usr/local/go/bin/go get -tags vips_static -t github.com/die-net/fotomat/...
/usr/local/go/bin/go get -ldflags="-s -w" -tags vips_static -t github.com/die-net/fotomat/...

# Test fotomat
RUN PKG_CONFIG_PATH=/usr/local/lib/pkgconfig GOPATH=/app CGO_LDFLAGS_ALLOW="-Wl,--export-dynamic" \

This file was deleted.

@@ -8,55 +8,65 @@ cd $( dirname $0 )/..
version=$( perl -ne '/FotomatVersion.*\b(\d+\.\d+\.\d+)/ and print "${1}-1"' cmd/fotomat/version.go )

build() {
local tag="$1"
local base="$1"
local format=""
local path=""
local final=""

if [ ! -f Dockerfile.$tag ]; then
echo "Dockerfile.$tag doesn't exist!"
return
local repo="${base%%:*}"
local tag="${base#*:}"

if [ "$repo" = "" -o "$tag" = "" -o "$tag" = "$repo" ]; then
echo "Base must be formatted as repo:tag"
exit 1
fi

case "$tag" in
dpkg-*)
case $repo in
debian|mint|ubuntu)
format="dpkg"
path="app/src/github.com/die-net/fotomat/dist/dpkg/fotomat.deb"
final="fotomat-${version}.${tag/dpkg-/}.amd64.deb"
final="fotomat-${version}.${tag}.amd64.deb"
;;
rpm-*)
centos|fedora|rhel|sl)
path="root/rpmbuild/RPMS/*/fotomat*.rpm"
format="rpm"
;;
*)
echo "Don't understand how to parse tag $tag"
exit 1
;;
echo "Don't understand how to parse base $base"
exit 1
;;
esac

if [ ! -f Dockerfile.$format ]; then
echo "Dockerfile.$format doesn't exist!"
return
fi

local slashes=$(( 0 + $( echo "$path" | tr -cd / | wc -c ) ))

docker build -f Dockerfile.$tag -t dienet/fotomat:$tag .
docker rm fotomat-$tag || true
docker run --name fotomat-$tag dienet/fotomat:$tag /bin/true
docker export fotomat-$tag | tar --strip-components=$slashes -xvf - "$path" || true
docker rm fotomat-$tag
docker rmi dienet/fotomat:$tag
docker build --pull -f Dockerfile.$format --build-arg BASE=$base -t dienet/fotomat:$repo$tag .
docker rm fotomat-$repo$tag || true
docker run --name fotomat-$repo$tag dienet/fotomat:$repo$tag /bin/true
docker export fotomat-$repo$tag | tar --strip-components=$slashes -xvf - "$path" || true
docker rm fotomat-$repo$tag
docker rmi dienet/fotomat:$repo$tag
if [ ! -z "$final" ]; then
mv "$( basename "$path" )" "$final"
fi
}

if [ $# -eq 0 ]; then
echo "Usage: $0 <tag> [<tag> ...] - Build one or more package tags via Docker"
echo " $0 all - Build all available tags"
echo "Usage: $0 <base> [<base> ...] - Build one or more packages from the given base image via Docker"
echo " $0 all - Build all known base images"
exit 1
fi

if [ "$1" = "all" ]; then
ls -1 Dockerfile.dpkg-* Dockerfile.rpm-* | while read file; do
tag=${file/Dockerfile./}
build "$tag"
for base in debian:buster debian:stretch debian:jessie centos:7 centos:6; do
build "$base"
done
else
for tag in "$@"; do
build "$tag"
for base in "$@"; do
build "$base"
done
fi
@@ -26,7 +26,7 @@ images in the shortest time and at the smallest file size possible.

%install
install -d -m 755 $RPM_BUILD_ROOT/usr/sbin/
install -s -m 755 /app/bin/fotomat $RPM_BUILD_ROOT/usr/sbin/
install -m 755 /app/bin/fotomat $RPM_BUILD_ROOT/usr/sbin/

%files
/usr/sbin/fotomat
@@ -46,28 +46,28 @@ case "$release" in
debian-8|ubuntu-1[456].*|mint-17.*)
# Debian 8, Ubuntu 14-16, Mint 17
apt-get -q update
apt-get install -y -q --no-install-recommends ca-certificates git curl tar automake build-essential libglib2.0-dev libjpeg-dev libpng12-dev libwebp-dev libgif-dev liblcms2-dev libtiff5-dev libxml2-dev libexif-dev libexpat1-dev libfftw3-dev libffi-dev librsvg2-dev libpoppler-glib-dev
apt-get install -y -q --no-install-recommends ca-certificates git curl tar automake build-essential libglib2.0-dev libjpeg-dev libpng12-dev libwebp-dev libgif-dev liblcms2-dev libtiff5-dev libxml2-dev libexif-dev libexpat1-dev libfftw3-dev libffi-dev librsvg2-dev libpoppler-glib-dev libselinux1-dev
;;
debian-9|debian-unknown|ubuntu-1[789].*)
# Debian 9 or sid, Ubuntu 17-19
apt-get -q update
apt-get install -y -q --no-install-recommends ca-certificates git curl tar automake build-essential libglib2.0-dev libjpeg-dev libpng-dev libwebp-dev libgif-dev liblcms2-dev libtiff5-dev libxml2-dev libexif-dev libexpat1-dev libfftw3-dev libffi-dev librsvg2-dev libpoppler-glib-dev
apt-get install -y -q --no-install-recommends ca-certificates git curl tar automake build-essential libglib2.0-dev libjpeg-dev libpng-dev libwebp-dev libgif-dev liblcms2-dev libtiff5-dev libxml2-dev libexif-dev libexpat1-dev libfftw3-dev libffi-dev librsvg2-dev libpoppler-glib-dev libselinux1-dev libmount-dev libzstd-dev
;;
centos-7*|rhel-7*)
# RHEL/CentOS/SL 7
yum -y install epel-release
yum -y update
yum install -y curl tar findutils git automake make gcc gcc-c++ glib2-devel libexif-devel libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel giflib-devel lcms2-devel libxml2-devel expat-devel libffi-devel jbigkit-devel librsvg2-dev libpoppler-glib-devel
yum install -y curl tar findutils git automake make gcc gcc-c++ glib2-devel libexif-devel libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel giflib-devel lcms2-devel libxml2-devel expat-devel libffi-devel jbigkit-devel librsvg2-devel poppler-glib-devel libselinux-devel libmount-devel bzip2-devel
;;
fedora-2[1-3])
# Fedora 21-23
yum install -y curl tar findutils git automake make gcc gcc-c++ glib2-devel libexif-devel libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel giflib-devel lcms2-devel libxml2-devel expat-devel libffi-devel jbigkit-devel fftw3-devel fontconfig-devel libtool-ltdl-devel librsvg2-dev libpoppler-glib-devel
yum install -y curl tar findutils git automake make gcc gcc-c++ glib2-devel libexif-devel libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel giflib-devel lcms2-devel libxml2-devel expat-devel libffi-devel jbigkit-devel fftw3-devel fontconfig-devel libtool-ltdl-devel librsvg2-devel poppler-glib-devel
;;
"Red Hat Enterprise Linux release 6."*|"CentOS release 6."*|"Scientific Linux release 6."*)
# RHEL/CentOS/SL 6
yum -y install epel-release
yum -y update
yum install -y curl tar findutils git automake make gcc gcc-c++ glib2-devel libexif-devel libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel giflib-devel lcms2-devel libxml2-devel expat-devel librsvg2-dev libpoppler-glib-devel
yum install -y curl tar findutils git automake make gcc gcc-c++ glib2-devel libexif-devel libjpeg-turbo-devel libpng-devel libtiff-devel libwebp-devel giflib-devel lcms2-devel libxml2-devel expat-devel
;;
*)
echo "Sorry, I don't yet know how to install on $release ($(uname -a))."
@@ -95,9 +95,10 @@ else
--disable-pyvips8 --disable-static --without-analyze --without-cfitsio \
--without-fftw --without-gsf --without-magick --without-matio \
--without-openslide --without-orc --without-pangoft2 --without-ppm \
--without-python --without-radiance --without-tiff --without-x \
--without-radiance --without-x \
--with-OpenEXR --with-jpeg --with-lcms --with-libexif --with-giflib \
--with-libwebp --with-png --with-poppler --with-rsvg ${VIPS_OPTIONS:-}
--with-libwebp --with-png --with-poppler --with-rsvg --with-tiff \
${VIPS_OPTIONS:-}
make -j $( getconf _NPROCESSORS_ONLN 2> /dev/null || echo 1 )
make install
cd ..
@@ -117,9 +118,10 @@ else
exit 1
fi

url="https://storage.googleapis.com/golang/go${GO_VERSION}.${arch}.tar.gz"
echo "Installing Go from ${url}"
mkdir -p /usr/local/go && \
curl -sSL https://storage.googleapis.com/golang/go${GO_VERSION}.${arch}.tar.gz | \
tar --strip-components=1 -C /usr/local/go -xzf -
curl -sSL $url | tar --strip-components=1 -C /usr/local/go -xzf -
ln -sf ../go/bin/go /usr/local/bin/go
echo "Installed $(go version)"
fi

0 comments on commit 5fe6644

Please sign in to comment.
You can’t perform that action at this time.