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 | |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 27 | get-variant() { |
| 28 | local branch; branch=$(git rev-parse --abbrev-ref HEAD) |
| 29 | case "$branch" in |
| 30 | master) echo "" ;; |
| 31 | *) echo "-${branch}" ;; |
| 32 | esac |
| 33 | } |
| 34 | |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 35 | get-published-versions() { |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 36 | local regex="[0-9\.]+[a-z\-]*" |
| 37 | curl -q -fsSL https://registry.hub.docker.com/v1/repositories/jenkinsci/jenkins/tags | egrep -o "\"name\": \"${regex}\"" | egrep -o "${regex}" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | get-latest-versions() { |
| 41 | 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 |
| 42 | } |
| 43 | |
| 44 | publish() { |
| 45 | local version=$1 |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 46 | local variant=$2 |
| 47 | local tag="${version}${variant}" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 48 | local sha |
| 49 | local build_opts="--no-cache --pull" |
| 50 | |
| 51 | sha=$(curl -q -fsSL "http://repo.jenkins-ci.org/simple/releases/org/jenkins-ci/main/jenkins-war/${version}/jenkins-war-${version}.war.sha1") |
| 52 | |
Carlos Sanchez | 7b8382f | 2017-02-06 12:00:52 +0100 | [diff] [blame] | 53 | docker build --build-arg "JENKINS_VERSION=$version" \ |
| 54 | --build-arg "JENKINS_SHA=$sha" \ |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 55 | --tag "jenkinsci/jenkins:${tag}" ${build_opts} . |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 56 | |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 57 | docker-tag "${tag}" "latest${variant}" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 58 | |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 59 | docker push "jenkinsci/jenkins:${tag}" |
| 60 | docker push "jenkinsci/jenkins:latest${variant}" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 61 | |
| 62 | # Update lts tag |
Carlos Sanchez | 7b8382f | 2017-02-06 12:00:52 +0100 | [diff] [blame] | 63 | if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 64 | echo "Updating lts${variant} tag to ${tag}" |
| 65 | docker-tag "$version" "lts${variant}" |
| 66 | docker push "jenkinsci/jenkins:lts${variant}" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 67 | fi |
| 68 | } |
| 69 | |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 70 | variant=$(get-variant) |
| 71 | |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 72 | published_versions="$(get-published-versions)" |
| 73 | |
| 74 | for version in $(get-latest-versions); do |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 75 | tag="${version}${variant}" |
| 76 | if echo "${published_versions}" | grep -q "^${tag}$"; then |
| 77 | echo "Tag is already published: $tag" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 78 | else |
Carlos Sanchez | 3ffc4e4 | 2017-02-06 13:20:44 +0100 | [diff] [blame^] | 79 | echo "Publishing tag: $tag" |
| 80 | publish "$version" "$variant" |
Carlos Sanchez | 0f763d4 | 2017-02-06 10:55:11 +0100 | [diff] [blame] | 81 | fi |
| 82 | done |
| 83 | |
| 84 | |