-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclone-and-build.sh
executable file
·66 lines (53 loc) · 1.56 KB
/
clone-and-build.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
source ${1:-input.env}
SCRIPT_DIR=$(pwd)
TMP_DIR=$(mktemp -d "/tmp/cachi2.play.XXXXXXXXXX")
set -ex
# clone source code
cd $TMP_DIR
git clone "$GIT_REPO" sources
cd sources
git checkout "$REF"
cd ..
mkdir output
# prefetch dependencies
podman run --rm \
-v $(realpath ./sources):/tmp/sources:z \
-v $(realpath ./output):/tmp/output:z \
"$CACHI2_IMAGE" \
--log-level "DEBUG" \
fetch-deps "$PREFETCH_INPUT" \
--source "/tmp/sources" \
--output "/tmp/output" \
--dev-package-managers
# generate environmnent variables
podman run --rm \
-v $(realpath ./sources):/tmp/sources:z \
-v $(realpath ./output):/tmp/output:z \
"$CACHI2_IMAGE" \
generate-env /tmp/output \
--format env \
--output /tmp/output/cachi2.env
mv ./output/cachi2.env .
# inject project files
podman run --rm \
-v $(realpath ./sources):/tmp/sources:z \
-v $(realpath ./output):/tmp/output:z \
"$CACHI2_IMAGE" \
inject-files /tmp/output
# use the cachi2 env variables in all RUN instructions in the Containerfile
sed -i 's|^\s*run |RUN . /tmp/cachi2.env \&\& \\\n |i' "./sources/$CONTAINERFILE_PATH"
# in case RPMs for x86_64 were prefetched, mount the repofiles during the container build
if [ -d "./output/deps/rpm/x86_64/repos.d" ]; then
echo "rpms found"
MOUNT_RPM_REPOS="-v $(realpath ./output/deps/rpm/x86_64/repos.d):/etc/yum.repos.d"
fi
# build hermetically
podman build -t "$OUTPUT_IMAGE" \
-v $(realpath ./output):/tmp/output:Z \
-v $(realpath ./cachi2.env):/tmp/cachi2.env \
$MOUNT_RPM_REPOS \
--no-cache \
--network=none \
-f "./sources/$CONTAINERFILE_PATH" \
sources