Skip to content

Commit 82c727b

Browse files
Merge pull request #115 from appirio-tech/dev
Merge to Master from Dev
2 parents a6b67f2 + 2eb68dd commit 82c727b

File tree

4 files changed

+304
-37
lines changed

4 files changed

+304
-37
lines changed

.circleci/config.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
version: 2
2+
jobs:
3+
"build-dev":
4+
docker:
5+
- image: circleci/openjdk:8-jdk
6+
steps:
7+
# Initialization1.
8+
- run: git clone --branch master https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
9+
- checkout
10+
- run:
11+
name: Installation of build dependencies.
12+
command: |
13+
sudo apt install jq
14+
sudo apt install awscli
15+
- run:
16+
name: Configuring maven
17+
command: |
18+
MVNSERVERSETTING='<server>\n <id>tcrepo</id> \n <username>${env.MVNUSERNAME}</username> \n <password>${env.MVNPASSWD}</password> \n </server> '
19+
C=$(echo $MVNSERVERSETTING | sed 's/\//\\\//g')
20+
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
21+
MVNSERVERSETTING='<server>\n <id>tcreposnap</id> \n <username>${env.MVNUSERNAME}</username> \n <password>${env.MVNPASSWD}</password> \n </server> '
22+
C=$(echo $MVNSERVERSETTING | sed 's/\//\\\//g')
23+
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
24+
- setup_remote_docker
25+
- restore_cache:
26+
key: ap-review-microservice-{{ checksum "~/project/service/pom.xml" }}
27+
- run: mvn -f ~/project/service/pom.xml dependency:go-offline
28+
- save_cache:
29+
paths:
30+
- ~/.m2
31+
key: ap-review-microservice-{{ checksum "~/project/service/pom.xml" }}
32+
- run: mvn -f ~/project/service/pom.xml clean site package
33+
- run:
34+
name: Save test results
35+
command: |
36+
mkdir -p ~/junit/
37+
find . -type f -regex ".*/target/site/cobertura/coverage.xml" -exec cp {} ~/junit/ \;
38+
# find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \;
39+
when: always
40+
- store_test_results:
41+
path: ~/junit
42+
- store_artifacts:
43+
path: ~/junit
44+
- run: docker --version
45+
- run:
46+
name: Deploy to AWS
47+
command: |
48+
chmod +x /home/circleci/project/service/build/deploy.sh
49+
/home/circleci/project/service/build/deploy.sh /home/circleci/project /home/circleci/project/service/build ap-review dev
50+
51+
"build-prod":
52+
docker:
53+
- image: circleci/openjdk:8-jdk
54+
steps:
55+
# Initialization1.
56+
- run: git clone --branch master https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
57+
- checkout
58+
- run:
59+
name: Installation of build dependencies.
60+
command: |
61+
sudo apt install jq
62+
sudo apt install awscli
63+
- run:
64+
name: Configuring maven
65+
command: |
66+
MVNSERVERSETTING='<server>\n <id>tcrepo</id> \n <username>${env.MVNUSERNAME}</username> \n <password>${env.MVNPASSWD}</password> \n </server> '
67+
C=$(echo $MVNSERVERSETTING | sed 's/\//\\\//g')
68+
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
69+
MVNSERVERSETTING='<server>\n <id>tcreposnap</id> \n <username>${env.MVNUSERNAME}</username> \n <password>${env.MVNPASSWD}</password> \n </server> '
70+
C=$(echo $MVNSERVERSETTING | sed 's/\//\\\//g')
71+
sudo sed -i.bak "/<\/servers>/ s/.*/${C}\n&/" /opt/apache-maven/conf/settings.xml
72+
- setup_remote_docker
73+
- restore_cache:
74+
key: ap-review-microservice-{{ checksum "~/project/service/pom.xml" }}
75+
- run: mvn -f ~/project/service/pom.xml dependency:go-offline
76+
- save_cache:
77+
paths:
78+
- ~/.m2
79+
key: ap-review-microservice-{{ checksum "~/project/service/pom.xml" }}
80+
- run: mvn -f ~/project/service/pom.xml clean site package
81+
- run:
82+
name: Save test results
83+
command: |
84+
mkdir -p ~/junit/
85+
find . -type f -regex ".*/target/site/cobertura/coverage.xml" -exec cp {} ~/junit/ \;
86+
# find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \;
87+
when: always
88+
- store_test_results:
89+
path: ~/junit
90+
- store_artifacts:
91+
path: ~/junit
92+
- run: docker --version
93+
- run:
94+
name: Deploy to AWS
95+
command: |
96+
chmod +x /home/circleci/project/service/build/deploy.sh
97+
/home/circleci/project/service/build/deploy.sh /home/circleci/project /home/circleci/project/service/build ap-review prod
98+
99+
workflows:
100+
version: 2
101+
build:
102+
jobs:
103+
# Development builds are executed on "develop" branch only.
104+
- "build-dev":
105+
filters:
106+
branches:
107+
only: dev
108+
- "build-prod":
109+
filters:
110+
branches:
111+
only: prod

service/build/buildimage.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
# Define script variables
3+
WORKSPACE=$1
4+
DEPLOY_DIR=$2
5+
SERVICE=$3
6+
APINAME=$3 #ap-review
7+
CONFIG=$4
8+
ENV=$4
9+
10+
11+
REPO="${SERVICE}-microservice"
12+
TAG="${REPO}:${CONFIG}.${VER}"
13+
IMAGE="${REGISTRY}/${TAG}"
14+
15+
16+
DOCKER_REPO=appiriodevops
17+
VER=`date "+%Y%m%d%H%M"`
18+
IMAGE="$SERVICE-microservice:$ENV.$VER"
19+
20+
DOCKERRUN_TEMPLATE=$DEPLOY_DIR/Dockerrun.aws.json.template
21+
DOCKERRUN=$DEPLOY_DIR/Dockerrun.aws.json
22+
AWS_S3_BUCKET=appirio-platform-dev
23+
AWS_PROFILE="tc-$ENV"
24+
AWS_S3_KEY="services/docker/$IMAGE"
25+
ENV_JAVA_PARAMS=" "
26+
ENV_CONFIG=`echo "$ENV" | tr '[:lower:]' '[:upper:]'`
27+
28+
AWS_REGION=$(eval "echo \$${ENV_CONFIG}_AWS_REGION")
29+
AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV_CONFIG}_AWS_ACCESS_KEY_ID")
30+
AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV_CONFIG}_AWS_SECRET_ACCESS_KEY")
31+
32+
configure_aws_cli() {
33+
aws --version
34+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
35+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
36+
aws configure set default.region $AWS_REGION
37+
aws configure set default.output json
38+
echo "Configured AWS CLI."
39+
}
40+
41+
configure_aws_cli
42+
43+
# Elastic Beanstalk Application name
44+
# dev
45+
APPNAME="Development"
46+
if [ "$ENV" = "qa" ]; then
47+
APPNAME="QA"
48+
fi
49+
if [ "$ENV" = "prod" ]; then
50+
APPNAME="Production"
51+
AWS_S3_BUCKET=appirio-platform-prod
52+
ENV_JAVA_PARAMS='-Xmx3g -Dnewrelic.environment=production -javaagent:$NEWRELIC_JAR'
53+
fi
54+
55+
cd $DEPLOY_DIR
56+
57+
echo "Generating Dockerfile"
58+
cat Dockerfile.template | sed -e "s/@ENV_JAVA_PARAMS@/$ENV_JAVA_PARAMS/g" > Dockerfile
59+
60+
echo "Generate sumo config files"
61+
cat sumo.conf.template | sed -e "s/@env@/${ENV}/g" > sumo.conf
62+
cat sumo-sources.json.template | sed -e "s/@env@/${ENV}/g" > sumo-sources.json
63+
64+
echo "Copying deployment files to build folder"
65+
cp $WORKSPACE/service/target/review-microservice*.jar review-microservice.jar
66+
cp $WORKSPACE/service/src/main/resources/review-service.yaml review-service.yaml
67+
68+
echo "Generating Docker aws json......."
69+
PLATFORM_BUCKET=appirio-platform-$CONFIG
70+
EBDOCKER_FILENAME=${APINAME}-${CONFIG}.${VER}.aws.json
71+
cat $WORKSPACE/service/build/Dockerrun.aws.json.template | sed -e "s/@IMAGE@/${IMAGE}/g" > ./$EBDOCKER_FILENAME
72+
cat ./$EBDOCKER_FILENAME
73+
74+
echo "copying beanstalk docker file..."
75+
aws s3 cp $EBDOCKER_FILENAME s3://$PLATFORM_BUCKET/services/elasticbeanstalk/
76+
77+
echo "copying dockercfg......"
78+
aws s3 cp "s3://appirio-platform-$ENV/services/common/dockercfg" ~/.dockercfg
79+
80+
echo "Building docker image $DOCKER_REPO/$IMAGE"
81+
docker build -t $DOCKER_REPO/$IMAGE $DEPLOY_DIR
82+
83+
VER1="$ENV.$VER"
84+
echo export TAGNAME="$VER1" >> "$BASH_ENV"

service/build/deploy.sh

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,42 @@
33
WORKSPACE=$1
44
DEPLOY_DIR=$2
55
SERVICE=$3
6+
APINAME=$3 #ap-review
7+
CONFIG=$4
68
ENV=$4
79

10+
11+
REPO="${SERVICE}-microservice"
12+
TAG="${REPO}:${CONFIG}.${VER}"
13+
IMAGE="${REGISTRY}/${TAG}"
14+
15+
816
DOCKER_REPO=appiriodevops
917
VER=`date "+%Y%m%d%H%M"`
1018
IMAGE="$SERVICE-microservice:$ENV.$VER"
19+
1120
DOCKERRUN_TEMPLATE=$DEPLOY_DIR/Dockerrun.aws.json.template
1221
DOCKERRUN=$DEPLOY_DIR/Dockerrun.aws.json
1322
AWS_S3_BUCKET=appirio-platform-dev
1423
AWS_PROFILE="tc-$ENV"
1524
AWS_S3_KEY="services/docker/$IMAGE"
1625
ENV_JAVA_PARAMS=" "
26+
ENV_CONFIG=`echo "$ENV" | tr '[:lower:]' '[:upper:]'`
27+
28+
AWS_REGION=$(eval "echo \$${ENV_CONFIG}_AWS_REGION")
29+
AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV_CONFIG}_AWS_ACCESS_KEY_ID")
30+
AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV_CONFIG}_AWS_SECRET_ACCESS_KEY")
31+
32+
configure_aws_cli() {
33+
aws --version
34+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
35+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
36+
aws configure set default.region $AWS_REGION
37+
aws configure set default.output json
38+
echo "Configured AWS CLI."
39+
}
40+
41+
configure_aws_cli
1742

1843
# Elastic Beanstalk Application name
1944
# dev
@@ -40,24 +65,49 @@ echo "Copying deployment files to build folder"
4065
cp $WORKSPACE/service/target/review-microservice*.jar review-microservice.jar
4166
cp $WORKSPACE/service/src/main/resources/review-service.yaml review-service.yaml
4267

68+
echo "Generating Docker aws json......."
69+
PLATFORM_BUCKET=appirio-platform-$CONFIG
70+
EBDOCKER_FILENAME=${APINAME}-${CONFIG}.${VER}.aws.json
71+
cat $WORKSPACE/service/build/Dockerrun.aws.json.template | sed -e "s/@IMAGE@/${IMAGE}/g" > ./$EBDOCKER_FILENAME
72+
cat ./$EBDOCKER_FILENAME
73+
74+
echo "copying beanstalk docker file..."
75+
aws s3 cp $EBDOCKER_FILENAME s3://$PLATFORM_BUCKET/services/elasticbeanstalk/
76+
77+
echo "copying dockercfg......"
78+
aws s3 cp "s3://appirio-platform-$ENV/services/common/dockercfg" ~/.dockercfg
79+
#eval $(aws ecr get-login --region $AWS_REGION --no-include-email)
80+
# Builds Docker image of the app.
81+
#TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$AWS_REPOSITORY:$CIRCLE_SHA1
82+
4383
echo "Building docker image $DOCKER_REPO/$IMAGE"
4484
docker build -t $DOCKER_REPO/$IMAGE $DEPLOY_DIR
4585

4686
echo "Pushing image to docker $DOCKER_REPO/$IMAGE"
4787
#docker login -u ykohata
4888
docker push $DOCKER_REPO/$IMAGE
4989

50-
echo "Generating dockerrun file"
51-
cat $DOCKERRUN_TEMPLATE | sed -e "s/@IMAGE@/${IMAGE}/g" > $DOCKERRUN
90+
# echo "Generating dockerrun file"
91+
# cat $DOCKERRUN_TEMPLATE | sed -e "s/@IMAGE@/${IMAGE}/g" > $DOCKERRUN
92+
93+
# echo "Uploading dockerrun file to aws"
94+
95+
# echo "Pushing Dockerrun.aws.json to S3: ${AWS_S3_BUCKET}/${AWS_S3_KEY}"
96+
# aws s3api put-object --bucket "${AWS_S3_BUCKET}" --key "${AWS_S3_KEY}" --body $DOCKERRUN
5297

53-
echo "Uploading dockerrun file to aws"
98+
#EBVERSION=${APINAME}-${CONFIG}.${VER}
5499

55-
echo "Pushing Dockerrun.aws.json to S3: ${AWS_S3_BUCKET}/${AWS_S3_KEY}"
56-
aws s3api put-object --profile $AWS_PROFILE --bucket "${AWS_S3_BUCKET}" --key "${AWS_S3_KEY}" --body $DOCKERRUN
100+
#aws elasticbeanstalk create-application-version --application-name ${APPNAME} --version-label ${EBVERSION} --source-bundle S3Bucket=${PLATFORM_BUCKET},S3Key=services/elasticbeanstalk/$EBDOCKER_FILENAME
101+
102+
#echo "Creating new application version $IMAGE in $APPNAME from s3:${AWS_S3_BUCKET}/${AWS_S3_KEY}"
103+
#aws elasticbeanstalk create-application-version --application-name $APPNAME --version-label $IMAGE --source-bundle S3Bucket="$AWS_S3_BUCKET",S3Key="$AWS_S3_KEY"
104+
105+
# assumes beanstalk app for this service has already been created and configured
106+
#aws elasticbeanstalk update-environment --environment-name $APINAME --version-label $EBVERSION
57107

58-
echo "Creating new application version $IMAGE in $APPNAME from s3:${AWS_S3_BUCKET}/${AWS_S3_KEY}"
59-
aws elasticbeanstalk create-application-version --profile $AWS_PROFILE --application-name $APPNAME --version-label $IMAGE --source-bundle S3Bucket="$AWS_S3_BUCKET",S3Key="$AWS_S3_KEY"
108+
echo "Creating new EBS application version \n"
109+
aws elasticbeanstalk create-application-version --application-name $APPNAME --version-label $IMAGE --source-bundle S3Bucket=${PLATFORM_BUCKET},S3Key=services/elasticbeanstalk/$EBDOCKER_FILENAME
60110

61-
echo "updating elastic beanstalk environment ${AWS_EB_ENV} with the version $IMAGE."
111+
echo "Updating EBS with the version $IMAGE \n"
62112
# assumes beanstalk app for this service has already been created and configured
63-
aws elasticbeanstalk --profile $AWS_PROFILE update-environment --environment-name $SERVICE-$ENV --version-label $IMAGE
113+
aws elasticbeanstalk update-environment --environment-name $SERVICE-$ENV --version-label $IMAGE

0 commit comments

Comments
 (0)