Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker bootstrap script #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

literalplus
Copy link
Contributor

Ellipsis

This MR adds a bootstrap script for Docker, which allows us to switch between Jenkinsfile and CLI mode seamlessly without having to mess with environment variables. It also streamlines a few operations in the Dockerfiles to use environment variables.

This is as suggested by @oleg-nenashev in #207 (comment), and inherently requires that #207 (CLI mode) be merged first.

Clean diff without the #207 changes here: https://github.com/xxyy/jenkinsfile-runner/compare/178/cli-mode...xxyy:docker-bootstrap-script?expand=1

@oleg-nenashev
Copy link
Member

I need to review it carefully. I just expected few params in /app/bin/jenkinsfile-runner TBH (missed that this script already exists)

@oleg-nenashev oleg-nenashev self-requested a review October 28, 2019 14:11
@literalplus
Copy link
Contributor Author

literalplus commented Oct 29, 2019

The /app/bin/jenkinsfile-runner script is auto-generated by appassembler-maven-plugin and mostly just wraps the Java call. I also noticed a jenkinsfile-runner-launcher script in the root dir, but I'm not sure if it's also used for something else, so I left it there. That one just handles the $DEBUG environment variable.

Although the new script doesn't do much more than that, just moves a few repeated paths into environment variables so we don't have to duplicate the final values in both the Dockerfile and the script.

I'll resolve the new merge conflicts after the review is in to avoid extra traffic on this PR – the affected files seem to change frequently.

@oleg-nenashev
Copy link
Member

also noticed a jenkinsfile-runner-launcher script in the root dir, but I'm not sure if it's also used for something else, so I left it there. That one just handles the $DEBUG environment variable.

Yes, I forgot it exists. It would be the best place for the new CLI argument so that we do not create more small scripts.

@literalplus
Copy link
Contributor Author

I can move the logic into that script. Do you know if it is used anywhere else that we would need to stay compatible with?

What should it do if the required environment variables (jenkins home, jenkins ref dir) are not defined? Error out like now (breaks existing usages of the script, if any) or only pass the --runWorkspace, --file, --jenkins-war and --plugins arguments if the variables are set?

We might be able to save this for --jenkins-war and --plugins by adding them to ENTRYPOINT, but still need special handling for --file and --runWorkspace because those aren't compatible/useful with --cli. (That's also the reason for the special handling there)

I'll probably only get around to doing that end of November

@oleg-nenashev
Copy link
Member

I can move the logic into that script. Do you know if it is used anywhere else that we would need to stay compatible with?

The script is used only for Docker images. Jenkinsfile Runner is in Beta, hence there is no strict compatibility requirements ATM

What should it do if the required environment variables (jenkins home, jenkins ref dir) are not defined?

Not sure I get it. AFAICT there is no serious changes needed being compared with the current behavior

@literalplus
Copy link
Contributor Author

literalplus commented Nov 10, 2019

Not sure I get it.

not an issue if it's only used for Docker :) I thought it might be used for launching in standalone as well, in that case people with existing setups might call that script without the environment variables set

This allows users to pass "cli" or "run" as Docker CMD to easily
switch modes without having to set environment variables. Also provides
the DEBUG environment variable to the non-dev Dockerfile.

Removes the FORCE_JENKINS_CLI environment variables as it's no
longer necessary.

as per jenkinsci#207 (comment)
@literalplus
Copy link
Contributor Author

Updated to expand the existing script

@oleg-nenashev
Copy link
Member

retriggering CI

@oleg-nenashev
Copy link
Member

Sorry for nt acting on this PR. The Dockerfile patch is still relevant, but I have a slightly different patch in mind: let's modify how CLI works by adding a top-level command. E.g. it would be:

  • jenkinsfile-runner [run] [args...] for common mode
  • jenkinsfile-runner cli [args...] for CLI
  • jenkinsfile-runner manage-plugins [args...] for the plugin manager
  • jenkinsfile-runner help for the top-level help
  • jenkinsfile-runner version for the version info

It would make the CLI more extensible in the future, and it will help to simplify the Dockerfile as well

@literalplus
Copy link
Contributor Author

literalplus commented Jul 31, 2020

That sounds like a good idea! I assume we'd want these commands handled in the app itself instead of the wrapper script then. Thus I'd remove the top-level command handling from the launcher (lines 28-42). However this doesn't make the Dockerfile any simpler than it already is in this PR, so am I understanding this correctly?

I think it makes sense to do refactoring the CLI as a separate task/PR, since it is technically independent from these changes here, which we could then merge for now (minus lines 28-42). I could move the CLI logic into the app for this year's Hacktoberfest if that works for you.

Having top-level commands, we might also be able to split their logic into separate classes, making Bootstrap.java a little slimmer. (I haven't looked at args4j in detail yet, I hope it supports that.)

@literalplus
Copy link
Contributor Author

Sorry for the ping @oleg-nenashev, do you have feedback on what I suggested in my previous comment? Would be great to have this cleared up before Hacktoberfest starts if we want to do it with that :) BTW I'm available to do other stuff as well so if you already have anything specific in mind that needs to be done besides the issues that are already tagged, I'd be happy to help!

re: making it simpler - you're right, we could save the case statement etc. and just always pass -f and --runWorkspace with your suggestion. (= lines 28-42 from above). If the above is fine, I'll rebase this PR (otherwise we could also drop this one and do these changes together with a new top-level command PR)

@oleg-nenashev
Copy link
Member

Hi @literalplus . My apologies, I missed the notification.

I assume we'd want these commands handled in the app itself instead of the wrapper script then. Thus I'd remove the top-level command handling from the launcher (lines 28-42). However this doesn't make the Dockerfile any simpler than it already is in this PR, so am I understanding this correctly?

Yes. It is rather a longer-term change when more commands are introduced

Having top-level commands, we might also be able to split their logic into separate classes, making Bootstrap.java a little slimmer. (I haven't looked at args4j in detail yet, I hope it supports that.)

args4j supports only one-level CLI, so it will require manual implementation. Anyway, it is quite easy to implement multiple option classes with inheritance where needed

BTW I'm available to do other stuff as well so if you already have anything specific in mind that needs to be done besides the issues that are already tagged, I'd be happy to help!

Any contributions are welcome! Right now I am mostly focused on getting the new packaging flow in place + on performance/size optimizations. But there is a lot of opportunities in the code. https://github.com/jenkinsci/jenkinsfile-runner-image-packs is also an area where many contributions could be made (see CONTRIBUTING)

@literalplus
Copy link
Contributor Author

Since this just popped up in my notifications, a short heads-up: I was unable to participate in this year's Hacktoberfest due to private issues, sorry for not reporting back. I can't yet say when I'll be able to reallocate time for this yet, but will ✨ eventually ✨ be able to take a look (but it's totally fine if it's done by then, there will be other things to do in the future)

@oleg-nenashev
Copy link
Member

Sure @literalplus . Any contributions are always appreciated and welcome, regardless of Hacktoberfest. I have started implementing #429 , it should be done this week. But there is a lot of other stuff that could be done

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

Successfully merging this pull request may close these issues.

None yet

2 participants