Skip to content

Commit

Permalink
Fix up docker build scripts (linkerd#6781)
Browse files Browse the repository at this point in the history
A few small improvements to our docker build scripts:

* Centralized the list of docker images to a DOCKER_IMAGES variable defined in _docker.sh
* Build scripts now honor the TAG variable, if defined
* Unused docker-images script has been removed

We also update the `--control-plane-version` Linkerd install flag to affect the policy controller version as well.

Taken together, this enables the following workflow for building and deploying changes to individual Linkerd components.  For example, suppose you wish to deploy changes which only affect the controller image:

```console
# Begin by building all images at main with a dev tag
> TAG=alex-dev bin/docker-build

# OR begin by retagging all images from a recent release
> bin/docker-retag-all edge-21.8.4 alex-dev

# Make changes and then rebuild specific component
> TAG=alex-dev bin/docker-build-controller

# Load images into kind
> TAG=alex-dev bin/image-load --kind --cluster alex

# Install Linkerd
> bin/linkerd install --control-plane-version alex-dev --proxy-version alex-dev | k apply -f -
```

Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong authored Sep 1, 2021
1 parent ecd3970 commit 8f15683
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 91 deletions.
16 changes: 16 additions & 0 deletions bin/_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ export DOCKER_PUSH=${DOCKER_PUSH:-}
# Default supported docker image architectures
export SUPPORTED_ARCHS=${SUPPORTED_ARCHS:-linux/amd64,linux/arm64,linux/arm/v7}

# Splitting of DOCKER_IMAGES variable is desired.
# shellcheck disable=SC2206
export DOCKER_IMAGES=(${DOCKER_IMAGES:-
cli-bin
cni-plugin
controller
policy-controller
metrics-api
debug
grafana
proxy
web
jaeger-webhook
tap
})

docker_repo() {
repo=$1

Expand Down
7 changes: 3 additions & 4 deletions bin/docker-build-cli-bin
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh

dockerfile=$rootdir/cli/Dockerfile
tag=$(head_root_tag)

# shellcheck disable=SC2046
docker_build cli-bin "$tag" "$dockerfile" \
--build-arg LINKERD_VERSION="$tag" \
docker_build cli-bin "${TAG:-$(head_root_tag)}" "$dockerfile" \
--build-arg LINKERD_VERSION="${TAG:-$(head_root_tag)}" \
--target="$DOCKER_TARGET"

IMG=$(docker_repo cli-bin):$tag
IMG=$(docker_repo cli-bin):${TAG:-$(head_root_tag)}
ID=$(docker create "$IMG")

# copy the newly built linkerd cli binaries to the local system
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-build-cni-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ rootdir=$( cd "$bindir"/.. && pwd )

dockerfile=$rootdir/cni-plugin/Dockerfile

docker_build cni-plugin "$(head_root_tag)" "$dockerfile"
docker_build cni-plugin "${TAG:-$(head_root_tag)}" "$dockerfile"
3 changes: 1 addition & 2 deletions bin/docker-build-controller
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh

dockerfile=$rootdir/controller/Dockerfile
tag=$(head_root_tag)
docker_build controller "$tag" "$dockerfile" --build-arg LINKERD_VERSION="$tag"
docker_build controller "${TAG:-$(head_root_tag)}" "$dockerfile" --build-arg LINKERD_VERSION="${TAG:-$(head_root_tag)}"
2 changes: 1 addition & 1 deletion bin/docker-build-debug
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ rootdir=$( cd "$bindir"/.. && pwd )

dockerfile=$rootdir/Dockerfile-debug

docker_build debug "$(head_root_tag)" "$dockerfile"
docker_build debug "${TAG:-$(head_root_tag)}" "$dockerfile"
2 changes: 1 addition & 1 deletion bin/docker-build-grafana
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ rootdir=$( cd "$bindir"/.. && pwd )

dockerfile=$rootdir/grafana/Dockerfile

docker_build grafana "$(head_root_tag)" "$dockerfile"
docker_build grafana "${TAG:-$(head_root_tag)}" "$dockerfile"
3 changes: 1 addition & 2 deletions bin/docker-build-jaeger-webhook
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh

dockerfile=$rootdir/jaeger/injector/Dockerfile
tag=$(head_root_tag)
docker_build jaeger-webhook "$tag" "$dockerfile" --build-arg LINKERD_VERSION="$tag"
docker_build jaeger-webhook "${TAG:-$(head_root_tag)}" "$dockerfile" --build-arg LINKERD_VERSION="${TAG:-$(head_root_tag)}"

3 changes: 1 addition & 2 deletions bin/docker-build-metrics-api
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh

dockerfile=$rootdir/viz/metrics-api/Dockerfile
tag=$(head_root_tag)
docker_build metrics-api "$tag" "$dockerfile"
docker_build metrics-api "${TAG:-$(head_root_tag)}" "$dockerfile"

3 changes: 1 addition & 2 deletions bin/docker-build-policy-controller
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ if [ "$DOCKER_TARGET" = 'multi-arch' ]; then
exit 1
fi

tag=$(head_root_tag)
ROOTDIR=$( cd "$bindir"/../policy-controller && pwd )
docker_build policy-controller "$tag" "$ROOTDIR/amd64.dockerfile"
docker_build policy-controller "${TAG:-$(head_root_tag)}" "$ROOTDIR/amd64.dockerfile"
5 changes: 2 additions & 3 deletions bin/docker-build-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ get_extra_options() {
echo "$options"
}

tag=$(head_root_tag)
# We want wordsplit for the extra options here:
# shellcheck disable=SC2046
docker_build proxy "$tag" "$dockerfile" \
--build-arg "LINKERD_VERSION=$tag" \
docker_build proxy "${TAG:-$(head_root_tag)}" "$dockerfile" \
--build-arg "LINKERD_VERSION=${TAG:-$(head_root_tag)}" \
$(get_extra_options)
3 changes: 1 addition & 2 deletions bin/docker-build-tap
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh

dockerfile=$rootdir/viz/tap/Dockerfile
tag=$(head_root_tag)
docker_build tap "$tag" "$dockerfile"
docker_build tap "${TAG:-$(head_root_tag)}" "$dockerfile"
3 changes: 1 addition & 2 deletions bin/docker-build-web
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ rootdir=$( cd "$bindir"/.. && pwd )
. "$bindir"/_tag.sh

dockerfile=$rootdir/web/Dockerfile
tag=$(head_root_tag)
docker_build web "$tag" "$dockerfile" --build-arg LINKERD_VERSION="$tag"
docker_build web "${TAG:-$(head_root_tag)}" "$dockerfile" --build-arg LINKERD_VERSION="${TAG:-$(head_root_tag)}"
23 changes: 0 additions & 23 deletions bin/docker-images

This file was deleted.

4 changes: 2 additions & 2 deletions bin/docker-pull
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
# shellcheck source=_docker.sh
. "$bindir"/_docker.sh

for img in cli-bin cni-plugin controller metrics-api debug grafana proxy web jaeger-webhook tap; do
docker_pull $img "$tag"
for img in "${DOCKER_IMAGES[@]}"; do
docker_pull "$img" "$tag"
done
4 changes: 2 additions & 2 deletions bin/docker-push
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
# shellcheck source=_docker.sh
. "$bindir"/_docker.sh

for img in cli-bin cni-plugin controller metrics-api debug grafana proxy web jaeger-webhook tap; do
docker_push $img "$tag"
for img in "${DOCKER_IMAGES[@]}"; do
docker_push "$img" "$tag"
done
5 changes: 2 additions & 3 deletions bin/docker-retag-all
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )

# shellcheck source=_docker.sh
. "$bindir"/_docker.sh

for img in cli-bin cni-plugin controller debug grafana proxy web ; do
docker_retag $img "$from" "$to"
for img in "${DOCKER_IMAGES[@]}" ; do
docker_retag "$img" "$from" "$to"
done
13 changes: 8 additions & 5 deletions bin/image-load
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ k3d=""
cluster=""
archive=""
preload=""
images_default=(proxy controller policy-controller web metrics-api grafana debug cni-plugin jaeger-webhook tap)
images=()

bindir=$( cd "${BASH_SOURCE[0]%/*}" && pwd )
# shellcheck source=_docker.sh
. "$bindir"/_docker.sh

usage() {
printf "Load into KinD/k3d the referred Linkerd images. If no images are specified all of them are loaded (%s)\n" "${images_default[*]}"
printf "Load into KinD/k3d the referred Linkerd images. If no images are specified all of them are loaded (%s)\n" "${DOCKER_IMAGES[*]}"
echo ""
echo "Usage:"
echo " bin/image-load [--kind] [--k3d] [--cluster name] [--preload] [--archive] [image] [image]..."
Expand All @@ -37,7 +40,7 @@ usage() {

while :
do
case $1 in
case ${1:-} in
-h|--help)
usage
exit 0
Expand All @@ -59,7 +62,7 @@ do
archive=1
;;
*)
if [ -z "$1" ]; then
if [ -z "${1:-}" ]; then
break
fi
if echo "$1" | grep -q '^-.*' ; then
Expand All @@ -73,7 +76,7 @@ do
done

if [ ${#images[@]} -eq 0 ]; then
images=("${images_default[@]}")
images=("${DOCKER_IMAGES[@]}")
fi

bindir=$( cd "${0%/*}" && pwd )
Expand Down
2 changes: 1 addition & 1 deletion bin/install-pr
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ then
fi
"$bindir"/image-load --"$distro" --archive --cluster "$cluster"
else
for image in cni-plugin controller debug grafana proxy web
for image in "${DOCKER_IMAGES[@]}"
do
image=$(docker load -i "image-archives/$image.tar" | sed 's/Loaded image: //')
docker push "$image"
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func testInstallOptionsNoCerts(ha bool) (*charts.Values, error) {
values.Proxy.Image.Version = installProxyVersion
values.DebugContainer.Image.Version = installDebugVersion
values.ControllerImageVersion = installControlPlaneVersion
values.PolicyController.Image.Version = installControlPlaneVersion
values.HeartbeatSchedule = fakeHeartbeatSchedule()

return values, nil
Expand All @@ -334,6 +335,7 @@ func testInstallValues() (*charts.Values, error) {
values.DebugContainer.Image.Version = installDebugVersion
values.LinkerdVersion = installControlPlaneVersion
values.ControllerImageVersion = installControlPlaneVersion
values.PolicyController.Image.Version = installControlPlaneVersion
values.HeartbeatSchedule = fakeHeartbeatSchedule()

identityCert, err := ioutil.ReadFile(filepath.Join("testdata", "valid-crt.pem"))
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func makeInstallUpgradeFlags(defaults *l5dcharts.Values) ([]flag.Flag, *pflag.Fl
"Tag to be used for the control plane component images",
func(values *l5dcharts.Values, value string) error {
values.ControllerImageVersion = value
values.PolicyController.Image.Version = value
return nil
}),
}
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/testdata/install_controlplane_tracing_output.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8f15683

Please sign in to comment.