-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathstart-buildkit.sh
More file actions
executable file
·31 lines (26 loc) · 1.01 KB
/
start-buildkit.sh
File metadata and controls
executable file
·31 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# This script MUST be sourced (i.e. use `source start-buildkit.sh`).
# Variable used by KraftKit, hence the requirement for sourcing the script
export KRAFTKIT_BUILDKIT_HOST=docker-container://buildkit
# Install container if not already installed.
if [ -n "$(docker ps --all --no-trunc --quiet --filter 'name=^buildkit$')" ]; then
echo "Container 'buildkit' is already installed. Nothing to do."
else
echo "Installing 'buildkit' container ... "
docker run -d --name buildkit --privileged moby/buildkit:latest
return $?
fi
if [ "$(docker container inspect -f '{{.State.Running}}' buildkit 2> /dev/null)" = "true" ]; then
echo "Container 'buildkit' is already running. Nothing to do."
else
echo "Starting 'buildkit' container ... "
docker start buildkit
return $?
fi
CACHE_ARGS=()
if [ -n "${CACHE_DIR:-}" ]; then
mkdir -p "$CACHE_DIR"
CACHE_ARGS+=(--cache-from type=local,src="$CACHE_DIR")
CACHE_ARGS+=(--cache-to type=local,dest="$CACHE_DIR",mode=max)
fi
export CACHE_ARGS