blob: 7ca49d3d1522cdd93493284f83dde69e2514ed91 [file] [log] [blame]
Carlos Sanchez0f763d42017-02-06 10:55:11 +01001#!/bin/bash -eu
2
3# Publish any versions of the docker image not yet pushed to jenkinsci/jenkins
4
5set -o pipefail
6
7sort-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
16docker-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 Sanchez3ffc4e42017-02-06 13:20:44 +010027get-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 Sanchez0f763d42017-02-06 10:55:11 +010035get-published-versions() {
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010036 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 Sanchez0f763d42017-02-06 10:55:11 +010038}
39
40get-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
44publish() {
45 local version=$1
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010046 local variant=$2
47 local tag="${version}${variant}"
Carlos Sanchez0f763d42017-02-06 10:55:11 +010048 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 Sanchez7b8382f2017-02-06 12:00:52 +010053 docker build --build-arg "JENKINS_VERSION=$version" \
54 --build-arg "JENKINS_SHA=$sha" \
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010055 --tag "jenkinsci/jenkins:${tag}" ${build_opts} .
Carlos Sanchez0f763d42017-02-06 10:55:11 +010056
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010057 docker-tag "${tag}" "latest${variant}"
Carlos Sanchez0f763d42017-02-06 10:55:11 +010058
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010059 docker push "jenkinsci/jenkins:${tag}"
60 docker push "jenkinsci/jenkins:latest${variant}"
Carlos Sanchez0f763d42017-02-06 10:55:11 +010061
62 # Update lts tag
Carlos Sanchez7b8382f2017-02-06 12:00:52 +010063 if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010064 echo "Updating lts${variant} tag to ${tag}"
65 docker-tag "$version" "lts${variant}"
66 docker push "jenkinsci/jenkins:lts${variant}"
Carlos Sanchez0f763d42017-02-06 10:55:11 +010067 fi
68}
69
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010070variant=$(get-variant)
71
Carlos Sanchez0f763d42017-02-06 10:55:11 +010072published_versions="$(get-published-versions)"
73
74for version in $(get-latest-versions); do
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010075 tag="${version}${variant}"
76 if echo "${published_versions}" | grep -q "^${tag}$"; then
77 echo "Tag is already published: $tag"
Carlos Sanchez0f763d42017-02-06 10:55:11 +010078 else
Carlos Sanchez3ffc4e42017-02-06 13:20:44 +010079 echo "Publishing tag: $tag"
80 publish "$version" "$variant"
Carlos Sanchez0f763d42017-02-06 10:55:11 +010081 fi
82done
83
84