Skip to content

Commit

Permalink
pass directory to the buildpack downloader directly
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Busko <pavel.busko@sap.com>
  • Loading branch information
modulo11 and pbusko committed Jul 24, 2024
1 parent fb80538 commit bdf461f
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 59 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/apex/log v1.9.0
github.com/buildpacks/lifecycle v0.19.7
github.com/buildpacks/pack v0.34.2
github.com/buildpacks/pack v0.35.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/docker/docker v27.0.3+incompatible
github.com/google/go-containerregistry v0.19.2
github.com/google/go-containerregistry v0.20.0
github.com/jarcoal/httpmock v1.3.1
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
Expand Down Expand Up @@ -61,7 +61,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v26.1.3+incompatible // indirect
github.com/docker/cli v26.1.4+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.1 // indirect
github.com/docker/go-connections v0.5.0 // indirect
Expand Down Expand Up @@ -117,13 +117,13 @@ require (
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
Expand Down
42 changes: 22 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUM
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/GoogleContainerTools/kaniko v1.23.0 h1:/YTWOF3uL40kNyK2821Wc+12Czlon1U+gmISWw9CLTM=
github.com/GoogleContainerTools/kaniko v1.23.0/go.mod h1:lTA7EDyPzSGYxcXxaxWCztINdHMb1Qxj6+eAn1vo2EI=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
Expand Down Expand Up @@ -90,8 +92,8 @@ github.com/buildpacks/imgutil v0.0.0-20240605145725-186f89b2d168 h1:yVYVi1V7x1bX
github.com/buildpacks/imgutil v0.0.0-20240605145725-186f89b2d168/go.mod h1:n2R6VRuWsAX3cyHCp/u0Z4WJcixny0gYg075J39owrk=
github.com/buildpacks/lifecycle v0.19.7 h1:q9a96xDGC7mhzJ5h+Esrg7q8PSYgL5XmBiBnSRNLalw=
github.com/buildpacks/lifecycle v0.19.7/go.mod h1:OJ8JCdBSbzeY45l5l3YuGbcPAOKYUv1GUaKP2uDeUS0=
github.com/buildpacks/pack v0.34.2 h1:6+BvuYeS07QUJZAkb/L9v2TI7mtLA2zzbfewfB4bRT8=
github.com/buildpacks/pack v0.34.2/go.mod h1:g1o7cohzXn2X+uYdWKdFgity1l2QvUDSGIMVhzBbA1M=
github.com/buildpacks/pack v0.35.0 h1:cgIZ5T1fKVBOAb3CtHJAMlRb3/OYez3fIIyqmComVhY=
github.com/buildpacks/pack v0.35.0/go.mod h1:ttb2Qmr1u7LKnhZNZJLCE/WQUXTtZoo+mJ4welgxS5c=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down Expand Up @@ -126,8 +128,8 @@ github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v26.1.3+incompatible h1:bUpXT/N0kDE3VUHI2r5VMsYQgi38kYuoC0oL9yt3lqc=
github.com/docker/cli v26.1.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v26.1.4+incompatible h1:I8PHdc0MtxEADqYJZvhBrW9bo8gawKwwenxRM7/rLu8=
github.com/docker/cli v26.1.4+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v27.0.3+incompatible h1:aBGI9TeQ4MPlhquTQKq9XbK79rKFVwXNUAYz9aXyEBE=
Expand Down Expand Up @@ -194,8 +196,8 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-containerregistry v0.19.2 h1:TannFKE1QSajsP6hPWb5oJNgKe1IKjHukIKDUmvsV6w=
github.com/google/go-containerregistry v0.19.2/go.mod h1:YCMFNQeeXeLF+dnhhWkqDItx/JSkH01j1Kis4PsjzFI=
github.com/google/go-containerregistry v0.20.0 h1:wRqHpOeVh3DnenOrPy9xDOLdnLatiGuuNRVelR2gSbg=
github.com/google/go-containerregistry v0.20.0/go.mod h1:YCMFNQeeXeLF+dnhhWkqDItx/JSkH01j1Kis4PsjzFI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg=
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
Expand Down Expand Up @@ -266,8 +268,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e h1:Qa6dnn8DlasdXRnacluu8HzPts0S1I9zvvUPDbBnXFI=
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e/go.mod h1:waEya8ee1Ro/lgxpVhkJI4BVASzkm3UZqkx/cFJiYHM=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/buildkit v0.13.2 h1:nXNszM4qD9E7QtG7bFWPnDI1teUQFQglBzon/IU3SzI=
github.com/moby/buildkit v0.13.2/go.mod h1:2cyVOv9NoHM7arphK9ZfHIWKn9YVZRFd1wXB8kKmEzY=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
Expand Down Expand Up @@ -430,13 +432,13 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -482,30 +484,30 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
82 changes: 77 additions & 5 deletions integration/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var _ = Describe("Lifecycle", func() {

BeforeEach(func() {
cacheDir = GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
req := testcontainers.ContainerRequest{
Image: "ubuntu:noble",
ImagePlatform: "linux/amd64",
Expand Down Expand Up @@ -59,7 +60,7 @@ var _ = Describe("Lifecycle", func() {
return err
},
func(ctx context.Context, container testcontainers.Container) error {
code, _, err := container.Exec(ctx, []string{"apt", "install", "ca-certificates", "-y"})
code, _, err := container.Exec(ctx, []string{"apt", "install", "ca-certificates", "skopeo", "-y"})
if code != 0 {
return fmt.Errorf("failed to run install ca-certificates, RC: %d", code)
}
Expand All @@ -75,13 +76,37 @@ var _ = Describe("Lifecycle", func() {
return err
}

if err := container.CopyDirToContainer(ctx, "workspace", "/home/ubuntu/", 0o755); err != nil {
if err := container.CopyDirToContainer(ctx, "./testdata/workspace", "/home/ubuntu/", 0o755); err != nil {
return err
}

code, _, err := container.Exec(ctx, []string{"chown", "-R", "ubuntu:ubuntu", "/home/ubuntu/workspace"})
if code != 0 {
return fmt.Errorf("failed to run run chown, RC: %d", code)
return fmt.Errorf("failed to run chown, RC: %d", code)
}
if err != nil {
return err
}

code, _, err = container.Exec(ctx, []string{"mkdir", "-p", "/tmp/buildpacks"})
if code != 0 {
return fmt.Errorf("failed to run mkdir, RC: %d", code)
}
if err != nil {
return err
}

code, _, err = container.Exec(ctx, []string{"skopeo", "copy", "docker://gcr.io/paketo-buildpacks/java:latest", "oci:/tmp/buildpacks/10bfa3ba0b8af13e"})
if code != 0 {
return fmt.Errorf("failed to run skopeo, RC: %d", code)
}
if err != nil {
return err
}

code, _, err = container.Exec(ctx, []string{"chown", "-R", "ubuntu:ubuntu", "/tmp/buildpacks"})
if code != 0 {
return fmt.Errorf("failed to run chown, RC: %d", code)
}

return err
Expand All @@ -97,7 +122,54 @@ var _ = Describe("Lifecycle", func() {
Expect(err).To(BeNil())
})

It("should succeed", func() {
It("should build an app using system buildpacks", func() {
code, out, err := testContainer.Exec(context.Background(), []string{
"/tmp/builder",
"-b", "gcr.io/paketo-buildpacks/java",
"-r", "/tmp/build-result.json",
"-d", "/tmp/droplet.tgz",
"-l", "/home/ubuntu/layers",
"-w", "/home/ubuntu/workspace",
"--pass-env-var", "BP_JVM_VERSION",
}, exec.WithUser("ubuntu"))
Expect(err).To(BeNil())

buf := bytes.NewBufferString("")
_, err = io.Copy(buf, out)
Expect(err).To(BeNil())
outString := buf.String()
Expect(outString).To(ContainSubstring("Downloading buildpack from URI: file://"))
Expect(outString).To(ContainSubstring("Run image info in analyzed metadata is"))
Expect(outString).To(ContainSubstring("Checking for match against descriptor"))
Expect(outString).To(ContainSubstring("Finished running build"))
Expect(outString).To(ContainSubstring("Copying SBOM files"))
Expect(outString).To(ContainSubstring("Listing processes"))
Expect(outString).To(ContainSubstring("Builder ran for"))
Expect(outString).To(ContainSubstring("result file saved to"))
Expect(outString).To(ContainSubstring("droplet archive saved to"))

Expect(code).To(Equal(0))

r, err := testContainer.CopyFileFromContainer(context.Background(), "/tmp/build-result.json")
Expect(err).To(BeNil())
defer r.Close()

resultBuf := bytes.NewBuffer(nil)
_, err = io.Copy(resultBuf, r)
Expect(err).To(BeNil())

result := staging.StagingResult{}
Expect(json.Unmarshal(resultBuf.Bytes(), &result)).To(Succeed())
Expect(result.LifecycleType).To(Equal("cnb"))
Expect(result.ProcessTypes).To(Equal(staging.ProcessTypes{
"executable-jar": "java org.springframework.boot.loader.JarLauncher",
"task": "java org.springframework.boot.loader.JarLauncher",
"web": "java org.springframework.boot.loader.JarLauncher",
}))
Expect(result.Buildpacks).To(HaveLen(10))
})

It("build an app using custom buildpacks", func() {
By("building the app", func() {
code, out, err := testContainer.Exec(context.Background(), []string{
"/tmp/builder",
Expand Down Expand Up @@ -163,7 +235,7 @@ var _ = Describe("Lifecycle", func() {
Expect(code).To(Equal(0))
Expect(err).To(BeNil())

Expect(testContainer.CopyDirToContainer(context.Background(), "workspace", "/home/ubuntu/", 0o755)).To(Succeed())
Expect(testContainer.CopyDirToContainer(context.Background(), "testdata/workspace", "/home/ubuntu/", 0o755)).To(Succeed())
code, _, err = testContainer.Exec(context.Background(), []string{"chown", "-R", "ubuntu:ubuntu", "/home/ubuntu/workspace"})
Expect(code).To(Equal(0))
Expect(err).To(BeNil())
Expand Down
File renamed without changes.
25 changes: 1 addition & 24 deletions pkg/buildpacks/translate.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package buildpacks

import (
"archive/tar"
"compress/gzip"
"errors"
"fmt"
"os"
"path/filepath"

"code.cloudfoundry.org/cnbapplifecycle/pkg/archive"
"code.cloudfoundry.org/cnbapplifecycle/pkg/log"
"github.com/cespare/xxhash/v2"
)
Expand All @@ -24,12 +21,7 @@ func Translate(bps []string, buildpacksDir string, logger *log.Logger) ([]string
}

if downloaded {
newPath, err := createArchive(bpDir)
if err != nil {
return nil, err
}

newList = append(newList, newPath)
newList = append(newList, fmt.Sprintf("file://%s", bpDir))
} else {
newList = append(newList, bp)
}
Expand Down Expand Up @@ -59,18 +51,3 @@ func checkIfDownloaded(path string) (bool, error) {
func buildpackPath(name string, path string) string {
return filepath.Join(path, fmt.Sprintf("%016x", xxhash.Sum64String(name)))
}

func createArchive(path string) (string, error) {
newPath := fmt.Sprintf("%s.tgz", path)

f, err := os.OpenFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o644)
if err != nil {
return "", err
}
defer f.Close()

bgw := gzip.NewWriter(f)
defer bgw.Close()

return fmt.Sprintf("file://%s", newPath), archive.FromDirectory(path, tar.NewWriter(bgw))
}
4 changes: 2 additions & 2 deletions pkg/buildpacks/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ var _ = Describe("Translate", func() {
bps, err = buildpacks.Translate(bps, bpDir, logger)
Expect(err).NotTo(HaveOccurred())
Expect(bps).To(Equal([]string{
fmt.Sprintf("file://%s.tgz", filepath.Join(bpDir, hashedName)),
fmt.Sprintf("file://%s", filepath.Join(bpDir, hashedName)),
"bar",
}))
Expect(fmt.Sprintf("%s.tgz", filepath.Join(bpDir, hashedName))).To(BeARegularFile())
Expect(filepath.Join(bpDir, hashedName)).To(BeADirectory())
})

When("when hashed path is not a directory", func() {
Expand Down

0 comments on commit bdf461f

Please sign in to comment.