Review build script
This commit is contained in:
parent
8883354cfc
commit
216258c4d1
@ -8,6 +8,7 @@
|
||||
/.editorconfig
|
||||
/.gitignore
|
||||
/.travis.yml
|
||||
/build.sh
|
||||
/CHANGELOG.md
|
||||
/LICENSE
|
||||
/README.md
|
||||
|
36
.travis.yml
36
.travis.yml
@ -6,8 +6,10 @@ services:
|
||||
env:
|
||||
global:
|
||||
- VERSION=17955
|
||||
- DOCKER_LOGIN=crazymax
|
||||
- DOCKER_USERNAME=crazymax
|
||||
- DOCKER_REPONAME=jetbrains-license-server
|
||||
- QUAY_LOGIN=crazymax
|
||||
- QUAY_USERNAME=crazymax
|
||||
- QUAY_REPONAME=jetbrains-license-server
|
||||
- MICROBADGER_HOOK=https://hooks.microbadger.com/images/crazymax/jetbrains-license-server/PWF7sHnaK1djP4E9r5VY5suUqVk=
|
||||
@ -17,40 +19,8 @@ env:
|
||||
before_install:
|
||||
- sudo apt-get update
|
||||
- docker --version
|
||||
- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
|
||||
- export DOCKER_TAG=$(if [ "$BRANCH" == "master" ]; then echo "latest"; else echo $BRANCH; fi)
|
||||
- export WAN_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
|
||||
- echo "WAN_IP=$WAN_IP, TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH, DOCKER_TAG=$DOCKER_TAG"
|
||||
|
||||
install:
|
||||
- |
|
||||
docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
|
||||
--build-arg VCS_REF=${TRAVIS_COMMIT::8} \
|
||||
--build-arg VERSION=${VERSION} \
|
||||
-t docker_build .
|
||||
|
||||
before_script:
|
||||
- docker run -d -p 8000:80 -e JLS_VIRTUAL_HOSTS=$WAN_IP --name $DOCKER_REPONAME docker_build
|
||||
- sleep 20
|
||||
- docker logs $DOCKER_REPONAME
|
||||
|
||||
script:
|
||||
- docker ps | grep $DOCKER_REPONAME
|
||||
- |
|
||||
test $TRAVIS_PULL_REQUEST = false \
|
||||
&& echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin \
|
||||
&& docker tag docker_build $DOCKER_USERNAME/$DOCKER_REPONAME:$DOCKER_TAG \
|
||||
&& docker tag docker_build $DOCKER_USERNAME/$DOCKER_REPONAME:$VERSION \
|
||||
&& docker push $DOCKER_USERNAME/$DOCKER_REPONAME \
|
||||
&& curl -X POST $MICROBADGER_HOOK \
|
||||
&& echo "$QUAY_PASSWORD" | docker login quay.io --username "$QUAY_USERNAME" --password-stdin \
|
||||
&& docker tag docker_build quay.io/$DOCKER_USERNAME/$DOCKER_REPONAME:$DOCKER_TAG \
|
||||
&& docker tag docker_build quay.io/$DOCKER_USERNAME/$DOCKER_REPONAME:$VERSION \
|
||||
&& docker push quay.io/$QUAY_USERNAME/$QUAY_REPONAME
|
||||
|
||||
branches:
|
||||
except:
|
||||
- /^[0-9]/
|
||||
script: ./build.sh
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
|
115
build.sh
Normal file
115
build.sh
Normal file
@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
PROJECT=jetbrains-licenses-server
|
||||
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
BUILD_TAG=docker_build
|
||||
VCS_REF=${TRAVIS_COMMIT::8}
|
||||
RUNNING_TIMEOUT=120
|
||||
RUNNING_LOG_CHECK="is listening on"
|
||||
|
||||
PUSH_LATEST=${PUSH_LATEST:-true}
|
||||
DOCKER_USERNAME=${DOCKER_USERNAME:="crazymax"}
|
||||
DOCKER_LOGIN=${DOCKER_LOGIN:="crazymax"}
|
||||
DOCKER_REPONAME=${DOCKER_REPONAME:="jetbrains-licenses-server"}
|
||||
QUAY_USERNAME=${QUAY_USERNAME:="crazymax"}
|
||||
QUAY_LOGIN=${QUAY_LOGIN:="crazymax"}
|
||||
QUAY_REPONAME=${QUAY_REPONAME:="jetbrains-licenses-server"}
|
||||
|
||||
# Check local or travis
|
||||
BRANCH=${TRAVIS_BRANCH:-local}
|
||||
if [[ ${TRAVIS_PULL_REQUEST} == "true" ]]; then
|
||||
BRANCH=${TRAVIS_PULL_REQUEST_BRANCH}
|
||||
fi
|
||||
DOCKER_TAG=${BRANCH:-local}
|
||||
if [[ "$BRANCH" == "master" ]]; then
|
||||
DOCKER_TAG=latest
|
||||
elif [[ "$BRANCH" == "local" ]]; then
|
||||
BUILD_DATE=
|
||||
VERSION=local
|
||||
fi
|
||||
|
||||
echo "PROJECT=${PROJECT}"
|
||||
echo "VERSION=${VERSION}"
|
||||
echo "BUILD_DATE=${BUILD_DATE}"
|
||||
echo "BUILD_TAG=${BUILD_TAG}"
|
||||
echo "VCS_REF=${VCS_REF}"
|
||||
echo "PUSH_LATEST=${PUSH_LATEST}"
|
||||
echo "DOCKER_LOGIN=${DOCKER_LOGIN}"
|
||||
echo "DOCKER_USERNAME=${DOCKER_USERNAME}"
|
||||
echo "DOCKER_REPONAME=${DOCKER_REPONAME}"
|
||||
echo "QUAY_LOGIN=${QUAY_LOGIN}"
|
||||
echo "QUAY_USERNAME=${QUAY_USERNAME}"
|
||||
echo "QUAY_REPONAME=${QUAY_REPONAME}"
|
||||
echo "TRAVIS_BRANCH=${TRAVIS_BRANCH}"
|
||||
echo "TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}"
|
||||
echo "BRANCH=${BRANCH}"
|
||||
echo "DOCKER_TAG=${DOCKER_TAG}"
|
||||
echo
|
||||
|
||||
# Build
|
||||
echo "### Build"
|
||||
docker build \
|
||||
--build-arg BUILD_DATE=${BUILD_DATE} \
|
||||
--build-arg VCS_REF=${VCS_REF} \
|
||||
--build-arg VERSION=${VERSION} \
|
||||
-t ${BUILD_TAG} .
|
||||
echo
|
||||
|
||||
echo "### Test"
|
||||
docker rm -f ${PROJECT} || true
|
||||
docker run -d -p 8000:80 \
|
||||
-e "JLS_VIRTUAL_HOSTS=docker.test" \
|
||||
--name ${PROJECT} ${BUILD_TAG}
|
||||
echo
|
||||
|
||||
echo "### Waiting for ${PROJECT} to be up..."
|
||||
TIMEOUT=$((SECONDS + RUNNING_TIMEOUT))
|
||||
while read LOGLINE; do
|
||||
echo ${LOGLINE}
|
||||
if [[ ${LOGLINE} == *"${RUNNING_LOG_CHECK}"* ]]; then
|
||||
echo "Container up!"
|
||||
break
|
||||
fi
|
||||
if [[ $SECONDS -gt ${TIMEOUT} ]]; then
|
||||
>&2 echo "ERROR: Failed to run ${PROJECT} container"
|
||||
docker rm -f ${PROJECT} > /dev/null 2>&1 || true
|
||||
exit 1
|
||||
fi
|
||||
done < <(docker logs -f ${PROJECT} 2>&1)
|
||||
docker rm -f ${PROJECT} > /dev/null 2>&1 || true
|
||||
echo
|
||||
|
||||
if [ "${VERSION}" == "local" -o "${TRAVIS_PULL_REQUEST}" == "true" ]; then
|
||||
echo "INFO: This is a PR or a local build, skipping push..."
|
||||
exit 0
|
||||
fi
|
||||
if [[ ! -z ${DOCKER_PASSWORD} ]]; then
|
||||
echo "### Push to Docker Hub..."
|
||||
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_LOGIN" --password-stdin > /dev/null 2>&1
|
||||
if [ "${DOCKER_TAG}" == "latest" -a "${PUSH_LATEST}" == "true" ]; then
|
||||
docker tag ${BUILD_TAG} ${DOCKER_USERNAME}/${DOCKER_REPONAME}:${DOCKER_TAG}
|
||||
fi
|
||||
if [[ "${VERSION}" != "latest" ]]; then
|
||||
docker tag ${BUILD_TAG} ${DOCKER_USERNAME}/${DOCKER_REPONAME}:${VERSION}
|
||||
fi
|
||||
docker push ${DOCKER_USERNAME}/${DOCKER_REPONAME}
|
||||
if [[ ! -z ${MICROBADGER_HOOK} ]]; then
|
||||
echo "Call MicroBadger hook"
|
||||
curl -X POST ${MICROBADGER_HOOK}
|
||||
echo
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
if [[ ! -z ${QUAY_PASSWORD} ]]; then
|
||||
echo "### Push to Quay..."
|
||||
echo "$QUAY_PASSWORD" | docker login quay.io --username "$QUAY_LOGIN" --password-stdin > /dev/null 2>&1
|
||||
if [ "${DOCKER_TAG}" == "latest" -a "${PUSH_LATEST}" == "true" ]; then
|
||||
docker tag ${BUILD_TAG} quay.io/${QUAY_USERNAME}/${QUAY_REPONAME}:${DOCKER_TAG}
|
||||
fi
|
||||
if [[ "${VERSION}" != "latest" ]]; then
|
||||
docker tag ${BUILD_TAG} quay.io/${QUAY_USERNAME}/${QUAY_REPONAME}:${VERSION}
|
||||
fi
|
||||
docker push quay.io/${QUAY_USERNAME}/${QUAY_REPONAME}
|
||||
echo
|
||||
fi
|
Loading…
Reference in New Issue
Block a user