Skip to content

Commit

Permalink
Merge pull request #23 from gsi-labs/patch/solution-builder
Browse files Browse the repository at this point in the history
Added static files at tf build
  • Loading branch information
NoeSamaille authored and GitHub Enterprise committed Feb 10, 2022
2 parents 7f22803 + 415e706 commit 6344315
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 5 deletions.
4 changes: 4 additions & 0 deletions public/credentials.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Add the values for the Credentials to access the IBM Cloud
# Instructions to access this information can be found in the README.MD
# This is a template file and the ./launch.sh script looks for a file based on this template named credentials.properties
ibmcloud.api.key=""
36 changes: 36 additions & 0 deletions public/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

ENV="credentials"

function prop {
grep "${1}" ${ENV}.properties | grep -vE "^#" | cut -d'=' -f2 | sed 's/"//g'
}

if [[ -f "${ENV}.properties" ]]; then
# Load the credentials
IBMCLOUD_API_KEY=$(prop 'ibmcloud.api.key')
CLASSIC_API_KEY=$(prop 'classic.api.key')
CLASSIC_USERNAME=$(prop 'classic.username')
LOGIN_USER=$(prop 'login.user')
LOGIN_PASSWORD=$(prop 'login.password')
LOGIN_TOKEN=$(prop 'login.token')
SERVER_URL=$(prop 'server.url')
else
echo "Error: The ${ENV}.properties file is not found."
exit 1
fi

if [[ -d "workspace" ]]; then
echo "Found workspace"
else
mkdir workspace
cp terraform/* workspace
cp utils/* workspace
fi

docker run -it \
-e "TF_VAR_ibmcloud_api_key=${IBMCLOUD_API_KEY}" \
-e "IBMCLOUD_API_KEY=${IBMCLOUD_API_KEY}" \
-v ${PWD}:/terraform \
-w /terraform/workspace \
quay.io/ibmgaragecloud/cli-tools:v0.15
15 changes: 15 additions & 0 deletions public/utils/apply-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

find . -type d -maxdepth 1 | grep -vE "[.]/[.].*" | grep -vE "^[.]$" | grep -v workspace | sort | \
while read dir;
do
name=$(echo "$dir" | sed -E "s~[.]/(.*)~\1~g")

echo "*** Applying ${name} ***"

cd "${name}" && \
terraform init && \
terraform apply -auto-approve && \
cd - 1> /dev/null || \
exit 1
done
3 changes: 3 additions & 0 deletions public/utils/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

terraform apply -auto-approve
20 changes: 20 additions & 0 deletions public/utils/destroy-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

find . -type d -maxdepth 1 | grep -vE "[.]/[.].*" | grep -vE "^[.]$" | grep -v workspace | sort -r | \
while read dir;
do
name=$(echo "$dir" | sed -E "s~[.]/(.*)~\1~g")

if [[ ! -f "./${name}/terraform.tfstate" ]]; then
echo "*** No state found for ${name}. Skipping ***"
continue
fi

echo "*** Destroying ${name} ***"

cd "${name}" && \
terraform init && \
./destroy.sh && \
cd - 1> /dev/null || \
exit 1
done
39 changes: 39 additions & 0 deletions public/utils/destroy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /bin/bash

RESOURCE_FILTER="$1"

echo ""
echo "Listing current state"
terraform state list

if [[ -n "${RESOURCE_FILTER}" ]]; then
echo ""
echo "Collecting resources to destroy using filter: ${RESOURCE_FILTER}"
RESOURCE_LIST=""
while read -r resource; do
echo " Adding $resource to destroy targets"
RESOURCE_LIST="$RESOURCE_LIST -target=$resource"
done < <(terraform state list | grep -E "${RESOURCE_FILTER}")
else
echo ""
echo "Collecting resources to destroy"
RESOURCE_LIST=""
while read -r resource; do
echo " Adding $resource to destroy targets"
RESOURCE_LIST="$RESOURCE_LIST -target=$resource"
done < <(terraform state list)
fi

if [[ -n "$RESOURCE_LIST" ]]; then
echo ""
echo "Planning destroy"
terraform plan -destroy ${RESOURCE_LIST} -out=destroy.plan

echo ""
echo "Destroying resources"
terraform apply -auto-approve destroy.plan
else
echo ""
echo "Nothing to destroy!!"
fi

11 changes: 6 additions & 5 deletions src/helpers/services.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,17 @@ export class ServicesHelper {
}
}


let mdfiles = "";
terraformComponent.files.map(async (file: OutputFile) => {
if (file.type === "documentation") {
mdfiles += "- [" + file.name + "](" + file.name + ")\n";
}
});

zip.addLocalFolder('./public/utils', 'utils');
zip.addLocalFile('./public/credentials.template')
zip.addLocalFile('./public/launch.sh')

// Load the Core ReadME
const readme = new UrlFile({ name: 'README.MD', type: OutputFileType.documentation, url: "https://raw.githubusercontent.com/ibm-gsi-ecosystem/ibm-enterprise-catalog-tiles/main/BUILD.MD" });
const newFiles = terraformComponent.files;
Expand All @@ -422,6 +425,8 @@ export class ServicesHelper {

let contents: string | Buffer = "";
//console.log(file.name);
if (file.name.endsWith('.tfvars')) file.name = `terraform/${file.name.replace('terraform', `${bom.metadata.name}.auto`)}`;
if (file.name.endsWith('.tf')) file.name = `terraform/${file.name}`;
if (file.type === "documentation") {
try {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -442,10 +447,6 @@ export class ServicesHelper {
console.log("failed to load contents from ", file.name);
}
} else {
if (file.type === 'terraform') {
if (file.name?.endsWith('.tfvars')) file.name = file.name.replace('terraform', `${bom.metadata.name}.auto`);
file.name = `terraform/${file.name}`;
}
try {
contents = (await file.contents).toString();
} catch (e) {
Expand Down

0 comments on commit 6344315

Please sign in to comment.