Skip to content

Commit 3ddd742

Browse files
starter project downloader script for offline starter project testing added.
Signed-off-by: Michael Valdron <[email protected]>
1 parent 3816348 commit 3ddd742

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

.ci/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ COPY build-tools /build-tools
2121
COPY index/ /index
2222
COPY tests/registry /registry
2323

24+
# Download offline starter projects
25+
RUN bash /build-tools/dl_starter_projects.sh
26+
2427
# Run the registry build tools
2528
RUN /build-tools/build.sh /registry /build
2629

build-tools/dl_starter_projects.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Path of stacks directory in the registry
4+
STACKS_DIR=/registry/stacks
5+
# List of starter projects to use offline
6+
OFFLINE_STARTER_PROJECTS=("go-starter")
7+
8+
# Downloads a starter project from a remote git repository and packages it as a zip archive
9+
# to be used as an offline resource.
10+
download_git_starter_project() {
11+
stack_root=$1
12+
name=$2
13+
remote_url=$(yq e ".starterProjects[] | select(.name == \"${name}\").git.remotes.origin" $stack_root/devfile.yaml)
14+
15+
mkdir -p $stack_root/$name
16+
17+
git clone $remote_url $stack_root/$name
18+
19+
cd $stack_root/$name && rm -rf ./.git && zip -q $stack_root/$name.zip * .[^.]* && cd -
20+
21+
rm -rf $stack_root/$name
22+
}
23+
24+
# Downloads a starter project from a remote zip archive source
25+
# to be used as an offline resource.
26+
download_zip_starter_project() {
27+
stack_root=$1
28+
name=$2
29+
remote_url=$(yq e ".starterProjects[] | select(.name == \"${name}\").zip.location" $stack_root/devfile.yaml)
30+
31+
curl -L $remote_url -o $stack_root/$name.zip
32+
}
33+
34+
# Read stacks list
35+
read -r -a stacks <<< "$(ls ${STACKS_DIR} | tr '\n' ' ')"
36+
37+
echo "Downloading offline starter projects.."
38+
for starter_project in ${OFFLINE_STARTER_PROJECTS[@]}
39+
do
40+
for stack in ${stacks[@]}
41+
do
42+
stack_root=$STACKS_DIR/$stack
43+
stack_devfile=$stack_root/devfile.yaml
44+
# Read version list for stack
45+
read -r -a versions <<< "$(ls ${STACKS_DIR}/${stack} | grep -e '[0-9].[0-9].[0-9]' | tr '\n' ' ')"
46+
if [[ ${#versions[@]} -gt 0 ]]
47+
then
48+
for version in ${versions[@]}
49+
do
50+
stack_root=$STACKS_DIR/$stack/$version
51+
stack_devfile=$stack_root/devfile.yaml
52+
if [ ! -z "$(yq e ".starterProjects[] | select(.name == \"${starter_project}\")" $stack_devfile)" ]
53+
then
54+
if [ "$(yq e ".starterProjects[] | select(.name == \"${starter_project}\").git" $stack_devfile)" != "null" ]
55+
then
56+
echo "Downloading ${starter_project} starter project in stack ${stack} version ${version}.."
57+
download_git_starter_project $stack_root $starter_project
58+
echo "Downloading ${starter_project} starter project in stack ${stack} version ${version}..done!"
59+
elif [ "$(yq e ".starterProjects[] | select(.name == \"${starter_project}\").zip" $stack_devfile)" != "null" ]
60+
then
61+
echo "Downloading ${starter_project} starter project in stack ${stack} version ${version}.."
62+
download_zip_starter_project $stack_root $starter_project
63+
echo "Downloading ${starter_project} starter project in stack ${stack} version ${version}..done!"
64+
fi
65+
fi
66+
done
67+
elif [ ! -z "$(yq e ".starterProjects[] | select(.name == \"${starter_project}\")" $stack_devfile)" ]
68+
then
69+
if [ "$(yq e ".starterProjects[] | select(.name == \"${starter_project}\").git" $stack_devfile)" != "null" ]
70+
then
71+
echo "Downloading ${starter_project} starter project in stack ${stack}.."
72+
download_git_starter_project $stack_root $starter_project
73+
echo "Downloading ${starter_project} starter project in stack ${stack}..done!"
74+
elif [ "$(yq e ".starterProjects[] | select(.name == \"${starter_project}\").zip" $stack_devfile)" != "null" ]
75+
then
76+
echo "Downloading ${starter_project} starter project in stack ${stack}.."
77+
download_zip_starter_project $stack_root $starter_project
78+
echo "Downloading ${starter_project} starter project in stack ${stack}..done!"
79+
fi
80+
fi
81+
done
82+
done
83+
echo "Downloading offline starter projects..done!"

0 commit comments

Comments
 (0)