-
Notifications
You must be signed in to change notification settings - Fork 3
/
quickstart.sh
109 lines (91 loc) · 4.15 KB
/
quickstart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# This script is designed for quickstart. It creates and deploys a component with default configuration
# for a given domain name or IP address.
#
# Before running the script, users must:
# 1) Deploy Greengrass V2 to an x86-compatible Linux machine, virtual machine or EC2 instance. The default The
# Things Stack configuration settings shall pull amd64 images, hence the x86-compatibility requirement.
# 2) Initialize the Greengrass core device to satisfy the the requirements to run Docker containers using
# Docker Compose and Docker Hub.
# 3) Install cfssl on their developer machine.
# 4) Set the AWS region in gdk-config.json.
#
# This script will:
# 1) Install required Python packages.
# 2) Create self-signed certificates for a given domain name or IP address.
# 3) Create a minimal The Things Stack configuration for the given domain name or IP address.
# 4) Upload the secure configuration to a configuration secret in Secrets Manager.
# 5) Use GDK to build the component.
# 6) Use GDK to publish a new component version to Greengrass cloud services and upload artifacts to an S3 bucket.
# 7) Prompt you to add permissions for the configuration secret and artifacts bucket to the Greengrass core device role.
# 7) Deploy the new component version to the Greengrass core.
# 8) Run Robot Framework integration tests to confirm The Things Stack is running under Greengrass.
#
# Example execution:
# bash quickstart.sh example.com mypassword [email protected] GGTheThingsStackLoRaWAN
# Fail if we don't get the correct number of arguments
if [ "$#" -ne 4 ]; then
echo "Usage: bash quickstart.sh domain adminPassword adminEmail GGCoreDeviceName"
exit 1
fi
# Exit when any command fails
set -e
banner() {
echo -e "\n---------- $1 ----------"
}
# Don't let them proceed until they've set the region in the GDK configuration
done=0
while [ $done -eq 0 ]; do
echo "Have you set the AWS region in gdk-config.json? ('Press 'y' for yes or 'x' to exit)"
read -rsn1 keypress
if [ "$keypress" = "x" ]; then
echo "Cannot proceed"
exit 1
elif [ "$keypress" = "y" ]; then
done=1
fi
done
# Install requirements
banner "Install required packages"
pip3 install -r requirements.txt
pip3 install -r robot/requirements.txt
pip3 install git+https://github.com/aws-greengrass/aws-greengrass-gdk-cli.git
# Create self-signed certificates for the given domain name or IP address
banner "Create certificates"
bash create_certs.sh $1
# Generate the minimal required The Things Stack configuration for the given domain name or IP address
banner "Create minimal The Things Stack configuration"
python3 create_config_minimal.py $1
# Create The Things Stack configuration secret in Secrets Manager to hold the configuration securely
banner "Create or update The Things Stack configuration secret"
python3 create_config_secret.py $2 $3
# Build the component
banner "Build the Greengrass component"
gdk component build
# Publish a new component version
banner "Publish a new Greengrass component version"
gdk component publish
# Don't let them proceed until they've added the S3 bucket and secret permissions to the Greengrass device role
done=0
while [ $done -eq 0 ]; do
echo "Have you added the bucket and secret permissions to the Greengrass device role? ('Press 'y' for yes or 'x' to exit)"
read -rsn1 keypress
if [ "$keypress" = "x" ]; then
echo "Deployment not performed"
exit 1
elif [ "$keypress" = "y" ]; then
done=1
fi
done
# Get the recipe file generated by the build stage and extract the new component version
RECIPE_FILE=$(ls greengrass-build/recipes/aws.greengrass.labs.*.json)
COMPONENT_VERSION=$(cat $RECIPE_FILE | jq -r '.ComponentVersion')
# Deploy the new component version
banner "Deploy the new Greengrass component version"
python3 deploy_component_version.py $COMPONENT_VERSION $4
# Run the Robot Framework integration tests
banner "Run integration tests"
cd robot
robot --pythonpath libs --variable DOMAIN_NAME:$1 --variable ADMIN_PASSWORD:$2 --xunit results.xml --removekeywords NAME:Login suites