forked from devfile/registry-support
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding build script to extract stack resources (devfile#180)
Signed-off-by: Michael Hoang <[email protected]>
- Loading branch information
1 parent
a807358
commit 049028b
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
|
||
# Path of stacks directory in the registry | ||
STACKS_DIR=${STACKS_DIR:-/registry/stacks} | ||
|
||
# Downloads the parent devfile to be used as an offline resource | ||
download_parent_devfile() { | ||
local stack_root=$1 | ||
local name=$2 | ||
local parent_devfile_uri=$3 | ||
parent_devfile=${name}-parent.devfile.yaml | ||
|
||
if [ ! -f $stack_root/$parent_devfile ]; then | ||
curl -L $parent_devfile_uri -o $stack_root/$parent_devfile || return 1 | ||
fi | ||
} | ||
|
||
# Updates the uri to the downloaded offline parent devfile | ||
replace_parent_devfile() { | ||
local stack_root=$1 | ||
local name=$2 | ||
local parent_devfile_uri=$3 | ||
stack_devfile=$stack_root/devfile.yaml | ||
parent_devfile=../${name}-parent.devfile.yaml | ||
|
||
if [ -f $stack_root/$parent_devfile ]; then | ||
export PARENT_DEVFILE=$parent_devfile | ||
yq e -i ".parent.uri=env(PARENT_DEVFILE)" $stack_devfile | ||
fi | ||
} | ||
|
||
download_and_replace() { | ||
for stack in ${stacks[@]} | ||
do | ||
if [ $stack == "OWNERS" ]; then | ||
continue | ||
fi | ||
stack_root=$STACKS_DIR/$stack | ||
stack_devfile=$stack_root/devfile.yaml | ||
# Read version list for stack | ||
versions=($([ -f ${STACKS_DIR}/${stack}/stack.yaml ] && yq e '.versions.[].version' ${STACKS_DIR}/${stack}/stack.yaml)) | ||
# Multi version stack | ||
if [[ ${#versions[@]} -gt 0 ]] | ||
then | ||
for version in ${versions[@]} | ||
do | ||
stack_root=$STACKS_DIR/$stack/$version | ||
stack_devfile=$stack_root/devfile.yaml | ||
name="$(yq e ".metadata.name" $stack_devfile)" | ||
parent_devfile_uri="$(yq e ".parent.uri" $stack_devfile)" | ||
|
||
if [ "$parent_devfile_uri" != "null" ] | ||
then | ||
echo "Downloading parent devfile in stack ${stack} version ${version}.." | ||
download_parent_devfile $stack_root $name $parent_devfile_uri | ||
if [ $? -eq 0 ]; then | ||
replace_parent_devfile $stack_root $name $parent_devfile_uri | ||
fi | ||
echo "Downloading parent devfile in stack ${stack} version ${version}..done!" | ||
fi | ||
done | ||
# Not a multi version stack | ||
else | ||
name="$(yq e ".metadata.name" $stack_devfile)" | ||
parent_devfile_uri="$(yq e ".parent.uri" $stack_devfile)" | ||
|
||
if [ "$parent_devfile_uri" != "null" ] | ||
then | ||
echo "Downloading parent devfile in stack ${stack}.." | ||
download_parent_devfile $stack_root $name $parent_devfile_uri | ||
if [ $? -eq 0 ]; then | ||
replace_parent_devfile $stack_root $name $parent_devfile_uri | ||
fi | ||
echo "Downloading parent devfile in stack ${stack}..done!" | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
# Read stacks list | ||
read -r -a stacks <<< "$(ls ${STACKS_DIR} | tr '\n' ' ')" | ||
|
||
echo "Downloading parent devfiles.." | ||
download_and_replace | ||
echo "Downloading parent devfiles..done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
# Path of stacks directory in the registry | ||
STACKS_DIR=${STACKS_DIR:-/build/stacks} | ||
|
||
extract() { | ||
local stack_root=$1 | ||
if [[ -f "$stack_root/archive.tar" ]] | ||
then | ||
tar -xf "$stack_root/archive.tar" -C "$stack_root" | ||
echo "Successfully extracted archive.tar" | ||
else | ||
echo "Skipping... no archive.tar found" | ||
fi | ||
} | ||
|
||
registry=$1 | ||
|
||
read -r -a stacks <<< "$(ls ${STACKS_DIR} | tr '\n' ' ')" | ||
|
||
for stack in ${stacks[@]} | ||
do | ||
stack_root=$STACKS_DIR/$stack | ||
stack_archive=$stack_root/archive.tar | ||
|
||
# Read version list for stack | ||
versions=($([ -f ${STACKS_DIR}/${stack}/stack.yaml ] && yq e '.versions.[].version' ${STACKS_DIR}/${stack}/stack.yaml)) | ||
|
||
# Multi version stack | ||
if [[ ${#versions[@]} -gt 0 ]] | ||
then | ||
for version in ${versions[@]} | ||
do | ||
echo "Extracting archive.tar in stack ${stack} version ${version}.." | ||
extract "$stack_root/$version" | ||
done | ||
# Not a multi version | ||
else | ||
echo "Extracting archive.tar in stack ${stack}.." | ||
extract $stack_root | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
schemaVersion: 2.2.0 | ||
metadata: | ||
description: "Go is an open source programming language that makes it easy to build simple, reliable, and efficient software." | ||
displayName: Go Runtime | ||
icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/golang.svg | ||
name: go | ||
projectType: Go | ||
provider: Red Hat | ||
language: Go | ||
tags: | ||
- Go | ||
version: 2.1.0 | ||
parent: | ||
uri: https://registry.devfile.io/devfiles/go/2.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters