Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 6867b90

Browse files
authored
Merge pull request #5 from techgnosis/Jenkins
$USER was not defined in the containers in Jenkins so I'm removing it
2 parents 3c383dc + f8fcadd commit 6867b90

File tree

7 files changed

+36
-29
lines changed

7 files changed

+36
-29
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,26 @@ SHELL := /usr/bin/env bash
1818
# All is the first target in the file so it will get picked up when you just run 'make' on its own
1919
linting: check_shell check_python check_golang check_terraform check_docker check_base_files check_headers check_trailing_whitespace
2020

21+
SQLNAME := demo-postgres-5
22+
2123
# The .PHONY directive tells make that this isn't a real target and so
2224
# the presence of a file named 'check_shell' won't cause this target to stop
2325
# working
2426
.PHONY: create
2527
create:
26-
@source ./create.sh demo-postgres user user
28+
@source ./create.sh $(SQLNAME) user user
2729

2830
.PHONY: expose
2931
expose:
3032
@source ./scripts/expose.sh
3133

3234
.PHONY: validate
3335
validate:
34-
@source ./validate.sh demo-postgres
36+
@source ./validate.sh $(SQLNAME)
3537

3638
.PHONY: teardown
3739
teardown:
38-
@source ./teardown.sh demo-postgres
40+
@source ./teardown.sh $(SQLNAME)
3941

4042
.PHONY: check_shell
4143
check_shell:

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,21 @@ If you don't have a Google Cloud account you can sign up for a [free account](ht
109109

110110
## Deployment
111111

112-
Deployment is fully automated except for a few prompts for user input. In order
113-
to deploy you need to run **create.sh** and follow the prompts. The script
112+
Deployment is fully automated. In order
113+
to deploy you need to run **create.sh**. The script
114114
takes the following parameters, in order:
115115
* A name for your Cloud SQL instance
116116
* A username for a new Postgres user that you will use to connect to the
117117
instance with
118118
* A username for the pgAdmin console
119119

120-
Example: `./create.sh INSTANCE_NAME POSTGRES_USERNAME PGADMIN_USERNAME`
120+
The script requires the following environment variables to be defined:
121+
* USER_PASSWORD - the password to login to the Postgres instance
122+
* PG_ADMIN_CONSOLE_PASSWORD - the password to login to the pgAdmin UI
123+
124+
Here is what it looks like to run **create.sh**:
125+
126+
```USER_PASSWORD=password PG_ADMIN_CONSOLE_PASSWORD=password ./create.sh INSTANCE_NAME POSTGRES_USERNAME PGADMIN_USERNAME```
121127

122128
**create.sh** will run the following scripts:
123129
1. enable_apis.sh - enables the Kubernetes Engine API and Cloud SQL Admin API

scripts/cluster.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
set -o errexit
2121

22-
CLUSTER_NAME=$USER-poc-cluster
23-
PROJECT=$(gcloud config get-value core/project)
22+
ROOT=$(dirname "${BASH_SOURCE[0]}")
23+
source "${ROOT}"/constants.sh
24+
25+
2426

2527
# This line is just to eliminate a warning that GKE behavior will change in the
2628
# future. If we just set the new behavior now it doesn't warn us
@@ -35,7 +37,7 @@ gcloud container clusters create "$CLUSTER_NAME" \
3537
--num-nodes 1 \
3638
--enable-autorepair \
3739
--zone "$CLUSTER_ZONE" \
38-
--service-account="$USER"-poc-node-sa@"$PROJECT".iam.gserviceaccount.com \
40+
--service-account="postgres-demo-node-sa@$PROJECT".iam.gserviceaccount.com \
3941

4042
# Setting up .kube/config. This happens normally if you don't use --async
4143
gcloud container clusters get-credentials "$CLUSTER_NAME" --zone "$CLUSTER_ZONE"

scripts/constants.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PROJECT=$(gcloud config get-value core/project)
2+
3+
CLUSTER_ZONE=$(gcloud config get-value compute/zone)
4+
CLUSTER_NAME=postgres-demo-cluster
5+
6+
INSTANCE_REGION=$(gcloud config get-value compute/region)
7+
8+
SA_NAME=postgres-demo-sa
9+
NODE_SA_NAME=postgres-demo-node-sa
10+
FULL_SA_NAME=$SA_NAME@$PROJECT.iam.gserviceaccount.com
11+
FULL_NODE_SA_NAME=$NODE_SA_NAME@$PROJECT.iam.gserviceaccount.com

scripts/delete_resources.sh

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@
1818
# Cloud SQL instance takes a long time so deleting it is a separate step
1919
# that includes a prompt in another script
2020

21-
SA_NAME=$USER-poc-sa
22-
NODE_SA_NAME=$USER-poc-node-sa
23-
PROJECT=$(gcloud config get-value core/project)
24-
CLUSTER_ZONE=$(gcloud config get-value compute/zone)
25-
26-
FULL_SA_NAME=$SA_NAME@$PROJECT.iam.gserviceaccount.com
27-
FULL_NODE_SA_NAME=$NODE_SA_NAME@$PROJECT.iam.gserviceaccount.com
21+
ROOT=$(dirname "${BASH_SOURCE[0]}")
22+
source "${ROOT}"/constants.sh
2823

2924
gcloud container clusters delete \
30-
"$USER"-poc-cluster --zone "$CLUSTER_ZONE" --quiet
25+
postgres-demo-cluster --zone "$CLUSTER_ZONE" --quiet
3126

3227
gcloud projects remove-iam-policy-binding "$PROJECT" \
3328
--member serviceAccount:"$FULL_SA_NAME" \

scripts/service_account.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@
2020
# The second is for the GKE nodes and it gets the minimal permissions needed
2121
# for logging and monitoring as recommended by the GKE documentation
2222

23-
SA_NAME=$USER-poc-sa
24-
NODE_SA_NAME=$USER-poc-node-sa
25-
PROJECT=$(gcloud config get-value core/project)
23+
ROOT=$(dirname "${BASH_SOURCE[0]}")
24+
source "${ROOT}"/constants.sh
2625

2726
if [ -z "$PROJECT" ]; then
2827
echo "No default project set. Please set one with gcloud config"
2928
exit 1
3029
fi
3130

32-
FULL_SA_NAME=$SA_NAME@$PROJECT.iam.gserviceaccount.com
33-
34-
FULL_NODE_SA_NAME=$NODE_SA_NAME@$PROJECT.iam.gserviceaccount.com
35-
3631
gcloud iam service-accounts create "$SA_NAME" --display-name "$SA_NAME"
3732

3833
gcloud iam service-accounts create "$NODE_SA_NAME" --display-name "$NODE_SA_NAME"

validate.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@
1818
# make sure the Cloud SQL instance is up, as well as the GKE cluster and pod
1919

2020
ROOT=$(dirname "${BASH_SOURCE[0]}")
21-
22-
CLUSTER_NAME=$USER-poc-cluster
21+
source "${ROOT}"/scripts/constants.sh
2322

2423
help() {
2524
echo "./validate.sh INSTANCE_NAME"
2625
}
2726

28-
CLUSTER_ZONE=$(gcloud config get-value compute/zone)
29-
30-
export CLUSTER_ZONE
3127
if [ -z "$CLUSTER_ZONE" ]; then
3228
echo "Make sure that compute/zone is set in gcloud config"
3329
exit 1

0 commit comments

Comments
 (0)