-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathawseb-entrypoint.sh
75 lines (62 loc) · 2.49 KB
/
awseb-entrypoint.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
#!/usr/bin/env bash
# @Author: Andres Montoya
# Copyright (c) 2020, codehunters.io
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
function usage() {
printf "This script must be run with super-user privileges\n"
printf "Environment variabled definition:\n"
printf "AWSEB_APP_NAME: AWS Elastickbeastalk application name\n"
printf "AWSEB_ENV_NAME: AWS Elastickbeastalk environment name\n"
printf "AWSEB_S3_BUCKET: AWS S3 Bucket Name\n"
printf "AWSEB_S3_KEY: AWS S3 Bucket Key\n"
printf "AWSEB_RELEASE_VERSION: Name for release version file upload to AWS S3\n"
printf "LOCALDIR_RELEASE_VERSION: Location for release version file\n"
}
function s3() {
{
aws s3 cp "$LOCALDIR_RELEASE_VERSION" "s3://$AWSEB_S3_BUCKET/$AWSEB_S3_KEY/$AWSEB_RELEASE_VERSION" --expire "$(date -d "+15 days" -u +"%Y-%m-%dT%H:%M:%SZ")"
} || {
return 1
}
}
function eb() {
{
aws elasticbeanstalk create-application-version \
--application-name "$AWSEB_APP_NAME" \
--version-label "$AWSEB_RELEASE_VERSION" \
--description "Automatic Deployment for $AWSEB_RELEASE_VERSION" \
--source-bundle S3Bucket="$AWSEB_S3_BUCKET",S3Key="$AWSEB_S3_KEY/$AWSEB_RELEASE_VERSION" --auto-create-application
} || {
echo "An error occurred while trying to execute aws eb create-application-version command."
return 1
}
{
aws elasticbeanstalk update-environment \
--application-name "$AWSEB_APP_NAME" \
--environment-name "$AWSEB_ENV_NAME" \
--version-label "$AWSEB_RELEASE_VERSION"
} || {
echo "An error occurred while trying to execute aws eb update-environment command."
return 1
}
}
printf "Starting the AWS Beanstalk deployment\n"
if [[ $# -ne 0 ]]; then
if ([[ -n "$1" ]]) && [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
usage && exit 0
fi
fi
if [[ -n "$LOCALDIR_RELEASE_VERSION" ]] && [[ -n "$AWSEB_S3_BUCKET" ]] && [[ -n "$AWSEB_S3_KEY" ]] && [[ -n "$AWSEB_RELEASE_VERSION" ]]; then
s3 || { printf "An error occurred while trying to execute aws s3 command" && exit 1; }
if [[ -n "$AWSEB_APP_NAME" ]] && [[ -n "$AWSEB_ENV_NAME" ]]; then
eb || { printf "An error occurred while trying to execute aws eb command" && exit 1; }
printf "Ending the AWS Beanstalk deployment"
printf "AWS Beanstalk deployment is done"
exit 0
fi
fi
printf "The environment variables are null\n"
exit 1