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

Add ability to specify args that will be passed to docker during the build #232

Merged
merged 13 commits into from
Aug 9, 2023

Conversation

chrisneal
Copy link
Contributor

@chrisneal chrisneal commented Jul 14, 2023

This PR allows passing arguments to the docker build step.

We're using Buildx (that has been installed, which replaces docker build with docker buildx build). Buildx allows us to pass in additional parameters to the build command (for caching etc.).

This PR allows for docker args to be passed via the CLI:

--docker-arg="FOO=BAR" --docker-arg="FIZZ=BAR"

Or added to the manifest file:

docker-args:
    FOO: BAR
    FIZZ: BAR

@taylorotwell taylorotwell marked this pull request as draft July 24, 2023 21:55
@joedixon
Copy link
Contributor

Hey @chrisneal - would you be able to provide an example build command including the actual arguments you wish to use?

@chrisneal
Copy link
Contributor Author

@joedixon

docker build --pull --file=dockerfile.Production --tag=TAG --cache-from="type=local,src=/tmp/.buildx-cache" --cache-to="type=local,dest=/tmp/.buildx-cache" --provenance=false .

@joedixon
Copy link
Contributor

joedixon commented Jul 31, 2023

Thanks @chrisneal.

So to confirm, this PR is adding support for build and buildx options supported by the Docker CLI?

If so, options are supported by both docker build and docker buildx.

--build-arg is an option and is already handled separately by Vapor.

Assuming this is correct, do we need to provide support for options which don't require a value such as --pull (as per your example) which I don't think would be supported at present?

@chrisneal
Copy link
Contributor Author

@joedixon I have made that change.

The CLI will look like:

--docker-arg="FOO=BAR" --docker-arg="FIZZ=BAR" --docker-arg="FIZZLE"

The equivalent manifest file will now need to look like:

docker-args:
    - FOO: BAR
    - FIZZ: BAR
    - FIZZLE

@joedixon
Copy link
Contributor

joedixon commented Aug 3, 2023

Hey @chrisneal I made some tweaks to the PR:

  • Renamed dockerArgs to buildOptions to align more closely with the existing buildArgs
  • Options can be passed with --build-option in the CLI and docker-build-options in the manifest
  • Fixed the formatting of the generated commands to remove erroneous spaces
  • Added the option to the build command configuration
  • Pass build options through to the deploy command

Would you mind giving this a test and letting me know what you think?

@chrisneal
Copy link
Contributor Author

@joedixon This looks good, thank you for making those changes.

@chrisneal
Copy link
Contributor Author

@joedixon I've added a line to output the build command. I think this will be useful for people (aka. me) to see, if they're adding additional build options.

@chrisneal chrisneal marked this pull request as ready for review August 4, 2023 18:38
@taylorotwell taylorotwell marked this pull request as draft August 4, 2023 21:20
@chrisneal chrisneal marked this pull request as ready for review August 5, 2023 08:37
src/Docker.php Outdated Show resolved Hide resolved
@taylorotwell taylorotwell merged commit 84d0bb4 into laravel:master Aug 9, 2023
19 checks passed
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.

3 participants