Skip to content

Commit dd3abc8

Browse files
authored
fix: update script files (#6)
* fix: update script files
1 parent 1347f11 commit dd3abc8

File tree

13 files changed

+105
-74
lines changed

13 files changed

+105
-74
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- Update this title with a descriptive name. Use sentence case. -->
2-
# Terraform modules template project
2+
# IBM Cloud Pak for Data deployment on OpenShift
33

44
<!--
55
Update status and "latest release" badges:
@@ -14,7 +14,7 @@ Update status and "latest release" badges:
1414

1515

1616
This repository contains the following deployment an Red Hat OpenShift cluster:
17-
- [IBM Cloud Cloud Pak for Data](./solutions/deploy)
17+
- [IBM Cloud Pak for Data](./solutions/deploy)
1818

1919
**NB:** These solutions are not intended to be called by one or more other modules since they contain a provider configurations, meaning they are not compatible with the `for_each`, `count`, and `depends_on` arguments. For more information see [Providers Within Modules](https://developer.hashicorp.com/terraform/language/modules/develop/providers)
2020

examples/basic/README.md

Whitespace-only changes.

solutions/deploy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ You need the following permissions to run this module:
106106
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.66.0, < 2.0.0 |
107107
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | 2.35.1 |
108108
| <a name="requirement_null"></a> [null](#requirement\_null) | 3.2.2 |
109-
| <a name="requirement_restapi"></a> [restapi](#requirement\_restapi) | 1.18.2 |
109+
| <a name="requirement_shell"></a> [shell](#requirement\_shell) | 1.7.10 |
110110

111111
### Modules
112112

solutions/deploy/cloud-pak-deployer/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ resource "shell_script" "uninstall" {
295295

296296
lifecycle_commands {
297297
create = ""
298-
delete = file("${path.module}/scripts/uninstall.sh.tftpl")
298+
delete = file("${path.module}/scripts/uninstall.sh")
299299
}
300300

301301
environment = {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
${OC} create -f "${JOB_UNINSTALL_CPD_FILENAME}"
4+
RC=$?
5+
if [ "${RC}" -ne 0 ]; then echo "Unable to create job ${JOB_NAME}; exiting..." && exit 1; fi
6+
7+
timeout_seconds=1800 # 30 minutes
8+
sleep_seconds=5
9+
number_of_tries=$((timeout_seconds / sleep_seconds))
10+
complete=false
11+
failed=false
12+
13+
i=0
14+
while [ $i -lt "${number_of_tries}" ]; do
15+
16+
echo "Running job ... $i"
17+
${OC} get jobs -n "${NAMESPACE_NAME}"
18+
19+
${OC} wait --for=condition=complete job "${JOB_NAME}" -n "${NAMESPACE_NAME}" --timeout=0 2>/dev/null
20+
RC=$?
21+
if [ "${RC}" -eq 0 ]; then complete=true && break; fi
22+
23+
${OC} wait --for=condition=failed job "${JOB_NAME}" -n "${NAMESPACE_NAME}" --timeout=0 2>/dev/null
24+
RC=$?
25+
if [ "${RC}" -eq 0 ]; then failed=true && break; fi
26+
27+
i=$((i+1))
28+
29+
sleep "${sleep_seconds}"
30+
31+
done
32+
33+
${OC} describe pods -n "${NAMESPACE_NAME}"
34+
35+
if $failed; then
36+
echo "Job ${JOB_NAME} failed"
37+
exit 1
38+
elif "${complete}"; then
39+
echo "Job ${JOB_NAME} completed successfully"
40+
${OC} delete -f "${JOB_UNINSTALL_CPD_FILENAME}"
41+
RC=$?
42+
if [ "${RC}" -ne 0 ]; then echo "Unable to delete job ${JOB_NAME}; exiting..." && exit 1; fi
43+
exit 0
44+
fi

solutions/deploy/cloud-pak-deployer/scripts/uninstall.sh.tftpl

Lines changed: 0 additions & 40 deletions
This file was deleted.
File renamed without changes.

solutions/deploy/cpd-image-build/main.tf

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,15 @@ module "code_engine_build" {
8989
depends_on = [module.code_engine]
9090
}
9191

92-
resource "restapi_object" "buildrun" {
93-
path = "/v2/projects/${module.code_engine.project_id}/build_runs"
94-
data = jsonencode(
95-
{
96-
build_name = module.code_engine_build.name
97-
}
98-
)
99-
}
100-
101-
resource "time_sleep" "wait_for_build" {
102-
create_duration = "10m"
92+
resource "shell_script" "build_run" {
93+
lifecycle_commands {
94+
create = file("${path.module}/scripts/image-build.sh")
95+
delete = ""
96+
update = ""
97+
}
10398

104-
depends_on = [
105-
restapi_object.buildrun
106-
]
99+
environment = {
100+
REGION = var.region
101+
PROJECT_ID = module.code_engine.project_id
102+
}
107103
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
BUILD_OUTPUT=$(curl -X POST "https://api.${REGION}.codeengine.cloud.ibm.com/v2/projects/${PROJECT_ID}/build_runs" -H "Authorization: ${TOKEN}" -H "Content-Type: application/json" -d '{ "build_name": "cpd-build" }')
4+
RC=$?
5+
6+
BUILD_NAME=$(echo "${BUILD_OUTPUT}" | jq -r .name)
7+
8+
if [ $RC -ne 0 ] || [ "${BUILD_NAME}" == "null" ]; then
9+
echo "Creation of build run failed with rc = ${RC}. Output = ${BUILD_OUTPUT}"
10+
exit 1;
11+
fi
12+
13+
SLEEP_SECONDS=60
14+
NUMBER_OF_RETRIES=15
15+
COMPLETE=false
16+
17+
i=0
18+
while [ "${i}" -lt "${NUMBER_OF_RETRIES}" ]; do
19+
20+
echo "Running job ... $i"
21+
22+
BUILD_RUN_OUTPUT=$(curl -X GET "https://api.${REGION}.codeengine.cloud.ibm.com/v2/projects/${PROJECT_ID}/build_runs/${BUILD_NAME}" -H "Authorization: ${TOKEN}")
23+
echo "${BUILD_RUN_OUTPUT}"
24+
25+
BUILD_STATUS=$(echo "${BUILD_RUN_OUTPUT}" | jq -r .status)
26+
if [ "${BUILD_STATUS}" == "succeeded" ]; then COMPLETE=true && break; fi
27+
28+
i=$((i+1))
29+
30+
sleep "${SLEEP_SECONDS}"
31+
done
32+
33+
if [ "${COMPLETE}" = false ]; then
34+
echo "The build run did not complete in the alloted time. Output = ${BUILD_RUN_OUTPUT}"
35+
exit 1;
36+
fi
37+
38+
exit 0;

0 commit comments

Comments
 (0)