Skip to content

Commit 747d79c

Browse files
Merge pull request #30 from bitovi/bucket_name_fix
Applying update to generators
2 parents fc8bf5e + 414f994 commit 747d79c

File tree

5 files changed

+98
-19
lines changed

5 files changed

+98
-19
lines changed

operations/_scripts/deploy/deploy.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ set -x
44
echo "In deploy.sh"
55
GITHUB_REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///')
66

7-
# Generate the tf state bucket
8-
export TF_STATE_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_tf_state_bucket.sh | xargs)"
7+
# Generate buckets identifiers and check them agains AWS Rules
8+
export TF_STATE_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_buckets_identifiers.sh tf | xargs)"
9+
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/deploy/check_bucket_name.sh $TF_STATE_BUCKET
10+
export LB_LOGS_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_buckets_identifiers.sh lb | xargs)"
11+
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/deploy/check_bucket_name.sh $LB_LOGS_BUCKET
12+
13+
# Generate buckets identifiers
14+
export TF_STATE_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_buckets_identifiers.sh tf | xargs)"
15+
export LB_LOGS_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_buckets_identifiers.sh lb | xargs)"
916

1017
# Generate subdomain
1118
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_subdomain.sh
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
echo "In check_bucket_name.sh"
3+
4+
set -e
5+
6+
### S3 Buckets name must follow AWS rules. Info below.
7+
### https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
8+
9+
function checkBucket() {
10+
# check length of bucket name
11+
if [[ ${#1} -lt 3 || ${#1} -gt 63 ]]; then
12+
echo "::error::Bucket name must be between 3 and 63 characters long."
13+
exit 1
14+
fi
15+
16+
# check that bucket name consists only of lowercase letters, numbers, dots (.), and hyphens (-)
17+
if [[ ! $1 =~ ^[a-z0-9.-]+$ ]]; then
18+
echo "::error::Bucket name can only consist of lowercase letters, numbers, dots (.), and hyphens (-)."
19+
exit 1
20+
fi
21+
22+
# check that bucket name begins and ends with a letter or number
23+
if [[ ! $1 =~ ^[a-zA-Z0-9] ]]; then
24+
echo "::error::Bucket name must begin with a letter or number."
25+
exit 1
26+
fi
27+
if [[ ! $1 =~ [a-zA-Z0-9]$ ]]; then
28+
echo "::error::Bucket name must end with a letter or number."
29+
exit 1
30+
fi
31+
32+
# check that bucket name does not contain two adjacent periods
33+
if [[ $1 =~ \.\. ]]; then
34+
echo "::error::Bucket name cannot contain two adjacent periods."
35+
exit 1
36+
fi
37+
38+
# check that bucket name is not formatted as an IP address
39+
if [[ $1 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
40+
echo "::error::Bucket name cannot be formatted as an IP address."
41+
exit 1
42+
fi
43+
44+
# check that bucket name does not start with the prefix xn--
45+
if [[ $1 =~ ^xn-- ]]; then
46+
echo "::error::Bucket name cannot start with the prefix xn--."
47+
exit 1
48+
fi
49+
50+
# check that bucket name does not end with the suffix -s3alias
51+
if [[ $1 =~ -s3alias$ ]]; then
52+
echo "::error::Bucket name cannot end with the suffix -s3alias."
53+
exit 1
54+
fi
55+
}
56+
57+
checkBucket $1
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
GITHUB_IDENTIFIER="$(echo $($GITHUB_ACTION_PATH/operations/_scripts/generate/generate_identifier.sh) | tr '[:upper:]' '[:lower:]' | tr '_' '-' )"
6+
7+
case $1 in
8+
tf)
9+
# Generate TF_STATE_BUCKET ID if empty
10+
if [ -z "${TF_STATE_BUCKET}" ]; then
11+
# Add trailing id depending on name length - See AWS S3 bucket naming rules
12+
if [[ ${#GITHUB_IDENTIFIER} < 55 ]]; then
13+
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf-state"
14+
else
15+
TF_STATE_BUCKET="${GITHUB_IDENTIFIER}-tf"
16+
fi
17+
fi
18+
echo "$TF_STATE_BUCKET"
19+
20+
;;
21+
lb)
22+
# Generate LB_LOGS_BUCKET ID
23+
# Add trailing id depending on name length - See AWS S3 bucket naming rules
24+
if [[ ${#GITHUB_IDENTIFIER} < 59 ]]; then
25+
LB_LOGS_BUCKET="${GITHUB_IDENTIFIER}-logs"
26+
else
27+
LB_LOGS_BUCKET="${GITHUB_IDENTIFIER}-lg"
28+
fi
29+
echo "$LB_LOGS_BUCKET"
30+
;;
31+
esac

operations/_scripts/generate/generate_tf_state_bucket.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

operations/_scripts/generate/generate_tf_vars.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ app_branch_name = \"${GITHUB_BRANCH_NAME}\"
5757
app_install_root = \"/home/ubuntu\"
5858
5959
# Logs
60-
lb_access_bucket_name = \"${TF_STATE_BUCKET}-logs\"
60+
lb_access_bucket_name = \"${LB_LOGS_BUCKET}\"
6161
6262
# Security Group names
6363
security_group_name = \"${GITHUB_IDENTIFIER}\"

0 commit comments

Comments
 (0)