Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding build scripts to extract stack resources #180

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ COPY build-tools /build-tools
COPY index/ /index
COPY tests/registry /registry

# Download all the offline parent devfiles
RUN bash /build-tools/dl_parent_devfiles.sh

# Download offline starter projects
RUN bash /build-tools/dl_starter_projects.sh go-starter community

Expand Down
85 changes: 85 additions & 0 deletions build-tools/dl_parent_devfiles.sh
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!"
42 changes: 42 additions & 0 deletions build-tools/extract_resources.sh
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
14 changes: 14 additions & 0 deletions tests/registry/stacks/go/2.1.0/devfile.yaml
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
1 change: 1 addition & 0 deletions tests/registry/stacks/go/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ versions:
- version: 1.2.0
default: true # should have one and only one default version
- version: 2.0.0
- version: 2.1.0
Loading