Skip to content

Commit 6344315

Browse files
NoeSamailleGitHub Enterprise
authored andcommitted
Merge pull request #23 from gsi-labs/patch/solution-builder
Added static files at tf build
2 parents 7f22803 + 415e706 commit 6344315

7 files changed

Lines changed: 123 additions & 5 deletions

File tree

public/credentials.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add the values for the Credentials to access the IBM Cloud
2+
# Instructions to access this information can be found in the README.MD
3+
# This is a template file and the ./launch.sh script looks for a file based on this template named credentials.properties
4+
ibmcloud.api.key=""

public/launch.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
ENV="credentials"
4+
5+
function prop {
6+
grep "${1}" ${ENV}.properties | grep -vE "^#" | cut -d'=' -f2 | sed 's/"//g'
7+
}
8+
9+
if [[ -f "${ENV}.properties" ]]; then
10+
# Load the credentials
11+
IBMCLOUD_API_KEY=$(prop 'ibmcloud.api.key')
12+
CLASSIC_API_KEY=$(prop 'classic.api.key')
13+
CLASSIC_USERNAME=$(prop 'classic.username')
14+
LOGIN_USER=$(prop 'login.user')
15+
LOGIN_PASSWORD=$(prop 'login.password')
16+
LOGIN_TOKEN=$(prop 'login.token')
17+
SERVER_URL=$(prop 'server.url')
18+
else
19+
echo "Error: The ${ENV}.properties file is not found."
20+
exit 1
21+
fi
22+
23+
if [[ -d "workspace" ]]; then
24+
echo "Found workspace"
25+
else
26+
mkdir workspace
27+
cp terraform/* workspace
28+
cp utils/* workspace
29+
fi
30+
31+
docker run -it \
32+
-e "TF_VAR_ibmcloud_api_key=${IBMCLOUD_API_KEY}" \
33+
-e "IBMCLOUD_API_KEY=${IBMCLOUD_API_KEY}" \
34+
-v ${PWD}:/terraform \
35+
-w /terraform/workspace \
36+
quay.io/ibmgaragecloud/cli-tools:v0.15

public/utils/apply-all.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
find . -type d -maxdepth 1 | grep -vE "[.]/[.].*" | grep -vE "^[.]$" | grep -v workspace | sort | \
4+
while read dir;
5+
do
6+
name=$(echo "$dir" | sed -E "s~[.]/(.*)~\1~g")
7+
8+
echo "*** Applying ${name} ***"
9+
10+
cd "${name}" && \
11+
terraform init && \
12+
terraform apply -auto-approve && \
13+
cd - 1> /dev/null || \
14+
exit 1
15+
done

public/utils/apply.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
terraform apply -auto-approve

public/utils/destroy-all.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
find . -type d -maxdepth 1 | grep -vE "[.]/[.].*" | grep -vE "^[.]$" | grep -v workspace | sort -r | \
4+
while read dir;
5+
do
6+
name=$(echo "$dir" | sed -E "s~[.]/(.*)~\1~g")
7+
8+
if [[ ! -f "./${name}/terraform.tfstate" ]]; then
9+
echo "*** No state found for ${name}. Skipping ***"
10+
continue
11+
fi
12+
13+
echo "*** Destroying ${name} ***"
14+
15+
cd "${name}" && \
16+
terraform init && \
17+
./destroy.sh && \
18+
cd - 1> /dev/null || \
19+
exit 1
20+
done

public/utils/destroy.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /bin/bash
2+
3+
RESOURCE_FILTER="$1"
4+
5+
echo ""
6+
echo "Listing current state"
7+
terraform state list
8+
9+
if [[ -n "${RESOURCE_FILTER}" ]]; then
10+
echo ""
11+
echo "Collecting resources to destroy using filter: ${RESOURCE_FILTER}"
12+
RESOURCE_LIST=""
13+
while read -r resource; do
14+
echo " Adding $resource to destroy targets"
15+
RESOURCE_LIST="$RESOURCE_LIST -target=$resource"
16+
done < <(terraform state list | grep -E "${RESOURCE_FILTER}")
17+
else
18+
echo ""
19+
echo "Collecting resources to destroy"
20+
RESOURCE_LIST=""
21+
while read -r resource; do
22+
echo " Adding $resource to destroy targets"
23+
RESOURCE_LIST="$RESOURCE_LIST -target=$resource"
24+
done < <(terraform state list)
25+
fi
26+
27+
if [[ -n "$RESOURCE_LIST" ]]; then
28+
echo ""
29+
echo "Planning destroy"
30+
terraform plan -destroy ${RESOURCE_LIST} -out=destroy.plan
31+
32+
echo ""
33+
echo "Destroying resources"
34+
terraform apply -auto-approve destroy.plan
35+
else
36+
echo ""
37+
echo "Nothing to destroy!!"
38+
fi
39+

src/helpers/services.helper.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,17 @@ export class ServicesHelper {
396396
}
397397
}
398398

399-
400399
let mdfiles = "";
401400
terraformComponent.files.map(async (file: OutputFile) => {
402401
if (file.type === "documentation") {
403402
mdfiles += "- [" + file.name + "](" + file.name + ")\n";
404403
}
405404
});
406405

406+
zip.addLocalFolder('./public/utils', 'utils');
407+
zip.addLocalFile('./public/credentials.template')
408+
zip.addLocalFile('./public/launch.sh')
409+
407410
// Load the Core ReadME
408411
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" });
409412
const newFiles = terraformComponent.files;
@@ -422,6 +425,8 @@ export class ServicesHelper {
422425

423426
let contents: string | Buffer = "";
424427
//console.log(file.name);
428+
if (file.name.endsWith('.tfvars')) file.name = `terraform/${file.name.replace('terraform', `${bom.metadata.name}.auto`)}`;
429+
if (file.name.endsWith('.tf')) file.name = `terraform/${file.name}`;
425430
if (file.type === "documentation") {
426431
try {
427432
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -442,10 +447,6 @@ export class ServicesHelper {
442447
console.log("failed to load contents from ", file.name);
443448
}
444449
} else {
445-
if (file.type === 'terraform') {
446-
if (file.name?.endsWith('.tfvars')) file.name = file.name.replace('terraform', `${bom.metadata.name}.auto`);
447-
file.name = `terraform/${file.name}`;
448-
}
449450
try {
450451
contents = (await file.contents).toString();
451452
} catch (e) {

0 commit comments

Comments
 (0)