-
Notifications
You must be signed in to change notification settings - Fork 20
/
push-image-to-nexus.sh
55 lines (37 loc) · 1.94 KB
/
push-image-to-nexus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
# Build & upload docker image to Nexus
#
#
# Validate that this is a valid branch for CI/CD
#
export BRANCH_NAME=`echo "${TRAVIS_BRANCH}" | tr '[:upper:]' '[:lower:]'`
case "${BRANCH_NAME}" in
dev*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
ao-dev*)echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
qa*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
qe*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
rc*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
release-master*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
ft*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI" ;;
bf*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI" ;;
*) echo "Not a valid branch name for CI/CD" && exit -1;;
esac
echo $TRAVIS_BRANCH
echo ${DEPLOYMENT_SERVER}
export SHORT_COMMIT=`git rev-parse --short=7 ${TRAVIS_COMMIT}`
echo "short commit $SHORT_COMMIT"
sudo apt-get update
sudo apt-get install -y jq
IMAGE_NAME=`echo "${BUILD_REPO_NAME}_${TRAVIS_BRANCH}" | tr '[:upper:]' '[:lower:]'`
PACKAGE_NAME=`jq '.name' version.json | tr -d '"'`
PACKAGE_VERSION=`jq '.version' version.json | tr -d '"'`
echo "Package name & version : ${PACKAGE_NAME} $PACKAGE_VERSION "
docker build -t ${IMAGE_NAME}:${SHORT_COMMIT} --build-arg PackageName=${PACKAGE_NAME} --build-arg PackageVersion=${PACKAGE_VERSION} --build-arg NexusUser=${NEXUS_USER} --build-arg NexusPassword=${NEXUS_USER_PWD} -f Dockerfile_django .
sleep 3
docker image ls
if [ ${TRAVIS_PULL_REQUEST} != "false" ]; then echo "Not publishing a pull request !!!" && exit 0; fi
echo "uploading to DJANGO_IMAGE_NAME nexus" ${PACKAGE_NAME}
docker login -u ${NEXUS_USER} -p ${NEXUS_USER_PWD} ${NEXUS_CR_TOOLS_URL}
docker tag ${IMAGE_NAME}:${SHORT_COMMIT} ${NEXUS_CR_TOOLS_URL}/froala-${IMAGE_NAME}:${PACKAGE_VERSION}
docker push ${NEXUS_CR_TOOLS_URL}/froala-${IMAGE_NAME}:${PACKAGE_VERSION}