Skip to content

Commit 05051a9

Browse files
committed
Added create app version and deploy steps
1 parent b7b543e commit 05051a9

File tree

6 files changed

+72
-9
lines changed

6 files changed

+72
-9
lines changed

.DS_Store

6 KB
Binary file not shown.

Dockerrun.aws.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"AWSEBDockerrunVersion": "1",
3+
"Image": {
4+
"Name": "account.dkr.ecr.eu-west-2.amazonaws.com/gatekeeper:0.0.0"
5+
},
6+
"Ports": [
7+
{
8+
"ContainerPort": 80,
9+
"HostPort": 80
10+
}
11+
]
12+
}

Jenkinsfile

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,60 @@ pipeline {
7474
}
7575
}
7676
}
77+
stage('Create Elastic Beanstalk application version') {
78+
when {
79+
buildingTag()
80+
}
81+
environment {
82+
AWS_ACCESS_KEY_ID = credentials('home-server-aws-access-key')
83+
AWS_SECRET_ACCESS_KEY = credentials('home-server-aws-secret-key')
84+
AWS_DEFAULT_REGION = 'eu-west-2'
85+
HS_ACCOUNT_ID = credentials('home-server-aws-account-id')
86+
}
87+
steps {
88+
script {
89+
sh '''
90+
./build/aws/build-eb-zip.sh ${TAG_NAME} ${HS_ACCOUNT_ID};
91+
aws s3 cp gatekeeper-${TAG_NAME}.zip s3://elasticbeanstalk-${AWS_DEFAULT_REGION}-${HS_ACCOUNT_ID}/gatekeeper-${TAG_NAME}.zip;
92+
aws elasticbeanstalk create-application-version \
93+
--application-name gatekeeper \
94+
--version-label ${TAG_NAME} \
95+
--source-bundle S3Bucket="elasticbeanstalk-${AWS_DEFAULT_REGION}-${HS_ACCOUNT_ID}",S3Key="gatekeeper-${TAG_NAME}.zip" \
96+
--region=${AWS_DEFAULT_REGION};
97+
'''
98+
}
99+
}
100+
}
101+
stage('Deploy to environment') {
102+
when {
103+
buildingTag()
104+
}
105+
environment {
106+
AWS_ACCESS_KEY_ID = credentials('home-server-aws-access-key')
107+
AWS_SECRET_ACCESS_KEY = credentials('home-server-aws-secret-key')
108+
AWS_DEFAULT_REGION = 'eu-west-2'
109+
HS_ACCOUNT_ID = credentials('home-server-aws-account-id')
110+
}
111+
steps {
112+
script {
113+
sh '''
114+
aws elasticbeanstalk update-environment \
115+
--application-name gatekeeper \
116+
--environment-name ws-prod \
117+
--version-label ${TAG_NAME} \
118+
--region=${AWS_DEFAULT_REGION};
119+
'''
120+
}
121+
}
122+
}
77123
}
78124
post {
79125
always {
80-
cleanWs()
81126
script {
82127
sh 'docker compose -f docker-compose-mongo.yml down -v'
83128
sh "docker image rm cjww-development/gatekeeper:${env.TAG_NAME}"
84129
}
130+
cleanWs()
85131
}
86132
}
87133
}

build/.DS_Store

6 KB
Binary file not shown.

build/aws/.DS_Store

6 KB
Binary file not shown.

build/aws/assume-role.sh renamed to build/aws/build-eb-zip.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env sh
2-
31
#
42
# Copyright 2022 CJWW Development
53
#
@@ -16,11 +14,18 @@
1614
# limitations under the License.
1715
#
1816

19-
set +x
17+
VERSION=$1
18+
ACC_ID=$2
19+
20+
mkdir gatekeeper
21+
22+
cp Dockerrun.aws.json gatekeeper
23+
24+
sed -i "" -e "s/gatekeeper.*\"/gatekeeper:${VERSION}\"/" gatekeeper/Dockerrun.aws.json
25+
sed -i "" -e "s/account/${ACC_ID}/g" gatekeeper/Dockerrun.aws.json
2026

21-
OUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name tmp);
22-
export AWS_ACCESS_KEY_ID=$(echo $OUT | jq -r '.Credentials''.AccessKeyId');
23-
export AWS_SECRET_ACCESS_KEY=$(echo $OUT | jq -r '.Credentials''.SecretAccessKey');
24-
export AWS_SESSION_TOKEN=$(echo $OUT | jq -r '.Credentials''.SessionToken');
27+
cd gatekeeper
28+
zip -r ../gatekeeper-${VERSION}.zip .
29+
cd ..
2530

26-
set -x
31+
rm -rf gatekeeper

0 commit comments

Comments
 (0)