-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathbuild_devcontainer.sh
executable file
·67 lines (53 loc) · 2.28 KB
/
build_devcontainer.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
67
#!/bin/bash
# Define devcontainer configuration directory
devcontainer_dir=".devcontainer"
# Define configuration file path
config_file="devcontainer.json"
# Pass in values as parameters
# Example:
# ./build_devcontainer.sh stellar/vsc-soroban-examples-prebuild \
# stellar/vsc-soroban-examples-oci-prebuild ~/cache
pre_build_image=$1
oci_pre_build_image=$2
local_build_cache=$3
build_details_dir="z-dc-build-info/"
build_details_file="build-details.json"
if [ ! -e "${build_details_dir}" ]; then
mkdir -p "${build_details_dir}"
fi
if [ ! -e "${build_details_dir}${build_details_file}" ]; then
touch "${build_details_dir}${build_details_file}"
fi
# Build the devcontainer
output=$(devcontainer build \
--workspace-folder . \
--config $devcontainer_dir/$config_file \
--cache-from type=registry,ref="${pre_build_image}" \
--cache-from type=local,src="${local_build_cache}",mode=max \
--cache-to type=local,dest="${local_build_cache}",mode=max,oci-mediatypes=true,image-manifest=true \
--output type=image,name="${pre_build_image}")
echo " ✅ Devcontainer built"
# Extract imageName from JSON output using jq
image_name=$(echo "$output" | jq -r '.imageName[0]')
echo " 🔹 Image name: ${image_name}"
docker inspect "${image_name}" >> "${build_details_dir}${build_details_file}"
# Push new pre-build
docker tag "${image_name}":latest "${pre_build_image}":latest
docker push "${pre_build_image}":latest
echo " 🛠️ New prebuild pushed ${pre_build_image}:latest"
echo " ⚙️ Build info available at ${build_details_dir}${build_details_file}"
echo 'Y' | docker image prune
# Build the devcontainer again with OCI Output
oci_output=$(devcontainer build \
--workspace-folder . \
--config $devcontainer_dir/$config_file \
--cache-from type=registry,ref="${pre_build_image}" \
--cache-from type=registry,ref="${oci_pre_build_image}" \
--cache-to type=registry,ref="${oci_pre_build_image}",mode=max,oci-artifact=true \
--output type=image,name="${oci_pre_build_image}",mode=max,oci-mediatypes=true,compression=zstd)
# Extract ociImageName from JSON output using jq
oci_image_name=$(echo "$oci_output" | jq -r '.imageName[0]')
# Push new OCI pre-build
docker tag "${oci_image_name}":latest "${oci_pre_build_image}":latest
docker push "${oci_pre_build_image}":latest
echo 'Y' | docker image prune