Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from EOEPCA/develop
Browse files Browse the repository at this point in the history
Sync with develop
  • Loading branch information
rconway authored Jun 19, 2020
2 parents 2583764 + fdc7620 commit 6ab0657
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
if: branch = master AND NOT type IN (pull_request)
install: skip
script: travis/release.sh
post_script: travis/delete-dockerhub-images.sh

import:
- docs/.travis.yml
Expand Down
6 changes: 5 additions & 1 deletion travis/acceptanceTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# fail fast settings from https://dougrichardson.org/2018/08/03/fail-fast-bash-scripting.html
set -euov pipefail

# obtain current repository name
REPO_LOCAL_PATH=`git rev-parse --show-toplevel`
REPO_NAME=`basename $REPO_LOCAL_PATH`

# Check presence of environment variables
TRAVIS_BUILD_NUMBER="${TRAVIS_BUILD_NUMBER:-0}"

buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for tagging, since this is a transient artefact

docker run --rm -d -p 8080:7000 --name template-svc eoepca/template-service:${buildTag} # Runs container from EOEPCA repository
docker run --rm -d -p 8080:7000 --name ${REPO_NAME} eoepca/${REPO_NAME}:${buildTag} # Runs container from EOEPCA repository

sleep 15 # wait until the container is running

Expand Down
11 changes: 7 additions & 4 deletions travis/containerCreation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
# fail fast settings from https://dougrichardson.org/2018/08/03/fail-fast-bash-scripting.html
set -euov pipefail

# obtain current repository name
REPO_LOCAL_PATH=`git rev-parse --show-toplevel`
REPO_NAME=`basename $REPO_LOCAL_PATH`

./gradlew shadowJar

# Check presence of environment variables
TRAVIS_BUILD_NUMBER="${TRAVIS_BUILD_NUMBER:-0}"


# Create a Docker image and tag it as 'travis_<build number>'
buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for tagging, since this is a transient artefact

docker build -t eoepca/template-service .
docker tag eoepca/template-service eoepca/template-service:$buildTag # Tags container in EOEPCA repository with buildTag
docker build -t eoepca/${REPO_NAME} .
docker tag eoepca/${REPO_NAME} eoepca/${REPO_NAME}:$buildTag # Tags container in EOEPCA repository with buildTag

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

docker push eoepca/template-service:$buildTag # defaults to docker hub EOEPCA repository
docker push eoepca/${REPO_NAME}:$buildTag # defaults to docker hub EOEPCA repository
71 changes: 71 additions & 0 deletions travis/delete-dockerhub-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
# Based on kizbitz/dockerhub-v2-api-organization.sh at https://gist.github.com/kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721

# Example for the Docker Hub V2 API
# Returns all images and tags associated with a Docker Hub organization account.
# Requires 'jq': https://stedolan.github.io/jq/

# set username, password, and organization
ORG="eoepca"
if [ -z "$DOCKER_USERNAME" ]; then
echo "Please enter your Dockerhub account name for organization $ORG: "
read -r USERNAME
export DOCKER_USERNAME=${USERNAME}
fi
if [ -z "$DOCKER_PASSWORD" ]; then
echo "Please enter your Dockerhub password for accout $DOCKER_USERNAME, part of $ORG organization:"
read -r PASSWORD
export DOCKER_PASSWORD=${PASSWORD}
fi

ALL=false
while [ "$1" != "" ]; do
case $1 in
-a | --all ) ALL=true
;;
-h | --help ) #usage
exit
;;
* ) #usage
exit 1
esac
shift
done

# -------

set -e

# get token
echo "Retrieving token ..."
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${DOCKER_USERNAME}'", "password": "'${DOCKER_PASSWORD}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)

# get list of repositories
echo "Retrieving repository list ..."
REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/?page_size=200 | jq -r '.results|.[]|.name')

# obtain current repository name
REPO_LOCAL_PATH=`git rev-parse --show-toplevel`
REPO_NAME=`basename $REPO_LOCAL_PATH`

# delete images and/or tags
echo "Deleting images and tags for organization: ${ORG}"

echo $REPO_LIST
for i in ${REPO_LIST}
do
if [ "$i" = "$REPO_NAME" ] || [ "$ALL" = "true" ]; then
echo "\nEntering repository $i"

# Delete by tags starting with "travis_"
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${i}/tags/?page_size=300 | jq -r '.results|.[]| select (.name | startswith("travis_")) | .name')
for j in ${IMAGE_TAGS}
do
echo -n " - ${j} ... "
curl -X DELETE -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${i}/tags/${j}/
echo "DELETED"
done
fi
done

echo "\nFinished"
14 changes: 9 additions & 5 deletions travis/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ set -euov pipefail
# Check presence of environment variables
TRAVIS_BUILD_NUMBER="${TRAVIS_BUILD_NUMBER:-0}"

# obtain current repository name
REPO_LOCAL_PATH=`git rev-parse --show-toplevel`
REPO_NAME=`basename $REPO_LOCAL_PATH`

# Create a Docker image and tag it as 'travis_<build number>'
buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for tagging, since this is a transient artefact

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker pull eoepca/template-service:${buildTag} # have to pull locally in order to tag as a release
docker pull eoepca/${REPO_NAME}:${buildTag} # have to pull locally in order to tag as a release

# Tag and push as a Release following the SemVer approach, e.g. 0.1.1-Alpha
docker tag eoepca/template-service:${buildTag} eoepca/template-service:release_${TRAVIS_TAG} # This recovers the GitHub release/tag number
docker push eoepca/template-service:release_${TRAVIS_TAG}
docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:release_${TRAVIS_TAG} # This recovers the GitHub release/tag number
docker push eoepca/${REPO_NAME}:release_${TRAVIS_TAG}

# Tag and push as `latest`
docker tag eoepca/template-service:${buildTag} eoepca/template-service:latest
docker push eoepca/template-service:latest
docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:latest
docker push eoepca/${REPO_NAME}:latest

0 comments on commit 6ab0657

Please sign in to comment.