Skip to content

Commit 6fd472c

Browse files
committed
Use multi-stage Docker to download restic
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 6fd86e8 commit 6fd472c

4 files changed

Lines changed: 54 additions & 11 deletions

File tree

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@ _testmain.go
3131

3232
/bin
3333
/.go
34-
/.push-*
35-
/.container-*
36-
/.dockerfile-*
37-
/.idea

Dockerfile.dbg

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
FROM debian:stretch
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
ENV DEBCONF_NONINTERACTIVE_SEEN true
5+
6+
RUN set -x \
7+
&& apt-get update \
8+
&& apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl bzip2
9+
10+
RUN set -x \
11+
&& curl -Lo restic.bz2 https://github.com/restic/restic/releases/download/v{RESTIC_VER}/restic_{RESTIC_VER}_{ARG_OS}_{ARG_ARCH}.bz2 \
12+
&& bzip2 -d restic.bz2 \
13+
&& chmod 755 restic \
14+
&& curl -Lo restic_{NEW_RESTIC_VER}.bz2 https://github.com/restic/restic/releases/download/v{NEW_RESTIC_VER}/restic_{NEW_RESTIC_VER}_{ARG_OS}_{ARG_ARCH}.bz2 \
15+
&& bzip2 -d restic_{NEW_RESTIC_VER}.bz2 \
16+
&& chmod 755 restic_{NEW_RESTIC_VER}
17+
18+
19+
120
FROM {ARG_FROM}
221

3-
ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
22+
COPY --from=0 restic /bin/restic
23+
COPY --from=0 restic_{NEW_RESTIC_VER} /bin/restic_{NEW_RESTIC_VER}
24+
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
425

526
ENTRYPOINT ["/{ARG_BIN}"]

Dockerfile.in

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
FROM debian:stretch
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
ENV DEBCONF_NONINTERACTIVE_SEEN true
5+
6+
RUN set -x \
7+
&& apt-get update \
8+
&& apt-get install -y --no-install-recommends apt-transport-https ca-certificates curl bzip2
9+
10+
RUN set -x \
11+
&& curl -Lo restic.bz2 https://github.com/restic/restic/releases/download/v{RESTIC_VER}/restic_{RESTIC_VER}_{ARG_OS}_{ARG_ARCH}.bz2 \
12+
&& bzip2 -d restic.bz2 \
13+
&& chmod 755 restic \
14+
&& curl -Lo restic_{NEW_RESTIC_VER}.bz2 https://github.com/restic/restic/releases/download/v{NEW_RESTIC_VER}/restic_{NEW_RESTIC_VER}_{ARG_OS}_{ARG_ARCH}.bz2 \
15+
&& bzip2 -d restic_{NEW_RESTIC_VER}.bz2 \
16+
&& chmod 755 restic_{NEW_RESTIC_VER}
17+
18+
119
FROM {ARG_FROM}
220

3-
ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
21+
COPY --from=0 /restic /bin/restic
22+
COPY --from=0 /restic_{NEW_RESTIC_VER} /bin/restic_{NEW_RESTIC_VER}
23+
COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
424

525
# This would be nicer as `nobody:nobody` but distroless has no such entries.
626
USER 65535:65535

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ else
2727
endif
2828
endif
2929

30+
RESTIC_VER := 0.8.3
31+
# also update in restic wrapper library
32+
NEW_RESTIC_VER := 0.9.5
33+
3034
###
3135
### These variables should not need tweaking.
3236
###
@@ -176,11 +180,13 @@ DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG)
176180
container: bin/.container-$(DOTFILE_IMAGE)-PROD bin/.container-$(DOTFILE_IMAGE)-DBG
177181
bin/.container-$(DOTFILE_IMAGE)-%: bin/$(OS)_$(ARCH)/$(BIN) $(DOCKERFILE_%)
178182
@echo "container: $(IMAGE):$(TAG_$*)"
179-
@sed \
180-
-e 's|{ARG_BIN}|$(BIN)|g' \
181-
-e 's|{ARG_ARCH}|$(ARCH)|g' \
182-
-e 's|{ARG_OS}|$(OS)|g' \
183-
-e 's|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
183+
@sed \
184+
-e 's|{ARG_BIN}|$(BIN)|g' \
185+
-e 's|{ARG_ARCH}|$(ARCH)|g' \
186+
-e 's|{ARG_OS}|$(OS)|g' \
187+
-e 's|{ARG_FROM}|$(BASEIMAGE_$*)|g' \
188+
-e 's|{RESTIC_VER}|$(RESTIC_VER)|g' \
189+
-e 's|{NEW_RESTIC_VER}|$(NEW_RESTIC_VER)|g' \
184190
$(DOCKERFILE_$*) > bin/.dockerfile-$*-$(OS)_$(ARCH)
185191
@docker build -t $(IMAGE):$(TAG_$*) -f bin/.dockerfile-$*-$(OS)_$(ARCH) .
186192
@docker images -q $(IMAGE):$(TAG_$*) > $@

0 commit comments

Comments
 (0)