Skip to content

Commit 8f70958

Browse files
jkwong888osowski
authored andcommitted
trigger the installer when the variables change (#18)
* use terraform-module-icp-deploy standalone to install, update permissions * update documentation, support install off remote registry * add diagrams, trigger reinstallation when configuration changes
1 parent 9f33e05 commit 8f70958

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,25 @@ To move forward and create the objects, use the following command:
8888
terraform apply
8989
```
9090

91-
This will kick off all infrastructure objects. Once the infrastructure is created, if no bastion host is provisioned, the installation runs on the boot master (i.e. `icp-master01`) until it completes; otherwise the installation will continue synchronously using the bastion host's public IP (by setting the number of bastion nodes in `terraform.tfvars` to 1).
91+
The following diagram illustrates the process:
92+
93+
![terraform install](imgs/terraform_icp_install.png)
94+
95+
1. Terraform creates the infrastructure objects including EC2 instances.
96+
2. The scripts in the `scripts` directory will be uploaded to an S3 bucket
97+
3. The EC2 instances are configured with [cloud-init](https://cloud-init.io/) to retrieve the scripts from the S3 bucket on startup. The `bootstrap.sh` script is executed silently on every node and bootstraps each node (install docker, prepare storage, etc).
98+
4. A configuration file (`terraform.tfvars`) is generated from the outputs of the infrastructure for the [terraform-module-icp-deploy](https://github.com/ibm-cloud-architecture/terraform-module-icp-deploy) module and copied to the S3 bucket.
99+
5. The `start_install.sh` script is run on the first ICP master host, which clones the github module, downloads the `terraform.tfvars` file from the S3 bucket, and runs `terraform apply` in a docker container that triggers the rest of the ICP installation.
100+
101+
If no bastion host is provisioned, the installation runs silently on the boot master (i.e. `icp-master01`) using [cloud-init](https://cloud-init.io/) until it completes; otherwise the installation will continue synchronously using the bastion host's public IP (by setting the number of bastion nodes in `terraform.tfvars` to 1).
92102

93103
```
94104
bastion = {
95105
nodes = "1"
96106
}
97107
```
98108

99-
The installation output will be written to `/var/log/cloud-init-output.log` for RHEL 7.4 systems and `/var/log/messages` on RHEL 7.5+ systems. Bastion hosts are not required for normal operation of the cluster.
109+
The installation output will be written to `/tmp/icp_logs/start_install.log` on the first master. Bastion hosts are not required for normal operation of the cluster, but may be desired if you want to synchronously wait for the installation to complete, such as in execution from a devops pipeline.
100110

101111
When the installation completes, the `/opt/ibm/cluster` directory on the boot master (i.e. `icp-master01`) is backed up to S3 in a bucket named `icpbackup-<clusterid>`, which can be used in master recovery in case one of the master nodes fails. It is recommended after every time `terraform apply` is performed, to commit the `terraform.tfstate` into a backend so that the state is stored in source control.
102112

icp-deploy.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ resource "tls_private_key" "installkey" {
142142

143143
# kick off the installer from the bastion node, if one exists. otherwise it will get kicked off from cloud-init
144144
resource "null_resource" "start_install" {
145+
# trigger a reinstall if the cluster config changes
146+
triggers {
147+
terraform_tfvars_contents = "${aws_s3_bucket_object.terraform_tfvars.content}"
148+
icp_config_yaml_contents = "${aws_s3_bucket_object.icp_config_yaml.content}"
149+
}
150+
145151
count = "${var.bastion["nodes"] != 0 ? 1 : 0}"
146152

147153
provisioner "remote-exec" {

imgs/terraform_icp_install.png

26.9 KB
Loading

scripts/start_install.sh

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,6 @@ logmsg() {
1313
echo $date $hostname $1 | tee -a $logfile
1414
}
1515

16-
#
17-
# This function will populate the local Docker repository with the ICP images.
18-
#
19-
image_load() {
20-
if [[ ! -z $(docker images -q ${inception_image}) ]]; then
21-
# If we don't have an image locally we'll pull from docker hub registry
22-
logmsg "Not required to load images. Exiting"
23-
return 0
24-
fi
25-
26-
if [[ ! -z "${image_location}" ]]; then
27-
# Decide which protocol to use
28-
if [[ "${image_location:0:2}" == "s3" ]]; then
29-
# stream it right out of s3 into docker
30-
logmsg "Copying binary package from ${image_location} ..."
31-
${awscli} s3 cp ${image_location} /tmp
32-
33-
logmsg "Loading docker images from /tmp/`basename ${image_location}` ..."
34-
tar zxf /tmp/`basename ${image_location}` -O | docker load | tee -a $logfile
35-
36-
logmsg "Copying binary package to /opt/ibm/cluster/images ..."
37-
mkdir -p /opt/ibm/cluster/images
38-
mv /tmp/`basename ${image_location}` /opt/ibm/cluster/images
39-
40-
logmsg "Completed loading docker images from ${image_location} ..."
41-
fi
42-
fi
43-
}
44-
45-
4616
logmsg "~~~~~~~~ Starting ICP installation Code ~~~~~~~~"
4717

4818
##### MAIN #####
@@ -66,14 +36,13 @@ if [ -z "${awscli}" ]; then
6636
fi
6737

6838
if ! docker --version; then
69-
logmsg "Docker is not installed."
39+
logmsg "ERROR: Docker is not installed."
7040
exit 1
7141
fi
7242

7343
# Figure out the version
7444
# This will populate $org $repo and $tag
7545
parse_icpversion ${inception_image}
76-
logmsg "Populating the registry."
7746
logmsg "registry=${registry:-not specified} org=$org repo=$repo tag=$tag"
7847

7948
if [ ! -z "${username}" -a ! -z "${password}" ]; then
@@ -84,7 +53,30 @@ if [ ! -z "${username}" -a ! -z "${password}" ]; then
8453
fi
8554

8655
# load images
87-
image_load
56+
if [[ ! -z $(docker images -q ${inception_image}) ]]; then
57+
# If we don't have an image locally we'll pull from docker hub registry
58+
logmsg "Not required to load images. Exiting"
59+
return 0
60+
fi
61+
62+
if [[ ! -z "${image_location}" ]]; then
63+
# Decide which protocol to use
64+
if [[ "${image_location:0:2}" == "s3" ]]; then
65+
# stream it right out of s3 into docker
66+
logmsg "Copying binary package from ${image_location} ..."
67+
${awscli} s3 cp ${image_location} /tmp
68+
69+
logmsg "Loading docker images from /tmp/`basename ${image_location}` ..."
70+
tar zxf /tmp/`basename ${image_location}` -O | docker load | tee -a $logfile
71+
72+
logmsg "Copying binary package to /opt/ibm/cluster/images ..."
73+
mkdir -p /opt/ibm/cluster/images
74+
mv /tmp/`basename ${image_location}` /opt/ibm/cluster/images
75+
76+
logmsg "Completed loading docker images from ${image_location} ..."
77+
fi
78+
fi
79+
8880

8981
inception_image=${registry}${registry:+/}${org}/${repo}:${tag}
9082

0 commit comments

Comments
 (0)