Skip to content

Commit 7589912

Browse files
author
Sandip Das
committed
code changes
1 parent c6aebf8 commit 7589912

File tree

6 files changed

+90
-17
lines changed

6 files changed

+90
-17
lines changed

buildspec.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
version: 0.2
2+
run-as: root
3+
4+
25
phases:
3-
install:
4-
runtime-versions:
5-
nodejs: 12
6-
commands:
7-
- echo Getting Started
86
pre_build:
97
commands:
10-
- echo Installing some packages and source NPM dependencies...
11-
- npm install -g json
12-
- chmod +x ./build_scripts/create_configuration.sh
13-
- sh ./build_scripts/create_configuration.sh
14-
- npm install
15-
- aws --version
8+
- echo Logging in to Amazon ECR...
9+
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
10+
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
11+
- docker pull $REPOSITORY_URI:$IMAGE_TAG
1612
build:
1713
commands:
1814
- echo Build started on `date`
19-
- echo Run all of your build related code if any
20-
- echo Build finished, now moving to S3
15+
- echo Building the Docker image...
16+
- docker build --cache-from $REPOSITORY_URI:$IMAGE_TAG -t $IMAGE_REPO_NAME:$IMAGE_TAG .
17+
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
2118
post_build:
2219
commands:
2320
- echo Build completed on `date`
24-
artifacts:
25-
files:
26-
- '**/*'
21+
- echo Pushing the Docker image...
22+
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
23+
- echo Writing image definitions file...
24+
- printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
25+
cache:
26+
paths:
27+
- '/root/.m2/**/*'
28+
- '/root/.npm/**/*'
29+
- 'node_modules/**/*'

buildspec_normal.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: 0.2
2+
phases:
3+
install:
4+
runtime-versions:
5+
nodejs: 12
6+
commands:
7+
- echo Getting Started
8+
pre_build:
9+
commands:
10+
- echo Installing some packages and source NPM dependencies...
11+
- npm install -g json
12+
- chmod +x ./build_scripts/create_configuration.sh
13+
- sh ./build_scripts/create_configuration.sh
14+
- npm install
15+
- aws --version
16+
build:
17+
commands:
18+
- echo Build started on `date`
19+
- echo Run all of your build related code if any
20+
- echo Build finished, now moving to S3
21+
post_build:
22+
commands:
23+
- echo Build completed on `date`
24+
artifacts:
25+
files:
26+
- '**/*'

db_backup_and_upload.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /bin/bash
2+
# DB_FILE_BACKUP_NAME="dbname.sql"
3+
# S3_BUCKET_NAME="sample-bucket-sandip"
4+
5+
#mysqldump --add-drop-table -u admin -p`cat /etc/psa/.psa.shadow` dbname > $DB_FILE_BACKUP_NAME
6+
7+
8+
9+
if ! type aws >/dev/null 2>&1; then
10+
echo "we don't have aws sli installed, so installing aws cli"
11+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
12+
unzip awscliv2.zip
13+
sudo ./aws/install
14+
else
15+
echo "we aws cli installed, so continuing"
16+
fi
17+
18+
aws s3 cp $DB_FILE_BACKUP_NAME "s3://${S3_BUCKET_NAME}"

dbname.sql

Whitespace-only changes.

docker_image_push.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /bin/bash
2+
profile="default"
3+
region="us-west-2"
4+
buildTag="shellscript-demo:latest"
5+
6+
echo "$1"
7+
echo "$2"
8+
echo "$3"
9+
10+
if [[ -n "$1" ]]; then
11+
profile="$1"
12+
fi
13+
14+
if [[ -n "$2" ]]; then
15+
region="$2"
16+
fi
17+
18+
if [[ -n "$3" ]]; then
19+
region="$3"
20+
fi
21+
22+
23+
aws ecr get-login-password --region "${region}" --profile "${profile}" | docker login --username AWS --password-stdin "120717539064.dkr.ecr.${region}.amazonaws.com"
24+
docker build -t "${buildTag}" .
25+
docker tag "${buildTag}" "120717539064.dkr.ecr.us-west-2.amazonaws.com/${buildTag}"
26+
docker push "120717539064.dkr.ecr.us-west-2.amazonaws.com/${buildTag}"

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const config = require('config')
55
console.log(config);
66

77
app.get('/', (req, res) => {
8-
res.send('CICD App V5!')
8+
res.send('CICD App V1!')
99
})
1010

1111
app.get('/status', (req, res) => {

0 commit comments

Comments
 (0)