Skip to content

Commit 0894ff1

Browse files
committed
adding build script to extract stack resources
Signed-off-by: Michael Hoang <[email protected]>
1 parent b136d19 commit 0894ff1

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

.ci/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ COPY build-tools /build-tools
2727
COPY index/ /index
2828
COPY tests/registry /registry
2929

30+
# Download all the offline parent devfiles
31+
RUN bash /build-tools/dl_parent_devfiles.sh
32+
3033
# Download offline starter projects
3134
RUN bash /build-tools/dl_starter_projects.sh go-starter community
3235

build-tools/dl_parent_devfiles.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
# Path of stacks directory in the registry
4+
STACKS_DIR=${STACKS_DIR:-/registry/stacks}
5+
6+
# Downloads the parent devfile to be used as an offline resource
7+
download_parent_devfile() {
8+
local stack_root=$1
9+
local name=$2
10+
local parent_devfile_uri=$3
11+
parent_devfile=${name}-parent.devfile.yaml
12+
13+
if [ ! -f $stack_root/$parent_devfile ]; then
14+
curl -L $parent_devfile_uri -o $stack_root/$parent_devfile || return 1
15+
fi
16+
}
17+
18+
# Updates the uri to the downloaded offline parent devfile
19+
replace_parent_devfile() {
20+
local stack_root=$1
21+
local name=$2
22+
local parent_devfile_uri=$3
23+
stack_devfile=$stack_root/devfile.yaml
24+
parent_devfile=../${name}-parent.devfile.yaml
25+
26+
if [ -f $stack_root/$parent_devfile ]; then
27+
export PARENT_DEVFILE=$parent_devfile
28+
yq e -i ".parent.uri=env(PARENT_DEVFILE)" $stack_devfile
29+
fi
30+
}
31+
32+
download_and_replace() {
33+
for stack in ${stacks[@]}
34+
do
35+
if [ $stack == "OWNERS" ]; then
36+
continue
37+
fi
38+
stack_root=$STACKS_DIR/$stack
39+
stack_devfile=$stack_root/devfile.yaml
40+
# Read version list for stack
41+
versions=($([ -f ${STACKS_DIR}/${stack}/stack.yaml ] && yq e '.versions.[].version' ${STACKS_DIR}/${stack}/stack.yaml))
42+
# Multi version stack
43+
if [[ ${#versions[@]} -gt 0 ]]
44+
then
45+
for version in ${versions[@]}
46+
do
47+
stack_root=$STACKS_DIR/$stack/$version
48+
stack_devfile=$stack_root/devfile.yaml
49+
name="$(yq e ".metadata.name" $stack_devfile)"
50+
parent_devfile_uri="$(yq e ".parent.uri" $stack_devfile)"
51+
52+
if [ "$parent_devfile_uri" != "null" ]
53+
then
54+
echo "Downloading parent devfile in stack ${stack} version ${version}.."
55+
download_parent_devfile $stack_root $name $parent_devfile_uri
56+
if [ $? -eq 0 ]; then
57+
replace_parent_devfile $stack_root $name $parent_devfile_uri
58+
fi
59+
echo "Downloading parent devfile in stack ${stack} version ${version}..done!"
60+
fi
61+
done
62+
# Not a multi version stack
63+
else
64+
name="$(yq e ".metadata.name" $stack_devfile)"
65+
parent_devfile_uri="$(yq e ".parent.uri" $stack_devfile)"
66+
67+
if [ "$parent_devfile_uri" != "null" ]
68+
then
69+
echo "Downloading parent devfile in stack ${stack}.."
70+
download_parent_devfile $stack_root $name $parent_devfile_uri
71+
if [ $? -eq 0 ]; then
72+
replace_parent_devfile $stack_root $name $parent_devfile_uri
73+
fi
74+
echo "Downloading parent devfile in stack ${stack}..done!"
75+
fi
76+
fi
77+
done
78+
}
79+
80+
# Read stacks list
81+
read -r -a stacks <<< "$(ls ${STACKS_DIR} | tr '\n' ' ')"
82+
83+
echo "Downloading parent devfiles.."
84+
download_and_replace
85+
echo "Downloading parent devfiles..done!"

build-tools/extract_resources.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Path of stacks directory in the registry
4+
STACKS_DIR=${STACKS_DIR:-/build/stacks}
5+
6+
extract() {
7+
local stack_root=$1
8+
if [[ -f "$stack_root/archive.tar" ]]
9+
then
10+
tar -xf "$stack_root/archive.tar" -C "$stack_root"
11+
echo "Successfully extracted archive.tar"
12+
else
13+
echo "Skipping... no archive.tar found"
14+
fi
15+
}
16+
17+
registry=$1
18+
19+
read -r -a stacks <<< "$(ls ${STACKS_DIR} | tr '\n' ' ')"
20+
21+
for stack in ${stacks[@]}
22+
do
23+
stack_root=$STACKS_DIR/$stack
24+
stack_archive=$stack_root/archive.tar
25+
26+
# Read version list for stack
27+
versions=($([ -f ${STACKS_DIR}/${stack}/stack.yaml ] && yq e '.versions.[].version' ${STACKS_DIR}/${stack}/stack.yaml))
28+
29+
# Multi version stack
30+
if [[ ${#versions[@]} -gt 0 ]]
31+
then
32+
for version in ${versions[@]}
33+
do
34+
echo "Extracting archive.tar in stack ${stack} version ${version}.."
35+
extract "$stack_root/$version"
36+
done
37+
# Not a multi version
38+
else
39+
echo "Extracting archive.tar in stack ${stack}.."
40+
extract $stack_root
41+
fi
42+
done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
schemaVersion: 2.2.0
2+
metadata:
3+
description: "Go is an open source programming language that makes it easy to build simple, reliable, and efficient software."
4+
displayName: Go Runtime
5+
icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg
6+
name: go
7+
projectType: Go
8+
provider: Red Hat
9+
language: Go
10+
tags:
11+
- Go
12+
version: 2.1.0
13+
parent:
14+
uri: https://registry.devfile.io/devfiles/go/2.1.0

tests/registry/stacks/go/stack.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ versions:
77
- version: 1.2.0
88
default: true # should have one and only one default version
99
- version: 2.0.0
10+
- version: 2.1.0

0 commit comments

Comments
 (0)