Download restic binary outside container (#3327)

In #3310, the Dockerfile for the Tilt Velero container was modified to
call the `./hack/download-restic.sh` script. A side effect of this
change was that the context for the docker build was much larger as it
was the root of the Velero repo, rather than just the `_tiltbuild`
directory. With the frequent rebuilds of the image that happen when
using Tilt, a large amounts of disk space was being consumed by the
different layers of images builds in the Docker overlay filesystem (as
diffs could include the `.go` directory which can be several GBs).

This change modifies the `download-restic.sh` script to allow the output
directory for the restic binary to be configured. This means that the
script can be called directly from the Tiltfile and can be managed
outside the container build. This allows us to restore the previous
`_tiltbuild` context. It also speeds up image builds as we can download
restic once and use it for all builds rather than redownloading
frequently.

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
pull/3421/head
Bridget McErlean 2021-02-08 12:42:15 -05:00 committed by GitHub
parent 4823f49198
commit 65c16a1d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -72,15 +72,6 @@ COPY --from=tilt-helper /usr/bin/docker /usr/bin/docker
COPY --from=tilt-helper /go/kubernetes/client/bin/kubectl /usr/bin/kubectl
"""
docker_build_download_restic_commands = """
COPY ./hack/download-restic.sh /
RUN apt update && apt install -y wget
RUN mkdir -p /output/usr/bin && \
BIN=velero GOOS=linux GOARCH=amd64 RESTIC_VERSION=0.9.6 /download-restic.sh && \
mv /output/usr/bin/restic /usr/bin/restic && \
rm -rf /output/usr/bin
"""
##############################
# Setup Velero
##############################
@ -110,13 +101,19 @@ local_resource(
deps = ["internal", "pkg/cmd"],
)
local_resource(
"restic_binary",
cmd = 'cd ' + '.' + ';mkdir -p _tiltbuild/restic; BIN=velero GOOS=' + local_goos + ' GOARCH=amd64 RESTIC_VERSION=0.9.6 OUTPUT_DIR=_tiltbuild/restic ./hack/download-restic.sh',
)
# Note: we need a distro with a bash shell to exec into the Velero container
tilt_dockerfile_header = """
FROM ubuntu:focal as tilt
WORKDIR /
COPY --from=tilt-helper /start.sh .
COPY --from=tilt-helper /restart.sh .
COPY _tiltbuild/velero .
COPY velero .
COPY restic/restic /usr/bin/restic
"""
dockerfile_contents = "\n".join([
@ -124,10 +121,8 @@ dockerfile_contents = "\n".join([
additional_docker_helper_commands,
tilt_dockerfile_header,
additional_docker_build_commands,
docker_build_download_restic_commands,
])
def get_velero_entrypoint():
"""
Returns the entrypoint for the Velero container image.
@ -156,7 +151,7 @@ def get_velero_entrypoint():
# build into the container.
docker_build(
ref = "velero/velero",
context = ".",
context = "_tiltbuild",
dockerfile_contents = dockerfile_contents,
target = "tilt",
entrypoint = get_velero_entrypoint(),

View File

@ -18,6 +18,11 @@ set -o errexit
set -o nounset
set -o pipefail
# Use /output/usr/bin/ as the default output directory as this
# is the path expected by the Velero Dockerfile.
output_dir=${OUTPUT_DIR:-/output/usr/bin}
restic_bin=${output_dir}/restic
if [[ -z "${BIN}" ]]; then
echo "BIN must be set"
exit 1
@ -44,11 +49,11 @@ fi
# TODO: when the new restic version is released, make ppc64le to be also downloaded from their github releases.
# This has been merged and will be applied to next release: https://github.com/restic/restic/pull/2342
if [[ "${GOARCH}" = "ppc64le" ]]; then
wget --timeout=1 --tries=5 --quiet https://oplab9.parqtec.unicamp.br/pub/ppc64el/restic/restic-${RESTIC_VERSION} -O /output/usr/bin/restic
wget --timeout=1 --tries=5 --quiet https://oplab9.parqtec.unicamp.br/pub/ppc64el/restic/restic-${RESTIC_VERSION} -O ${restic_bin}
else
wget --quiet https://github.com/restic/restic/releases/download/v${RESTIC_VERSION}/restic_${RESTIC_VERSION}_${GOOS}_${GOARCH}.bz2
bunzip2 restic_${RESTIC_VERSION}_${GOOS}_${GOARCH}.bz2
mv restic_${RESTIC_VERSION}_${GOOS}_${GOARCH} /output/usr/bin/restic
mv restic_${RESTIC_VERSION}_${GOOS}_${GOARCH} ${restic_bin}
fi
chmod +x /output/usr/bin/restic
chmod +x ${restic_bin}