Skip to content

Commit 24e9617

Browse files
committed
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 e9957d6 commit 24e9617

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,8 @@ upload-charts: charts-release
340340
.PHONY: echo-release-charts
341341
echo-release-charts:
342342
@echo ${CHARTS_RELEASE}
343+
344+
.PHONY: buildah-docker
345+
buildah-docker:
346+
./hack/bin/buildah-compile.sh
347+
BUILDAH_PUSH=1 ./hack/bin/buildah-make-images.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-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+
mkdir -p "$TOP_LEVEL"/.stack-root-buildah
16+
mkdir -p "$TOP_LEVEL"/.stack-work-buildah
17+
mkdir -p "$TOP_LEVEL"/dist-buildah
18+
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
EXECUTABLES="cannon brig cargohold galley gundeck federator brig-index brig-schema galley-schema galley-migrate-data gundeck-schema proxy spar spar-schema"
9+
CONTAINER_NAME="output"
10+
DOCKER_TAG=$USER
11+
12+
buildah containers | awk '{print $5}' | grep "$CONTAINER_NAME" \
13+
|| buildah from --name "$CONTAINER_NAME" -v "${TOP_LEVEL}":/src --pull quay.io/wire/alpine-deps:develop
14+
15+
# Only brig needs these templates, but for simplicity we add them to all resulting images (optimization FUTUREWORK)
16+
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"'
17+
18+
for EX in $EXECUTABLES; do
19+
# Copy the main executable into the PATH on the container
20+
buildah run "$CONTAINER_NAME" -- cp "/src/dist/$EX" "/usr/bin/$EX"
21+
22+
# Start that executable by default when launching the docker image
23+
buildah config --entrypoint "[ \"/usr/bin/dumb-init\", \"--\", \"/usr/bin/$EX\" ]" "$CONTAINER_NAME"
24+
buildah config --cmd null "$CONTAINER_NAME"
25+
26+
# Bake an image
27+
buildah commit "$CONTAINER_NAME" quay.io/wire/"$EX":"$DOCKER_TAG"
28+
29+
# remove executable from the image in preparation for the next iteration
30+
buildah run "$CONTAINER_NAME" -- rm "/usr/bin/$EX"
31+
done
32+
33+
if [[ $BUILDAH_PUSH -eq 1 ]]; then
34+
for EX in $EXECUTABLES; do
35+
buildah push "quay.io/wire/$EX:$DOCKER_TAG"
36+
done
37+
fi

0 commit comments

Comments
 (0)