Skip to content

Commit 7e1c06a

Browse files
authored
[skip ci] faster local docker image building using buildah (#1349)
buildah-based docker image building for faster local development buildah-compile.sh compiles wire-server inside an alpine-based container based on quay.io/wire/alpine-builder. the tool 'buildah' is used to mount some folders in, and to keep the stack caches of .stack and .stack-work (renamed to avoid conflicts) for the next compilation After compilation, ./buildah-make-images.sh can be used to bake individual executables into their respective docker images used by kubernetes. Usage: just run 'make buildah-docker' which will compile and upload images to quay.io under the docker tag $USER by default.
1 parent cb51b01 commit 7e1c06a

File tree

8 files changed

+119
-0
lines changed

8 files changed

+119
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ hie.yaml
8787

8888
# generated files under .local
8989
.local
90+
91+
# buildah-based docker image building
92+
.stack-root-buildah/
93+
.stack-work-buildah/
94+
dist-buildah

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CHARTS_INTEGRATION := wire-server databases-ephemeral fake-aws
1515
# this list could be generated from the folder names under ./charts/ like so:
1616
# CHARTS_RELEASE := $(shell find charts/ -maxdepth 1 -type d | xargs -n 1 basename | grep -v charts)
1717
CHARTS_RELEASE := wire-server databases-ephemeral fake-aws aws-ingress backoffice calling-test demo-smtp elasticsearch-curator elasticsearch-external fluent-bit minio-external cassandra-external nginx-ingress-controller nginx-ingress-services reaper wire-server-metrics sftd
18+
BUILDAH_PUSH ?= 1
1819

1920
default: fast
2021

@@ -340,3 +341,12 @@ upload-charts: charts-release
340341
.PHONY: echo-release-charts
341342
echo-release-charts:
342343
@echo ${CHARTS_RELEASE}
344+
345+
.PHONY: buildah-docker
346+
buildah-docker:
347+
./hack/bin/buildah-compile.sh
348+
BUILDAH_PUSH=${BUILDAH_PUSH} ./hack/bin/buildah-make-images.sh
349+
350+
.PHONY: buildah-clean
351+
buildah-clean:
352+
./hack/bin/buildah-clean.sh

docs/developer/dependencies.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ telepresence --namespace "$NAMESPACE" --also-proxy cassandra-ephemeral --run bas
215215
216216
In both cases, you need to adjust the various integration configuration files and names so that this can work.
217217
218+
## Buildah (optional)
219+
220+
[Buildah](https://buildah.io/) is used for local docker image creation during development. See [buildah installation](https://github.com/containers/buildah/blob/master/install.md)
221+
222+
See `make buildah-docker` for an entry point here.
223+
218224
## Helm chart development, integration tests in kubernetes
219225
220226
You need `kubectl`, `helm`, and a valid kubernetes context. Refer to https://docs.wire.com for details.

hack/bin/buildah-clean.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
TOP_LEVEL="$(cd "$DIR/../.." && pwd)"
6+
7+
# Note: keep these paths in sync with the paths/names used in the other buildah-* scripts.
8+
rm -rf "$TOP_LEVEL"/dist-buildah
9+
rm -rf "$TOP_LEVEL"/.stack-root-buildah
10+
rm -rf "$TOP_LEVEL"/.stack-work-buildah
11+
buildah rm wire-server-dev
12+
buildah rm output

hack/bin/buildah-compile.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
# This compiles wire-server inside an alpine-based container based on quay.io/wire/alpine-builder.
4+
# the tool 'buildah' is used to mount some folders in, and to
5+
# keep the stack caches of .stack and .stack-work (renamed to avoid conflicts) for the next compilation
6+
7+
# After compilation, ./buildah-make-images.sh can be used
8+
# to bake individual executables into their respective docker images used by kubernetes.
9+
10+
set -ex
11+
12+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13+
TOP_LEVEL="$(cd "$DIR/../.." && pwd)"
14+
15+
# Note: keep the following names and paths in sync with the other buildah-* scripts.
16+
mkdir -p "$TOP_LEVEL"/.stack-root-buildah
17+
mkdir -p "$TOP_LEVEL"/.stack-work-buildah
18+
mkdir -p "$TOP_LEVEL"/dist-buildah
19+
CONTAINER_NAME=wire-server-dev
20+
21+
# check for the existence of; or create a working container
22+
buildah containers | awk '{print $5}' | grep "$CONTAINER_NAME" \
23+
|| buildah from --name "$CONTAINER_NAME" -v "${TOP_LEVEL}":/src --pull quay.io/wire/alpine-builder:develop
24+
25+
# The first time round, we want to copy the .stack folder from the alpine-builder for future use. Afterwards, we want to re-use the "dirty" stack root folder.
26+
# Current check hinges on the existence of a config file, and hardcodes some paths
27+
ls "$TOP_LEVEL/.stack-root-buildah/config.yaml" 2> /dev/null \
28+
|| buildah run "$CONTAINER_NAME" -- cp -a /root/.stack/. /src/.stack-root-buildah/
29+
30+
buildah run "$CONTAINER_NAME" -- /src/hack/bin/buildah-inside.sh

hack/bin/buildah-inside.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is meant to be run from inside a buildah container. See buildah-compile.sh for details.
4+
5+
set -e
6+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
TOP_LEVEL="$(cd "$DIR/../.." && pwd)"
8+
9+
cd "$TOP_LEVEL"
10+
stack install . --local-bin-path=dist-buildah --work-dir=.stack-work-buildah --stack-root="${TOP_LEVEL}"/.stack-root-buildah --fast

hack/bin/buildah-make-images.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
TOP_LEVEL="$(cd "$DIR/../.." && pwd)"
7+
8+
# FUTUREWORK: Define this list in the makefile to allow overriding
9+
EXECUTABLES="cannon brig cargohold galley gundeck federator brig-index brig-schema galley-schema galley-migrate-data gundeck-schema proxy spar spar-schema"
10+
CONTAINER_NAME="output"
11+
DOCKER_TAG=${DOCKER_TAG:-$USER}
12+
13+
buildah containers | awk '{print $5}' | grep "$CONTAINER_NAME" \
14+
|| buildah from --name "$CONTAINER_NAME" -v "${TOP_LEVEL}":/src --pull quay.io/wire/alpine-deps:develop
15+
16+
# Only brig needs these templates, but for simplicity we add them to all resulting images (optimization FUTUREWORK)
17+
buildah run "$CONTAINER_NAME" -- sh -c 'mkdir -p /usr/share/wire/templates && cp -r "/src/services/brig/deb/opt/brig/templates" "/usr/share/wire/templates"'
18+
19+
for EX in $EXECUTABLES; do
20+
# Copy the main executable into the PATH on the container
21+
buildah run "$CONTAINER_NAME" -- cp "/src/dist/$EX" "/usr/bin/$EX"
22+
23+
# Start that executable by default when launching the docker image
24+
buildah config --entrypoint "[ \"/usr/bin/dumb-init\", \"--\", \"/usr/bin/$EX\" ]" "$CONTAINER_NAME"
25+
buildah config --cmd null "$CONTAINER_NAME"
26+
27+
# Bake an image
28+
buildah commit "$CONTAINER_NAME" quay.io/wire/"$EX":"$DOCKER_TAG"
29+
30+
# remove executable from the image in preparation for the next iteration
31+
buildah run "$CONTAINER_NAME" -- rm "/usr/bin/$EX"
32+
done
33+
34+
if [[ $BUILDAH_PUSH -eq 1 ]]; then
35+
for EX in $EXECUTABLES; do
36+
buildah push "quay.io/wire/$EX:$DOCKER_TAG"
37+
done
38+
fi
39+
40+
"$DIR/buildah-purge-untagged.sh"

hack/bin/buildah-purge-untagged.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# Remove untagged images (if there are any) in the buildah store
4+
if buildah images | grep "<none>"; then
5+
buildah images | grep "<none>" | awk '{print $3}' | xargs -n 1 buildah rmi
6+
fi

0 commit comments

Comments
 (0)