Update example image Dockerfile

* Use a multistage Dockerfile with build args to provide the base postgres image
version
* Build stolon inside docker instead of copying locally built binaries (that
cannot be right since they may have been built for a different arch, os, glibc etc...).
This commit is contained in:
Simone Gotti 2019-10-10 16:38:01 +02:00
parent 18a8ca1342
commit 3c645ce740
5 changed files with 42 additions and 15 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
.git

View File

@ -37,9 +37,7 @@ stolonctl:
CGO_ENABLED=0 GO111MODULE=on go build -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/stolonctl $(REPO_PATH)/cmd/stolonctl
.PHONY: docker
docker: build
docker:
if [ -z $${PGVERSION} ]; then echo 'PGVERSION is undefined'; exit 1; fi; \
if [ -z $${TAG} ]; then echo 'TAG is undefined'; exit 1; fi; \
export TEMPFILE="$$(mktemp)"; \
sed -e "s/\$${PGVERSION}/$${PGVERSION}/" examples/kubernetes/image/docker/Dockerfile.template > $${TEMPFILE}; \
docker build -t $${TAG} -f $${TEMPFILE} .
docker build --build-arg PGVERSION=${PGVERSION} -t ${TAG} -f examples/kubernetes/image/docker/Dockerfile .

View File

@ -0,0 +1,36 @@
ARG PGVERSION
# base build image
FROM golang:1.13-buster AS build_base
WORKDIR /stolon
# only copy go.mod and go.sum
COPY go.mod .
COPY go.sum .
RUN go mod download
#######
####### Build the stolon binaries
#######
FROM build_base AS builder
# copy all the sources
COPY . .
RUN make
#######
####### Build the final image
#######
FROM postgres:$PGVERSION
RUN useradd -ms /bin/bash stolon
EXPOSE 5432
# copy the agola-web dist
COPY --from=builder /stolon/bin/ /usr/local/bin
RUN chmod +x /usr/local/bin/stolon-keeper /usr/local/bin/stolon-sentinel /usr/local/bin/stolon-proxy /usr/local/bin/stolonctl

View File

@ -1,9 +0,0 @@
FROM postgres:${PGVERSION}
RUN useradd -ms /bin/bash stolon
EXPOSE 5432
ADD bin/stolon-keeper bin/stolon-sentinel bin/stolon-proxy bin/stolonctl /usr/local/bin/
RUN chmod +x /usr/local/bin/stolon-keeper /usr/local/bin/stolon-sentinel /usr/local/bin/stolon-proxy /usr/local/bin/stolonctl

View File

@ -27,10 +27,11 @@ touch $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
sudo -E minikube start --vm-driver=none
make PGVERSION=10 TAG=stolon:master-pg10 docker
## Temporary hack disable checksum verification since semaphore has go 1.11.0 that had a bug causing different checksums than the right one generated by go 1.11.2
rm go.sum
make PGVERSION=10 TAG=stolon:master-pg10 docker
make
./bin/stolonctl --cluster-name kube-stolon --store-backend kubernetes --kube-resource-kind configmap init -y