blob: 40c68576361d5447748dce4943bb317553657e11 [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
27get-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
31get-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
35publish() {
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 Sanchez7b8382f2017-02-06 12:00:52 +010042 docker build --build-arg "JENKINS_VERSION=$version" \
43 --build-arg "JENKINS_SHA=$sha" \
Carlos Sanchez0f763d42017-02-06 10:55:11 +010044 --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 Sanchez7b8382f2017-02-06 12:00:52 +010052 if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
Carlos Sanchez0f763d42017-02-06 10:55:11 +010053 echo "Updating lts tag to $version"
54 docker-tag $version lts
55 docker push "jenkinsci/jenkins:lts"
56 fi
57}
58
59published_versions="$(get-published-versions)"
60
61for 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
68done
69
70