Skip to content

Commit 4752d7e

Browse files
dreis2211mbhave
authored andcommitted
Automate Docker updates in CI
See gh-20530
1 parent 88b7b78 commit 4752d7e

File tree

8 files changed

+124
-2
lines changed

8 files changed

+124
-2
lines changed

ci/images/get-docker-url.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e
3+
4+
version="19.03.7"
5+
echo "https://download.docker.com/linux/static/stable/x86_64/docker-$version.tgz";

ci/images/setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ test -f /opt/openjdk/bin/javac
2727
###########################################################
2828
# DOCKER
2929
###########################################################
30+
DOCKER_URL=$( ./get-docker-url.sh )
3031

3132
cd /
32-
curl -L https://download.docker.com/linux/static/stable/x86_64/docker-19.03.7.tgz | tar zx
33+
curl -L ${DOCKER_URL} | tar zx
3334
mv /docker/* /bin/
3435
chmod +x /bin/docker*
3536

ci/parameters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
docker-upgrade-issue-title: "Upgrade Docker version in CI"
12
email-server: "smtp.svc.pivotal.io"
23
email-from: "[email protected]"
34
email-to: ["[email protected]"]

ci/pipeline.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ resources:
2727
username: ((github-username))
2828
password: ((github-password))
2929
branch: ((branch))
30+
- name: git-repo-ci-docker
31+
type: git
32+
icon: github-circle
33+
source:
34+
uri: ((github-repo))
35+
username: ((github-username))
36+
password: ((github-password))
37+
branch: ci-docker-((branch))
3038
- name: git-repo-windows
3139
type: git
3240
source:
@@ -178,6 +186,37 @@ jobs:
178186
GITHUB_PASSWORD: ((github-password))
179187
GITHUB_USERNAME: ((github-username))
180188
image: spring-boot-ci-image
189+
- name: detect-docker-updates
190+
plan:
191+
- get: git-repo
192+
resource: git-repo-ci-docker
193+
- get: every-wednesday
194+
trigger: true
195+
- get: spring-boot-ci-image
196+
- do:
197+
- task: detect-docker-updates
198+
file: git-repo/ci/tasks/detect-docker-updates.yml
199+
params:
200+
GITHUB_REPO: spring-boot
201+
GITHUB_ORGANIZATION: spring-projects
202+
GITHUB_PASSWORD: ((github-password))
203+
GITHUB_USERNAME: ((github-username))
204+
ISSUE_TITLE: ((docker-upgrade-issue-title))
205+
image: spring-boot-ci-image
206+
- put: git-repo-ci-docker
207+
params:
208+
repository: docker-updates-git-repo
209+
force: true
210+
- task: create-pull-request
211+
file: git-repo/ci/tasks/create-pull-request.yml
212+
params:
213+
BASE_BRANCH: ((branch))
214+
BRANCH: ci-docker-((branch))
215+
GITHUB_REPO: spring-boot
216+
GITHUB_ORGANIZATION: spring-projects
217+
GITHUB_PASSWORD: ((github-password))
218+
GITHUB_USERNAME: ((github-username))
219+
ISSUE_TITLE: ((docker-upgrade-issue-title))
181220
- name: build
182221
serial: true
183222
public: true
@@ -540,6 +579,6 @@ groups:
540579
- name: "Release"
541580
jobs: ["stage-milestone", "stage-rc", "stage-release", "promote-milestone", "promote-rc", "promote-release", "sync-to-maven-central"]
542581
- name: "CI Images"
543-
jobs: ["build-spring-boot-ci-images", "detect-jdk-updates", "detect-ubuntu-image-updates"]
582+
jobs: ["build-spring-boot-ci-images", "detect-docker-updates", "detect-jdk-updates", "detect-ubuntu-image-updates"]
544583
- name: "Build Pull Requests"
545584
jobs: ["build-pull-requests"]

ci/scripts/create-pull-request.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
curl \
5+
-s \
6+
-u ${GITHUB_USERNAME}:${GITHUB_PASSWORD} \
7+
-H "Content-type:application/json" \
8+
-d "{\"head\":\"${BRANCH}\",\"base\":\"${BASE_BRANCH}\",\"title\":\"${ISSUE_TITLE}\",\"body\":\"\",\"labels\":[\"status: waiting-for-triage\",\"type: task\"]}" \
9+
-f \
10+
-X \
11+
POST "https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/pulls" > /dev/null || { echo "Failed to create pull request" >&2; exit 1; }

ci/scripts/detect-docker-updates.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
latest_version=$(curl -I -s https://github.com/docker/docker-ce/releases/latest | grep "location:" | awk '{n=split($0, parts, "/"); print substr(parts[n],2);}' | awk '{$1=$1;print}' | tr -d '\r' | tr -d '\n' )
4+
5+
if [[ $latest_version =~ (beta|rc) ]]; then
6+
echo "Skip pre-release versions"
7+
exit 0;
8+
fi
9+
10+
latest="https://download.docker.com/linux/static/stable/x86_64/docker-$latest_version.tgz"
11+
current=$( git-repo/ci/images/get-docker-url.sh )
12+
13+
if [[ $current = $latest ]]; then
14+
echo "Already up-to-date"
15+
exit 0;
16+
fi
17+
18+
existing_tasks=$( curl -s https://api.github.com/repos/${GITHUB_ORGANIZATION}/${GITHUB_REPO}/pulls\?labels\=type:%20task\&state\=open\&creator\=spring-buildmaster )
19+
existing_upgrade_issues=$( echo "$existing_tasks" | jq -c --arg TITLE "$ISSUE_TITLE" '.[] | select(.title==$TITLE)' )
20+
21+
if [[ ${existing_upgrade_issues} = "" ]]; then
22+
pushd git-repo > /dev/null
23+
popd > /dev/null
24+
git clone git-repo docker-updates-git-repo > /dev/null
25+
pushd docker-updates-git-repo > /dev/null
26+
# Create changes in dedicated branch
27+
branch="ci-docker-$latest_version"
28+
git config user.name "Spring Buildmaster" > /dev/null
29+
git config user.email "[email protected]" > /dev/null
30+
git checkout -b "$branch" origin/master > /dev/null
31+
sed -i "s/version=.*/version=\"$latest_version\"/" ci/images/get-docker-url.sh
32+
git add ci/images/get-docker-url.sh > /dev/null
33+
commit_message="Upgrade to Docker $latest_version in CI"
34+
git commit -m "$commit_message" > /dev/null
35+
else
36+
echo "Pull request already exists."
37+
fi

ci/tasks/create-pull-request.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
platform: linux
3+
inputs:
4+
- name: git-repo
5+
params:
6+
BASE_BRANCH:
7+
BRANCH:
8+
GITHUB_REPO:
9+
GITHUB_ORGANIZATION:
10+
GITHUB_PASSWORD:
11+
GITHUB_USERNAME:
12+
ISSUE_TITLE:
13+
run:
14+
path: git-repo/ci/scripts/create-pull-request.sh

ci/tasks/detect-docker-updates.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
platform: linux
3+
inputs:
4+
- name: git-repo
5+
outputs:
6+
- name: docker-updates-git-repo
7+
params:
8+
GITHUB_REPO:
9+
GITHUB_ORGANIZATION:
10+
GITHUB_PASSWORD:
11+
GITHUB_USERNAME:
12+
ISSUE_TITLE:
13+
run:
14+
path: git-repo/ci/scripts/detect-docker-updates.sh

0 commit comments

Comments
 (0)