-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathdeploy-dev-stack.sh
executable file
·72 lines (58 loc) · 2.57 KB
/
deploy-dev-stack.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
#!/bin/bash
set -o errexit -o pipefail
source ./scripts/common.sh
# This script runs a full site build, deploys to a unique S3 bucket, and runs Pulumi to deploy the specified stack.
#
# Usage:
#
# ./scripts/deploy-dev-stack.sh # Runs a full build. Prompts for stack name and before update.
# ./scripts/deploy-dev-stack.sh pulumi/stackname # Runs a full build, skipping the prompt for stack name.
# STACK_NAME=pulumi/stackname ./scripts/deploy-dev-stack.sh # Same as above.
# SKIP_BUILD=true ./scripts/deploy-dev-stack.sh # Skips the build step and goes straight to deployment, but still prompts before update.
# SKIP_PREVIEW=true ./scripts/deploy-dev-stack.sh # Skips the preview before updating. (Is the same as passing --yes.)
# Check to make sure the user belongs to the 'pulumi' org and has access to the project.
if [[ "$(pulumi -C infrastructure stack ls --json | jq -r -C '.[] | select(.url | startswith("https://app.pulumi.com/pulumi/www.pulumi.com/")).url')" == "" ]]; then
echo
echo "To work with dev stacks, you must belong to the https://app.pulumi.com/pulumi organization and have"
echo "access to the 'www.pulumi.com' project. Exiting."
exit 0
fi
echo
echo "Listing available stacks for this project..."
echo
pulumi -C infrastructure stack ls | grep -v "production" | grep -v "staging" | grep -v "testing"
stack_name="${STACK_NAME:=$1}"
if [ -z "$stack_name" ]; then
echo
read -p "Which stack would you like to deploy? " stack_name
fi
if [[ "$stack_name" == *production* || "$stack_name" == *staging* || "$stack_name" == *testing* ]]; then
echo
echo "Refusing to deploy the $stack_name stack with this script. Exiting."
exit 0
fi
echo
echo "Selecting the $stack_name stack..."
pulumi -C infrastructure stack select "$stack_name"
if [[ -z "$SKIP_BUILD" || "$SKIP_BUILD" == false ]]; then
echo
echo "Running a build and deploying to S3..."
# This environment variable doesn't actually correspond to any real environment; it just populates a variable
# we use to name the S3 bucket. (In GHA, we use it to target a GHA environment, but in this context, it has no effect.)
DEPLOYMENT_ENVIRONMENT="dev" pulumi env run pulumi/dev-stacks -- ./scripts/on-demand-build-sync-test.sh
else
echo
echo "Skipping build..."
fi
echo
echo "Deploying..."
echo
if [[ "$SKIP_PREVIEW" == true ]]; then
pulumi -C infrastructure up --skip-preview
else
pulumi -C infrastructure up
fi
echo "Done!"
echo
echo "https://$(pulumi -C infrastructure stack output websiteDomain)"
echo