Skip to content

Commit 3c645ce

Browse files
committed
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...).
1 parent 18a8ca1 commit 3c645ce

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ stolonctl:
3737
CGO_ENABLED=0 GO111MODULE=on go build -ldflags $(LD_FLAGS) -o $(PROJDIR)/bin/stolonctl $(REPO_PATH)/cmd/stolonctl
3838

3939
.PHONY: docker
40-
docker: build
40+
docker:
4141
if [ -z $${PGVERSION} ]; then echo 'PGVERSION is undefined'; exit 1; fi; \
4242
if [ -z $${TAG} ]; then echo 'TAG is undefined'; exit 1; fi; \
43-
export TEMPFILE="$$(mktemp)"; \
44-
sed -e "s/\$${PGVERSION}/$${PGVERSION}/" examples/kubernetes/image/docker/Dockerfile.template > $${TEMPFILE}; \
45-
docker build -t $${TAG} -f $${TEMPFILE} .
43+
docker build --build-arg PGVERSION=${PGVERSION} -t ${TAG} -f examples/kubernetes/image/docker/Dockerfile .
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
ARG PGVERSION
2+
3+
# base build image
4+
FROM golang:1.13-buster AS build_base
5+
6+
WORKDIR /stolon
7+
8+
# only copy go.mod and go.sum
9+
COPY go.mod .
10+
COPY go.sum .
11+
12+
RUN go mod download
13+
14+
#######
15+
####### Build the stolon binaries
16+
#######
17+
FROM build_base AS builder
18+
19+
# copy all the sources
20+
COPY . .
21+
22+
RUN make
23+
24+
#######
25+
####### Build the final image
26+
#######
27+
FROM postgres:$PGVERSION
28+
29+
RUN useradd -ms /bin/bash stolon
30+
31+
EXPOSE 5432
32+
33+
# copy the agola-web dist
34+
COPY --from=builder /stolon/bin/ /usr/local/bin
35+
36+
RUN chmod +x /usr/local/bin/stolon-keeper /usr/local/bin/stolon-sentinel /usr/local/bin/stolon-proxy /usr/local/bin/stolonctl

examples/kubernetes/image/docker/Dockerfile.template

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/semaphore-k8s.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ touch $HOME/.kube/config
2727
export KUBECONFIG=$HOME/.kube/config
2828
sudo -E minikube start --vm-driver=none
2929

30+
make PGVERSION=10 TAG=stolon:master-pg10 docker
31+
3032
## 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
3133
rm go.sum
32-
33-
make PGVERSION=10 TAG=stolon:master-pg10 docker
34+
make
3435

3536
./bin/stolonctl --cluster-name kube-stolon --store-backend kubernetes --kube-resource-kind configmap init -y
3637

0 commit comments

Comments
 (0)