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 support for arbitrary writable volume mounts during pack build #778

Merged
merged 12 commits into from
Aug 7, 2020

Conversation

jromero
Copy link
Member

@jromero jromero commented Aug 5, 2020

Summary

This PR adds support to volume mount at any location during pack build. It additionally adds support for writable mounts (rw).

Output

After

pack build --help
$ ./out/pack build --help
Generate app image from source code

Usage:
  pack build <image-name> [flags]

Flags:
  -B, --builder string              Builder image (default "gcr.io/paketo-buildpacks/builder:base")
  -b, --buildpack strings           Buildpack reference in the form of '<buildpack>@<version>',
                                      path to a buildpack directory (not supported on Windows),
                                      path/URL to a buildpack .tar or .tgz file, or
                                      the name of a packaged buildpack image
                                    Repeat for each buildpack in order,
                                      or supply once by comma-separated list
  -R, --buildpack-registry string   Buildpack Registry URL
      --clear-cache                 Clear image's associated cache before building
  -D, --default-process string      Set the default process type
  -d, --descriptor string           Path to the project descriptor file
  -e, --env stringArray             Build-time environment variable, in the form 'VAR=VALUE' or 'VAR'.
                                    When using latter value-less form, value will be taken from current
                                      environment at the time this command is executed.
                                    This flag may be specified multiple times and will override
                                      individual values defined by --env-file.
      --env-file stringArray        Build-time environment variables file
                                    One variable per line, of the form 'VAR=VALUE' or 'VAR'
                                    When using latter value-less form, value will be taken from current
                                      environment at the time this command is executed
  -h, --help                        Help for 'build'
      --network string              Connect detect and build containers to network
      --no-pull                     Skip pulling builder and run images before use
  -p, --path string                 Path to app dir or zip-formatted file (defaults to current working directory)
      --publish                     Publish to registry
      --run-image string            Run image (defaults to default stack's run image)
      --trust-builder               Trust the provided builder
                                    All lifecycle phases will be run in a single container (if supported by the lifecycle).
      --volume stringArray          Mount host volume into the build container, in the form '<host path>:<target path>[:<mode>]'.
                                    Repeat for each volume in order,
                                      or supply once by comma-separated list

Global Flags:
      --no-color     Disable color output
  -q, --quiet        Show less output
      --timestamps   Enable timestamps in output
  -v, --verbose      Show more output
mounting a custom lifecycle
$ pack build my-bash-app -B cnbs/sample-builder:bionic --volume=/Users/javier.romero/dev/buildpacks/lifecycle/out/linux/lifecycle/:/cnb/lifecycle/ -p ~/dev/buildpacks/samples/apps/bash-script/
Warning: Using untrusted builder with volume mounts. If there is sensitive data in the volumes, this may present a security vulnerability.
bionic: Pulling from cnbs/sample-builder
Digest: sha256:3665853288be6c7df936f53dd8fccea10d22785c3015aec4dd49ab44f9c3a7bb
Status: Image is up to date for cnbs/sample-builder:bionic
bionic: Pulling from cnbs/sample-stack-run
Digest: sha256:4c51a26b0546508ccd6f2d14753d041b595b3f9bceef77f4bb969e06c66474a4
Status: Image is up to date for cnbs/sample-stack-run:bionic
Warning: Mounting to a sensitive directory /cnb/lifecycle/
0.8.0: Pulling from buildpacksio/lifecycle
Digest: sha256:48dfb79e342fdeb68a1bf310b33b349269b2919cb5029e0b7184b84e82fc0bb3
Status: Image is up to date for buildpacksio/lifecycle:0.8.0
===> DETECTING
[detector] samples/bash-script 0.0.1
===> ANALYZING
[analyzer] Previous image with name "index.docker.io/library/my-bash-app:latest" not found
===> RESTORING
===> BUILDING
[builder] ---> Hello World buildpack
[builder] ---> Hello Bash Script buildpack
[builder] 
[builder] Here are the contents of the current working directory:
[builder] .:
[builder] total 16
[builder] drwxr-xr-x 2 cnb  cnb  4096 Aug  5 18:50 .
[builder] drwxr-xr-x 1 root root 4096 Aug  5 18:50 ..
[builder] -rwxr-xr-x 1 cnb  cnb   738 Apr  6 23:13 app.sh
[builder] -rw-r--r-- 1 cnb  cnb   202 Apr  6 23:13 project.toml
===> EXPORTING
[exporter] Adding layer 'launcher'
[exporter] Adding 1/1 app layer(s)
[exporter] Adding layer 'config'
[exporter] *** Images (d1b9f852dd37):
[exporter]       index.docker.io/library/my-bash-app:latest
Successfully built image my-bash-app

Documentation

Related

Resolves #764

Signed-off-by: Javier Romero <rjavier@vmware.com>
Signed-off-by: Javier Romero <rjavier@vmware.com>
Signed-off-by: Javier Romero <rjavier@vmware.com>
Signed-off-by: Javier Romero <rjavier@vmware.com>
Signed-off-by: Javier Romero <rjavier@vmware.com>
Signed-off-by: Javier Romero <rjavier@vmware.com>
Signed-off-by: Javier Romero <rjavier@vmware.com>
@codecov
Copy link

codecov bot commented Aug 6, 2020

Codecov Report

Merging #778 into main will decrease coverage by 0.01%.
The diff coverage is 85.72%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #778      +/-   ##
==========================================
- Coverage   74.75%   74.74%   -0.00%     
==========================================
  Files          77       77              
  Lines        5164     5174      +10     
==========================================
+ Hits         3860     3867       +7     
- Misses        999     1002       +3     
  Partials      305      305              
Flag Coverage Δ
#os_linux 77.25% <100.00%> (+0.04%) ⬆️
#os_macos 73.17% <100.00%> (+0.05%) ⬆️
#os_windows 72.99% <57.15%> (-0.14%) ⬇️
#unit 74.74% <85.72%> (-<0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Signed-off-by: Javier Romero <rjavier@vmware.com>
@jromero jromero added the breaking-change Known to be non-backwards compatible label Aug 6, 2020
@jromero jromero added this to the 0.13.0 milestone Aug 6, 2020
acceptance/acceptance_test.go Outdated Show resolved Hide resolved
Signed-off-by: Javier Romero <rjavier@vmware.com>
@jromero jromero marked this pull request as ready for review August 6, 2020 23:48
@jromero jromero requested a review from a team as a code owner August 6, 2020 23:48
Copy link
Member

@dfreilich dfreilich left a comment

Choose a reason for hiding this comment

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

Looks great. Should we have a warning that this may not work on other OSs?


func (i *PackInvoker) not0_11_0() bool {
// laterThan returns true if pack version is older than the provided version
func (i *PackInvoker) laterThan(version string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@jromero
Copy link
Member Author

jromero commented Aug 7, 2020

Looks great. Should we have a warning that this may not work on other OSs?

The only one I know of in which this may not work is Windows (WCOW) but honestly haven't thoroughly tested it in LCOW.

@ameyer-pivotal
Copy link
Contributor

ameyer-pivotal commented Aug 7, 2020

Looks great. Should we have a warning that this may not work on other OSs?

The only one I know of in which this may not work is Windows (WCOW) but honestly haven't thoroughly tested it in LCOW.

@jromero for WCOW, the solution would be fairly simple. Just use the mounts.NewParser(mounts.OSWindows) parser and users would just need to provide the target location as c:/path/in/container.

@jromero
Copy link
Member Author

jromero commented Aug 7, 2020

Looks great. Should we have a warning that this may not work on other OSs?

The only one I know of in which this may not work is Windows (WCOW) but honestly haven't thoroughly tested it in LCOW.

@jromero for WCOW, the solution would be fairly simple. Just use the mounts.NewParser(mounts.OSWindows) parser and users would just need to provide the target location as c:/path/in/container.

@ameyer-pivotal Thank you. If I'm not mistaken this will be taken care of as part of #739

@jromero jromero merged commit 3a3bf28 into main Aug 7, 2020
@jromero jromero deleted the feature/764-read-write-volumes branch August 7, 2020 19:05
@jromero jromero added the type/enhancement Issue that requests a new feature or improvement. label Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Known to be non-backwards compatible type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update --volume to support arbitrary target locations
3 participants