Skip to content

Conversation

dreis2211
Copy link
Contributor

Hi,

as discussed in #20420 this is an attempt to automate Docker upgrades for the CI environment. I say attempt, because I can't really test it in the real setup, so forgive me if things are not working. If they are, it should open a PR for version 19.03.8.

Let me know what you think.
Cheers,
Christoph

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 15, 2020
branch="ci-docker-$latest_version"
git config user.name "Spring Buildmaster" > /dev/null
git config user.email "buildmaster@springframework.org" > /dev/null
git checkout -b "$branch" origin/master > /dev/null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will work in the Concourse setup as I don't know if we have a real repository there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work. stage.sh does something similar.

sed -i "s/version=.*/version=\"$latest_version\"/" git-repo/ci/images/get-docker-url.sh
git add git-repo/ci/images/get-docker-url.sh > /dev/null
git commit -m "$issue_title" > /dev/null
git push origin "$branch" > /dev/null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we maybe need to switch to the master branch again afterwards?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can push from here as it will ask for credentials. We should probably commit inside the task and push using the git-resource in pipeline.yml. If there was no commit, it should be a no-op. Once the git-resource is used to push, we can trigger another task that creates the pull-request. This task config can then be shared between all the automatic detection jobs that we have (jdk, ubuntu and docker). It can take the branch name and issue title as params. What do you think @dreis2211?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure if I understand what you want to share exactly? Everything inside this if (so line 24-46) or just the curl command in line 36-43?
I must admit the Concourse setup you're asking for is not completely clear to me (although I generally understand the plan), but my Concourse experience is limited. I'd probably need a little bit of help with that, I guess.

@mbhave mbhave self-assigned this Mar 27, 2020
if [[ ${existing_upgrade_issues} = "" ]]; then
# Create changes in dedicated branch
branch="ci-docker-$latest_version"
git config user.name "Spring Buildmaster" > /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to cd into the git-repo before doing that.

@mbhave
Copy link
Contributor

mbhave commented Mar 27, 2020

Here's what I was thinking. detect-docker-updates.sh would look a lot like what you currently have except for line 33 (which tries to push to the git repo) and lines 36-43. For line 33, the push could be done in the pipeline.yml. We do something similar when staging a release. In this case, stage-git-repo is an output of the stage task which has the extra commit.

Following the put to the git repo in the pipeline.yml, we could have another task which creates the PR. This task would call a script that contains the curl command in lines 36-43. The creation of the PR would be conditional on the branch differing from master (or 2.2.x/2.1.x).

Here's what the pipeline.yml might look like:

    - task: detect-docker-updates
      file: git-repo/ci/tasks/detect-docker-updates.yml
      params:
        BRANCH: ((branch)) [1]
        GITHUB_REPO: spring-boot
        GITHUB_ORGANIZATION: spring-projects
        GITHUB_PASSWORD: ((github-password))
        GITHUB_USERNAME: ((github-username))
      image: spring-boot-ci-image
    - put: git-repo-ci-docker [2]
      params:
        repository: docker-updates-git-repo
        force: true
    - task: create-pull-request
      file: git-repo/ci/tasks/create-pull-request.yml
      params:
        BRANCH: ((branch))
        GITHUB_REPO: spring-boot
        GITHUB_ORGANIZATION: spring-projects
        GITHUB_PASSWORD: ((github-password))
        GITHUB_USERNAME: ((github-username))

[1] git-repo-ci-docker would be another resource in pipeline.yml which points to the branch we want to push to.

- name: git-repo-ci-docker
  type: git
  icon: github-circle
  source:
    uri: ((github-repo))
    username: ((github-username))
    password: ((github-password))
    branch: ci-docker-((branch))

[2] branch would be the branch configured in [1].

If this is still confusing and I can see how it can be because it is hard to test, I can prepare a branch with your PR and the changes I mentioned on top of that. Let me know what works best for you.

@dreis2211
Copy link
Contributor Author

Yeah, it's kind of hard if it can't be tested really. But I will give it a try - I have a way better idea now of what you were thinking. Will do so over the weekend, I guess. Thanks, @mbhave

- name: detect-docker-updates
plan:
- get: git-repo
resource: git-repo-ci-docker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if that should point to the new resource.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it should point to the new resource. We will only use the new resource to put to it since we want to put to that branch. Since the commit is based off master, we need to use the actual git-repo resource.

uri: ((github-repo))
username: ((github-username))
password: ((github-password))
branch: ci-docker-((branch))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this working if the branch doesn't exist?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need to create a long-running branch beforehand. I don't know if there's a way to create branches on the fly in concourse.

---
platform: linux
inputs:
- name: git-repo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this need to be a different input - e.g. the docker git resource in this case. Which makes it less generic somehow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this task, it only uses the git-repo to run the create-pull-request.sh. It's not actually used anywhere in the script itself so we can stick to using the regular git-repo and not the docker-specific one.

@dreis2211
Copy link
Contributor Author

dreis2211 commented Mar 29, 2020

I pushed an updated version, but the Concourse git-repo configs still confuse me. Their naming is simply not intuitive to me, sorry. I'm not happy with this PR - I can't really test the setup and it feels like doing open heart surgery with a blindfold on.
I need help, @mbhave

image: spring-boot-ci-image
- put: git-repo-ci-docker
params:
repository: docker-updates-git-repo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the docker-updates-git-repo coming from? I was assuming it needs to be an output in the detect-docker-updates.yml?

Copy link
Contributor

@mbhave mbhave Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. You do have it as an output in detect-docker-updates.yml if I'm not wrong. I renamed it to git-repo-updated for brevity in the branch I've linked to below.

@mbhave
Copy link
Contributor

mbhave commented Mar 30, 2020

@dreis2211 Thanks so much for updating this and sorry this is such a pain to test :( I will take a look at the updated PR today.

@dreis2211
Copy link
Contributor Author

No need to be sorry.

@mbhave
Copy link
Contributor

mbhave commented Mar 31, 2020

@dreis2211 I made a few minor changes to your PR here. I think this will work now. If you're okay with the changes, I can squash your commits, add mine on top and merge. We'll find out if it does work :)

@dreis2211
Copy link
Contributor Author

@mbhave I'm okay with whatever you suggest

@mbhave mbhave added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 31, 2020
@mbhave mbhave added this to the 2.1.x milestone Mar 31, 2020
mbhave pushed a commit that referenced this pull request Mar 31, 2020
mbhave added a commit that referenced this pull request Mar 31, 2020
@mbhave mbhave closed this in 8c8d7af Mar 31, 2020
@mbhave mbhave modified the milestones: 2.1.x, 2.1.14 Mar 31, 2020
@dreis2211
Copy link
Contributor Author

I guess it didn't work

mbhave added a commit that referenced this pull request Mar 31, 2020
mbhave added a commit that referenced this pull request Mar 31, 2020
@mbhave
Copy link
Contributor

mbhave commented Mar 31, 2020

It did with a few minor changes. The create pull request task was missing the image configuration and I had missed a cd when I added something in my polish commit.

@mbhave
Copy link
Contributor

mbhave commented Mar 31, 2020

Thanks for the PR @dreis2211!

@dreis2211
Copy link
Contributor Author

@mbhave The PR was created but it seems to be empty. Thoughts?

@mbhave
Copy link
Contributor

mbhave commented Mar 31, 2020

@dreis2211 I just realized that too. It had the right commit the first time I ran it. When I ran it again, it detected that a PR already exists and force pushed the existing master branch to the ci-docker-image branch. Effectively, the PR branch and master then became the same and GitHub thought the PR was merged.

I think if we remove this if condition and commit to ci-docker-image regardless of if a PR exists, it will keep the ci-docker-image branch up-to-date with master along with that additional commit on top.

We can then move that if condition to the create-pull-request.sh script.

@dreis2211
Copy link
Contributor Author

dreis2211 commented Mar 31, 2020

Seems like a plan. Sorry, that you have additional work with this PR. Let me know if I should open a PR for the suggested changes, but I think it's simpler if you do them directly

mbhave added a commit that referenced this pull request Mar 31, 2020
If a PR with the given title exists, we clone the existing PR branch so
that it doesn't get overridden by master.

See gh-20530
@mbhave
Copy link
Contributor

mbhave commented Mar 31, 2020

No problem! I hadn't anticipated this case. Anyway, I ran the pipeline twice and it seems to work now even when a PR exists. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants