Created
December 6, 2016 06:35
-
-
Save moinsam/441a3d5e8cc19a3b04be89010e24d0b1 to your computer and use it in GitHub Desktop.
Bash Script to build and push Docker image into ECR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to run this script you have to send a parameter as commend line argument like below,
Here possible parameter can be "development", "testing" and "production". This
To get the dockerconfig.json file see dockerconfig.json