Merge pull request #41 from ninech/build_and_tagging_improvements

Build and tagging improvements
This commit is contained in:
Christian Mäder 2018-01-30 12:47:42 +01:00 committed by GitHub
commit 71200070e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 6 deletions

View File

@ -20,9 +20,7 @@ after_script:
after_success: after_success:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then
./build.sh master --push; ./build-branches.sh --push;
./build.sh develop --push;
./build.sh develop-2.3 --push;
./build-latest.sh --push; ./build-latest.sh --push;
PRERELEASE=true ./build-latest.sh --push; PRERELEASE=true ./build-latest.sh --push;
fi fi

14
build-branches.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/branches"
CURL_OPTS="-s"
CURL="curl ${CURL_OPTS}"
BRANCHES=$($CURL "${URL_RELEASES}" | jq -r 'map(.name) | .[] | scan("^[^v].+")')
for BRANCH in $BRANCHES; do
./build.sh "${BRANCH}" $@
done

View File

@ -1,12 +1,15 @@
#!/bin/bash #!/bin/bash
URL_RELEASES=https://api.github.com/repos/digitalocean/netbox/releases ORIGINAL_GITHUB_REPO="digitalocean/netbox"
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases"
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name" JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"
CURL_OPTS="-s" CURL_OPTS="-s"
CURL="curl ${CURL_OPTS}"
VERSION=$(curl $CURL_OPTS "${URL_RELEASES}" | jq -r "${JQ_LATEST}") VERSION=$($CURL "${URL_RELEASES}" | jq -r "${JQ_LATEST}")
# Check if the prerelease version is actually higher than stable version # Check if the prerelease version is actually higher than stable version
if [ "${PRERELEASE}" == "true" ]; then if [ "${PRERELEASE}" == "true" ]; then
@ -25,4 +28,18 @@ if [ "${PRERELEASE}" == "true" ]; then
fi fi
fi fi
./build.sh "${VERSION}" $@ # Check if that version is not already available on docker hub:
ORIGINAL_DOCKERHUB_REPO="ninech/netbox"
DOCKERHUB_REPO="${DOCKERHUB_REPO-$ORIGINAL_DOCKERHUB_REPO}"
URL_DOCKERHUB_TOKEN="https://auth.docker.io/token?service=registry.docker.io&scope=repository:${DOCKERHUB_REPO}:pull"
BEARER_TOKEN="$($CURL "${URL_DOCKERHUB_TOKEN}" | jq -r .token)"
URL_DOCKERHUB_TAG="https://registry.hub.docker.com/v2/${DOCKERHUB_REPO}/tags/list"
AUTHORIZATION_HEADER="Authorization: Bearer ${BEARER_TOKEN}"
ALREADY_BUILT="$($CURL -H "${AUTHORIZATION_HEADER}" "${URL_DOCKERHUB_TAG}" | jq -e ".tags | any(.==\"${VERSION}\")")"
if [ "$ALREADY_BUILT" == "false" ]; then
./build.sh "${VERSION}" $@
else
echo "${VERSION} already exists on https://hub.docker.com/r/${DOCKERHUB_REPO}"
fi