Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
| 3 | # Publish any versions of the docker image not yet pushed to jenkinsci/jenkins |
| 4 | |
| 5 | set -o pipefail |
| 6 | |
| 7 | sort-versions() { |
| 8 | if [ "$(uname)" == 'Darwin' ]; then |
| 9 | gsort --version-sort |
| 10 | else |
| 11 | sort --version-sort |
| 12 | fi |
| 13 | } |
| 14 | |
| 15 | # Try tagging with and without -f to support all versions of docker |
| 16 | docker-tag() { |
| 17 | local from="jenkinsci/jenkins:$1" |
| 18 | local to="jenkinsci/jenkins:$2" |
| 19 | local out |
| 20 | if out=$(docker tag -f "$from" "$to" 2>&1); then |
| 21 | echo "$out" |
| 22 | else |
| 23 | docker tag "$from" "$to" |
| 24 | fi |
| 25 | } |
| 26 | |
| 27 | get-published-versions() { |
| 28 | curl -q -fsSL https://registry.hub.docker.com/v1/repositories/jenkinsci/jenkins/tags | egrep -o '"name": "[0-9\.]+"' | egrep -o '[0-9\.]+' |
| 29 | } |
| 30 | |
| 31 | get-latest-versions() { |
| 32 | curl -q -fsSL https://api.github.com/repos/jenkinsci/jenkins/tags?per_page=20 | grep '"name": "jenkins-' | egrep -o '[0-9]+(\.[0-9]+)+' | sort-versions | uniq |
| 33 | } |
| 34 | |
| 35 | publish() { |
| 36 | local version=$1 |
| 37 | local sha |
| 38 | local build_opts="--no-cache --pull" |
| 39 | |
| 40 | sha=$(curl -q -fsSL "http://repo.jenkins-ci.org/simple/releases/org/jenkins-ci/main/jenkins-war/${version}/jenkins-war-${version}.war.sha1") |
| 41 | |
Carlos Sanchez | 7b8382f | 2017-02-06 12:00:52 +0100 | [diff] [blame^] | 42 | docker build --build-arg "JENKINS_VERSION=$version" \ |
| 43 | --build-arg "JENKINS_SHA=$sha" \ |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 44 | --tag "jenkinsci/jenkins:$version" ${build_opts} . |
| 45 | |
| 46 | docker-tag $version latest |
| 47 | |
| 48 | docker push "jenkinsci/jenkins:$version" |
| 49 | docker push "jenkinsci/jenkins:latest" |
| 50 | |
| 51 | # Update lts tag |
Carlos Sanchez | 7b8382f | 2017-02-06 12:00:52 +0100 | [diff] [blame^] | 52 | if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 53 | echo "Updating lts tag to $version" |
| 54 | docker-tag $version lts |
| 55 | docker push "jenkinsci/jenkins:lts" |
| 56 | fi |
| 57 | } |
| 58 | |
| 59 | published_versions="$(get-published-versions)" |
| 60 | |
| 61 | for version in $(get-latest-versions); do |
| 62 | if echo "${published_versions}" | grep -q "^${version}$"; then |
| 63 | echo "Version is already published: $version" |
| 64 | else |
| 65 | echo "Publishing version: $version" |
| 66 | publish $version |
| 67 | fi |
| 68 | done |
| 69 | |
| 70 | |