Last active
July 30, 2020 17:32
-
-
Save vsdsantos/f6787fc6f472cc91dff688f25de71581 to your computer and use it in GitHub Desktop.
Clone repository and deploy on Docker Container
This file contains 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 | |
GIT_USERNAME= | |
REPOSITORY= | |
BRANCH="master" | |
GIT_PROTOCOL="https" | |
NAME= | |
TAG="latest" | |
while [ "$1" != "" ]; do | |
case $1 in | |
-u | --username ) shift | |
GIT_USERNAME=$1 | |
;; | |
-b | --branch ) shift | |
BRANCH=$1 | |
;; | |
-r | --repository ) shift | |
REPOSITORY=$1 | |
;; | |
-n | --name ) shift | |
NAME=$1 | |
;; | |
-t | --tag ) shift | |
TAG=$1 | |
;; | |
--ssh ) GIT_PROTOCOL="ssh" | |
esac | |
shift | |
done | |
echo "Creating and cleaning src folder..." | |
mkdir src | |
cd src | |
rm -rf $NAME | |
echo "Cloning repository..." | |
if [ "$GIT_PROTOCOL" = "https" ]; then | |
git clone $GIT_PROTOCOL://$GIT_USERNAME@$REPOSITORY $NAME || { exit 1; } | |
else | |
git clone git@$REPOSITORY $NAME || { exit 1; } | |
fi | |
cd $NAME && git checkout $BRANCH || { exit 1; } | |
echo "Building Docker image..." | |
docker build -t $NAME:$TAG . || { exit 1; } | |
echo "Deploing container..." | |
docker stop $NAME && docker rm $NAME | |
docker run --name $NAME -d $NAME:$TAG || { exit 1; } | |
echo 'Deploy successfull!' | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment