-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_image.sh
executable file
·48 lines (33 loc) · 1.87 KB
/
build_image.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -e
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR
# get the path to this script
MY_PATH=`dirname "$0"`
MY_PATH=`( cd "$MY_PATH" && pwd )`
cd ${MY_PATH}
## --------------------------------------------------------------
## | setup |
## --------------------------------------------------------------
source ./common_vars.sh
## --------------------------------------------------------------
## | build |
## --------------------------------------------------------------
# initialize the cache
[ ! -e ${CACHE_PATH}/${WORKSPACE_PATH} ] && mkdir -p ./${CACHE_PATH}/${WORKSPACE_PATH}
PASS_TO_DOCKER_BUILD="Dockerfile src ${CACHE_PATH}/${WORKSPACE_PATH}"
docker buildx use default
echo ""
echo "$0: building the user's workspace for $ARCH"
echo ""
# this first build compiles the contents of "src" and storest the intermediate
tar -czh $PASS_TO_DOCKER_BUILD 2>/dev/null | docker build - --pull=false --no-cache --target stage_cache_workspace --output ./${CACHE_PATH} --build-arg WORKSPACE_PATH=${WORKSPACE_PATH} --build-arg BASE_IMAGE=${BASE_IMAGE} --build-arg TRANSPORT_IMAGE=${TRANSPORT_IMAGE} --build-arg ARCH=${ARCH} --file Dockerfile --platform=linux/$ARCH
echo ""
echo "$0: packing the workspace into a docker image"
echo ""
# this second build takes the resulting workspace and storest in in a final image
# that can be deployed to a drone
docker build . --no-cache --target stage_finalization --file Dockerfile --build-arg WORKSPACE_PATH=${WORKSPACE_PATH} --build-arg BASE_IMAGE=${BASE_IMAGE} --build-arg TRANSPORT_IMAGE=${TRANSPORT_IMAGE} --build-arg ARCH=${ARCH} --tag $OUTPUT_IMAGE --platform=linux/$ARCH
echo ""
echo "$0: workspace was packed into '$OUTPUT_IMAGE'"
echo ""