Skip to content

Commit 7541195

Browse files
committed
Add new scripts for building images
1 parent 6ca514b commit 7541195

File tree

5 files changed

+134
-9
lines changed

5 files changed

+134
-9
lines changed

.gitpod.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ tasks:
2020
command: |
2121
gp await-port 5000
2222
REPO=localhost:5000/dazzle
23-
echo "To build specific chunks and combinations 'time ./dazzle-up.sh -c chunk1 -c chunk2 -n combo'"
24-
echo "To build all the chunks and combinations 'time ./dazzle-up.sh'"
23+
echo "To build specific chunks and combine them 'time ./build-chunk.sh -c chunk1 -c chunk2 -n combo'"
24+
echo "To build all the chunks and combinations 'time ./build-all.sh'"
25+
echo "To build a specific combination 'time ./build-combo.sh combo'"
2526
echo "To list image chunks 'dazzle project image-name $REPO'"
2627
echo "To list hashes for image chunks 'dazzle project hash $REPO'"
2728
echo "To print the combined image maniest 'dazzle project manifest $REPO'"

CONTRIBUTING.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Here is a list of dependencies and tools:
3131

3232
## Locally
3333

34-
We ship a shell script [dazzle-up.sh](dazzle-up.sh) that can be used to build the images locally. See the following sub sections for usage.
34+
We ship a shell script [build-all.sh](build-all.sh) that can be used to build the images locally. See the following sub sections for usage.
3535

3636
This script will first build the chunks and run tests followed by creation of container images. It uses `dazzle` to perform these tasks.
3737

@@ -45,20 +45,30 @@ where `combo` is the name of the combination defined in [dazzle.yaml](dazzle.yam
4545

4646
### Build Specific Chunks
4747

48-
Often, you would want to test only the chunks that you modify. You can do that by using the `-c` flag.
48+
Often, you would want to test only the chunks that you modify. You can do that with build-chunk.sh using the `-c` flag and specifying the name for your combination with `n`.
4949

5050
```console
51-
./dazzle-up.sh -c lang-c -c dep-cacert-update -n mychangecombo
51+
./build-chunk.sh -c lang-c -c dep-cacert-update -n mychangecombo
5252
```
5353

5454
Above command will build only chunks `lang-c` and `dep-cacert-update` and combine the created chunks (all variants, if any exists) as a combination with name `mychangecombo`.
5555

56+
### Build Specific Combination
57+
58+
Sometimes you only want to build one specification combination e.g. the postgresql or the go image. You can do that with
59+
60+
```console
61+
./build-combo.sh <comboName e.g. go>
62+
```
63+
64+
This will build all chunks that are referenced by the go combination and then combine them to create the go image.
65+
5666
### Build All Chunks
5767

5868
Execute the following command to build using the default config `dazzle.yaml` shipped in this repo:
5969

6070
```bash
61-
./dazzle-up.sh
71+
./build-all.sh
6272
```
6373

6474
> **NOTE:** Building images locally consumes a lot of resources and is often slow.

build-all.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
REPO=localhost:5000/dazzle
5+
# First, build chunks without hashes
6+
dazzle build $REPO -v --chunked-without-hash
7+
# Second, build again, but with hashes
8+
dazzle build $REPO -v
9+
# Third, create combinations of chunks
10+
dazzle combine $REPO --all -v

dazzle-up.sh renamed to build-chunk.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ readonly REPO="localhost:5000/dazzle"
1313

1414
function usage() {
1515
cat <<EOF
16-
Usage: ./dazzle-up.sh [OPTION]...
17-
Example: ./dazzle-up.sh -c lang-c -c dep-cacert-update -n mychangecombo
16+
Usage: ./build-chunk.sh [OPTION]...
17+
Example: ./build-chunk.sh -c lang-c -c dep-cacert-update -n mychangecombo
1818
Options for build:
1919
-h, --help Display this help
2020
-c, --chunk Chunk to build, You can build multiple chunks: -c chunk1 -c chunk2. If no chunks are supplied then build using existing config
@@ -85,7 +85,7 @@ while true; do
8585
;;
8686
*)
8787
echo Error: unknown flag "$1"
88-
echo "${YELLOW}Run 'dazzle-up.sh --help' for usage.${NC}"
88+
echo "${YELLOW}Run 'build-chunk.sh --help' for usage.${NC}"
8989
exit 1
9090
;;
9191
esac

build-combo.sh

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#! /bin/bash
2+
set -eo pipefail
3+
trap ctrl_c INT
4+
5+
readonly YELLOW=$(tput setaf 3)
6+
readonly NC=$(tput sgr0)
7+
8+
readonly BACKUP_FILE=".dazzle.yaml.orig"
9+
readonly ORIGINAL_FILE="dazzle.yaml"
10+
11+
function save_original {
12+
if [ ! -f ${BACKUP_FILE} ]; then
13+
echo "${YELLOW}Creating a backup of ${ORIGINAL_FILE} as it does not exist yet...${NC}" && cp ${ORIGINAL_FILE} ${BACKUP_FILE}
14+
fi
15+
}
16+
17+
function restore_original() {
18+
echo "${YELLOW}Restoring backup file ${BACKUP_FILE} to original file ${ORIGINAL_FILE}${NC}"
19+
cp ${BACKUP_FILE} ${ORIGINAL_FILE}
20+
}
21+
22+
function ctrl_c() {
23+
echo "${YELLOW}** Trapped CTRL-C${NC}"
24+
restore_original
25+
}
26+
27+
function build_combination {
28+
combination=$1
29+
30+
local exists="$(yq e '.combiner.combinations[] | select (.name=="'"$combination"'")' dazzle.yaml)"
31+
if [[ -z "$exists" ]]; then
32+
echo "combination is not defined"
33+
exit 1
34+
fi
35+
36+
refs=$(get_refs "$combination")
37+
requiredChunks=$(get_chunks "$refs" | sort | uniq)
38+
availableChunks=$(get_available_chunks)
39+
40+
for ac in $availableChunks; do
41+
if [[ ! "${requiredChunks[*]}" =~ "${ac}" ]]; then
42+
dazzle project ignore "$ac"
43+
fi
44+
done
45+
}
46+
47+
function get_refs {
48+
local ref=$1
49+
echo "$ref"
50+
51+
refs="$(yq e '.combiner.combinations[] | select (.name=="'"$ref"'") | .ref[]' dazzle.yaml)"
52+
if [[ -z "$refs" ]]; then
53+
return
54+
fi
55+
56+
for ref in $refs; do
57+
get_refs "$ref"
58+
done
59+
}
60+
61+
function get_chunks {
62+
for ref in $@; do
63+
chunks=$(yq e '.combiner.combinations[] | select (.name=="'"$ref"'") | .chunks[]' dazzle.yaml)
64+
echo "$chunks"
65+
done
66+
}
67+
68+
function get_available_chunks {
69+
local chunk_defs=$(ls chunks)
70+
for chunk in $chunk_defs;do
71+
local chunkYaml="chunks/${chunk}/chunk.yaml"
72+
if [[ -f "$chunkYaml" ]]; then
73+
variants=$(yq e '.variants[].name' "$chunkYaml" )
74+
for variant in $variants; do
75+
echo "$chunk:$variant"
76+
done
77+
else
78+
echo "$chunk"
79+
fi
80+
81+
done
82+
}
83+
84+
REPO=localhost:5000/dazzle
85+
86+
save_original
87+
88+
if [ -n "${1}" ]; then
89+
build_combination "$1"
90+
fi
91+
92+
# First, build chunks without hashes
93+
dazzle build $REPO -v --chunked-without-hash
94+
# Second, build again, but with hashes
95+
dazzle build $REPO -v
96+
97+
# Third, create combinations of chunks
98+
if [[ -n "${1}" ]]; then
99+
dazzle combine $REPO --combination "$1" -v
100+
else
101+
dazzle combine $REPO --all -v
102+
fi
103+
104+
restore_original

0 commit comments

Comments
 (0)