Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

fix: only deploy to DockerHub on tag-triggered builds #280

Merged
merged 3 commits into from
Sep 29, 2022

Conversation

dduportal
Copy link
Contributor

@dduportal dduportal commented Sep 23, 2022

Related to jenkinsci/docker-agent#605.

Closes jenkins-infra/helpdesk#2

This PR updates the Jenkinsfile (pipeline) and the docker-bake.hcl manifest with the following changes:

  • fix(Jenkinsfile): only deploy to DockerHub (--push argument for docker buildx bake command) when a tag triggered a build
  • fix(Jenkinsfile): stop polling for code change, to avoid triggering unexpected tag builds
  • chore(Jenkins): use declarative syntax as much as posible (simplification)
  • feat(docker-bake.hcl) automatic detection of the remoting version and build number from the tag

@dduportal
Copy link
Contributor Author

Ping @timja the windows build seems flacky. Do you mind merging or shall we fix it ?

@dduportal dduportal mentioned this pull request Sep 23, 2022
5 tasks
@slide
Copy link
Member

slide commented Sep 23, 2022

Yes, there is a commit that broke tests, if the build stage is passing for now it is probably ok. I am trying to address the issues in another PR.

@dduportal dduportal force-pushed the only-deploy-on-tags branch 2 times, most recently from 9805756 to 144112d Compare September 27, 2022 21:22
@dduportal
Copy link
Contributor Author

Yes, there is a commit that broke tests, if the build stage is passing for now it is probably ok. I am trying to address the issues in another PR.

Since I was slower to update, I rebased now that your PR is merged (THANKS).
I had to change the parallel thing, let me kno what you think: I've used scripted inside declarative, to keep the Linux / Windows parallel as well. Reason is that windows agent allocation takes a lot of time so better to start it as soon as posible in the pipeline.

This PR is required to ensure that jenkinsci/docker-agent#604 and jenkinsci/docker-agent#603 can be fixed without regression

@slide
Copy link
Member

slide commented Sep 27, 2022

The creation of the nmap container prior to the tests starting requires updating the tests as well. The nmap container is cleaned up in the tests, so that would need to be removed as well so it doesn't get cleaned up and then recreated anyway. Also, the builds may be on other nodes, so the nmap container needs to be part of the parallel part, or am I missing something?

@dduportal
Copy link
Contributor Author

The creation of the nmap container prior to the tests starting requires updating the tests as well. The nmap container is cleaned up in the tests, so that would need to be removed as well so it doesn't get cleaned up and then recreated anyway.

Thanks for this info. I initially thought that building it would, at least, keep the image layers into the Docker Engine cache, so the docker build in the pester tests would benefit the cache but would still be kept so contributoir could run it autonomously. I'll have a look then.

Also, the builds may be on other nodes, so the nmap container needs to be part of the parallel part, or am I missing something?

Not in the actual version of the pipeline: The agent directive which spawns a Windows VM agent is defined at the parent stage level.
But your message makes me wonder if we should not run each step of the "matrix" on a separate node: worth comparing the efficiency of both solutions:

  • On one side, these machines are huge, so building the images concurently might be efficient, and spawning them takes time and costs us money (billing per hour for Windows VM, instead of per-minute for Linux).

  • On the other side, the concurent tests that spawn a lot of containers could benefit a lot from NOT being run concurenctly on the same machines (docker build is optimized, docker run is not)

@timja
Copy link
Member

timja commented Sep 28, 2022

Not in the actual version of the pipeline: The agent directive which spawns a Windows VM agent is defined at the parent stage level.

but the previous version was doing that wasn't it? We changed to an agent per image because we kept getting disk full on the windows builds

@dduportal
Copy link
Contributor Author

Not in the actual version of the pipeline: The agent directive which spawns a Windows VM agent is defined at the parent stage level.

but the previous version was doing that wasn't it? We changed to an agent per image because we kept getting disk full on the windows builds

True: I misread the agent block location in the matrix (I should not have used the diff view :D).
Thanks folks, let me change this in the PR

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
@dduportal
Copy link
Contributor Author

Ready ro review folks:

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

This is not handling the case where we have to use a different docker-agent build number than in inbound-agent.

sometimes we have to use e.g. 4.13.5-6 due to release issues or whatever in the docker-agent repo but here it's the first release version.

We can't just always sync them as if we have changes in this repository e.g. to change the dockerfile here, we need to release a new build but that would require a new docker-agent release in a different repository which I don't think is right.

(if they were in the same repo then I guess we could release all at once always)

Jenkinsfile Outdated Show resolved Hide resolved
not { buildingTag() }
}
steps {
script {
Copy link
Member

Choose a reason for hiding this comment

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

visualisation is broken in blue ocean unfortunately as it can't handle this case 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I remember, it is the main reason why nesting matrix/parallel are not supported in declarative: to avoid breaking the UI.

But in fact, it looks better once the build is finished (wether it's successful, failing or aborted):

Capture d’écran 2022-09-29 à 06 38 41

  • Fixed graph once built:

Capture d’écran 2022-09-29 à 06 38 28

=> when using a clean agent (with no priori cache), the new build jumped from ~39min to ~32 min

Copy link
Member

Choose a reason for hiding this comment

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

interesting that it works after complete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interesting that it works after complete

Yep, I realized it while looking to this comment: I was sure it was working and just discovered that's it is broken "while" building.

@dduportal
Copy link
Contributor Author

dduportal commented Sep 29, 2022

This is not handling the case where we have to use a different docker-agent build number than in inbound-agent.

sometimes we have to use e.g. 4.13.5-6 due to release issues or whatever in the docker-agent repo but here it's the first release version.

We can't just always sync them as if we have changes in this repository e.g. to change the dockerfile here, we need to release a new build but that would require a new docker-agent release in a different repository which I don't think is right.

(if they were in the same repo then I guess we could release all at once always)

That is the goal of the variable AGENT_IMAGE_BUILD_NUMBER in the bake file (I've added a comment because it's confusing until we are able to merge on a single repository): https://github.com/jenkinsci/docker-inbound-agent/pull/280/files#diff-870f6fe23fc034f008f5203ee1e628d7bfa65a49095d5a4688db498328449ed2R37-R40

With your example, if you want to build the image jenkins/inbound-agent:4.13.5-1 inheriting from jenkins/agent:4.13.5-6 then you would do the same as usual: IMAGE_TAG=4.13.5-1 AGENT_IMAGE_BUILD_NUMBER=6 docker buildx bake <...>.

The change made in the bake file removes at least one case from the path (as it forces the remoting version to be the same for parent and agent image)

default = split("-", "${IMAGE_TAG}")[0]
}

variable "BUILD_NUMBER" {
Copy link
Member

Choose a reason for hiding this comment

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

there's already a build number variable in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this one is the inbound-agent build number (It took me 8hours in the plane to fully get it :D ).

Let me add a comment on this one.

Copy link
Member

Choose a reason for hiding this comment

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

you sure?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh good catch: this 2nd occurence is the result of me messing up the rebase.

Should be fixed now

@dduportal
Copy link
Contributor Author

@timja as soon as the JDK8/11 issues are fixed, I'm willing to open a PR to jenkinsci/agent repo to "merge" Dockerfiles, so any remoting updates would only be done once (and we could get rid of all this duplication).

Sounds good to you?

@timja
Copy link
Member

timja commented Sep 29, 2022

@timja as soon as the JDK8/11 issues are fixed, I'm willing to open a PR to jenkinsci/agent repo to "merge" Dockerfiles, so any remoting updates would only be done once (and we could get rid of all this duplication).

Sounds good to you?

would be great yeah

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
@dduportal dduportal merged commit 19fc4e3 into jenkinsci:master Sep 29, 2022
@dduportal dduportal added the bug label Sep 29, 2022
@dduportal dduportal deleted the only-deploy-on-tags branch September 29, 2022 13:41
lemeurherve pushed a commit to lemeurherve/jenkinsci-docker-inbound-agent that referenced this pull request Nov 19, 2023
lemeurherve pushed a commit to lemeurherve/docker-agent that referenced this pull request Nov 28, 2023
…uportal/only-deploy-on-tags

fix: only deploy to DockerHub on tag-triggered builds
lemeurherve pushed a commit to lemeurherve/docker-agent that referenced this pull request Nov 28, 2023
…uportal/only-deploy-on-tags

fix: only deploy to DockerHub on tag-triggered builds
lemeurherve pushed a commit to lemeurherve/docker-agent that referenced this pull request Nov 28, 2023
…uportal/only-deploy-on-tags

fix: only deploy to DockerHub on tag-triggered builds
lemeurherve pushed a commit to lemeurherve/docker-agent that referenced this pull request Nov 28, 2023
…uportal/only-deploy-on-tags

fix: only deploy to DockerHub on tag-triggered builds
lemeurherve pushed a commit to lemeurherve/docker-agent that referenced this pull request Nov 28, 2023
…uportal/only-deploy-on-tags

fix: only deploy to DockerHub on tag-triggered builds
lemeurherve pushed a commit to lemeurherve/docker-agent that referenced this pull request Jan 12, 2024
…only-deploy-on-tags

fix: only deploy to DockerHub on tag-triggered builds
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker images are building on tags
3 participants