Skip to content

Instantly share code, notes, and snippets.

@moinsam
Created December 6, 2016 06:35
Show Gist options
  • Save moinsam/441a3d5e8cc19a3b04be89010e24d0b1 to your computer and use it in GitHub Desktop.
Save moinsam/441a3d5e8cc19a3b04be89010e24d0b1 to your computer and use it in GitHub Desktop.
Bash Script to build and push Docker image into ECR
#!/bin/bash
if [ $# -eq 0 ]; then
echo "No arguments provided"
exit 1
fi
if [[ -z $2 ]]; then
echo ---------------Node-----------------
node --version
echo ---------------Npm------------------
npm --version
echo --------------Grunt-----------------
grunt --version
echo --------------Bower-----------------
bower --version
echo ------Update bower packages---------
bower update
echo -----Update npm dependencies--------
npm update
echo --------Build the project-----------
grunt clean build:$1
else
NODE_HOME = "$2"
echo "argument supplied " + $NODE_HOME
echo ---------------Node-----------------
$NODE_HOME/bin/node --version
echo ---------------Npm------------------
$NODE_HOME/bin/npm --version
echo --------------Grunt-----------------
$NODE_HOME/bin/grunt --version
echo --------------Bower-----------------
$NODE_HOME/bin/bower --version
echo ------Update bower packages---------
$NODE_HOME/bin/bower update
echo -----Update npm dependencies--------
$NODE_HOME/bin/npm update
echo --------Build the project-----------
$NODE_HOME/bin/grunt clean build:$1
fi
echo Get the project version from buidconfig.json
# Version key/value should be on his own line
NAME=$(cat buildconfig.json \
| grep name \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo $NAME
VERSION=$(cat buildconfig.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo $VERSION
REPO=$(cat buildconfig.json \
| grep repo \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo $REPO
REGION=$(cat buildconfig.json \
| grep region \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
echo $REGION
echo Login to ECR
eval $(aws ecr get-login --region $REGION)
echo Docker Build and Push
docker build -t $REPO/$NAME:$VERSION --no-cache=true .
docker push $REPO/$NAME:$VERSION
@moinsam
Copy link
Author

moinsam commented Dec 6, 2016

to run this script you have to send a parameter as commend line argument like below,

./docker-build.sh testing

Here possible parameter can be "development", "testing" and "production". This

To get the dockerconfig.json file see dockerconfig.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment