Skip to content

Commit

Permalink
Fix process type parsing (#912)
Browse files Browse the repository at this point in the history
* Use the last part of the path when trying to find matching process. (#903)

* Use the last part of the path when trying to find matching process.

The process was comparing the base path minus the extension, which was blocking types with a `.` in them from ever matching.

Fixes #895

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* fixup! Use the last part of the path when trying to find matching process.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* fixup! Use the last part of the path when trying to find matching process.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* fixup! Use the last part of the path when trying to find matching process.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* fixup! Use the last part of the path when trying to find matching process.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* fixup! Use the last part of the path when trying to find matching process.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* fixup! Use the last part of the path when trying to find matching process.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>

* Upgrade go to 1.18 (#907)

* Use go 1.18 in CI
* Bump deps (except toml)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Test path lookup (#909)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Revert "Merge branch 'release/0.14.2' into jab/fix-process-type-parsing"

This reverts commit 6f56a31, reversing
changes made to e544937.

Signed-off-by: Jesse Brown <jabrown85@gmail.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Co-authored-by: Natalie Arellano <narellano@vmware.com>

* Bump imgutil

Signed-off-by: Natalie Arellano <narellano@vmware.com>

Signed-off-by: Jesse Brown <jabrown85@gmail.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Co-authored-by: Jesse Brown <jabrown85@gmail.com>
  • Loading branch information
natalieparellano and jabrown85 authored Sep 14, 2022
1 parent df06171 commit 8241b13
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 6 deletions.
10 changes: 10 additions & 0 deletions acceptance/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func testLauncher(t *testing.T, when spec.G, it spec.S) {
assertOutput(t, cmd, "Executing web process-type")
})

when("process contains a period", func() {
it("launches that process", func() {
cmd := exec.Command("docker", "run", "--rm",
"--entrypoint=process.with.period"+exe,
"--env=CNB_PLATFORM_API="+latestPlatformAPI,
launchImage)
assertOutput(t, cmd, "Executing process.with.period process-type")
})
})

it("appends any args to the process args", func() {
cmd := exec.Command("docker", "run", "--rm",
"--entrypoint=web",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@
args = ["$WORKER_VAR"]
direct = false
buildpack-id = "0.4/buildpack"

[[processes]]
type = "process.with.period"
command = "echo"
args = ["Executing process.with.period process-type"]
direct = false
buildpack-id = "0.4/buildpack"
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@
args = ["/c", "echo VAR_FROM_EXEC_D: %VAR_FROM_EXEC_D%"]
direct = false
buildpack-id = "0.5/buildpack"

[[processes]]
type = "process.with.period"
command = "echo"
direct = false
args = ["Executing", "process.with.period", "process-type"]
buildpack-id = "some/buildpack"
8 changes: 5 additions & 3 deletions cmd/launcher/cli/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func defaultProcessType(platformAPI *api.Version, launchMD launch.Metadata) stri
cmd.DefaultLogger.Warnf("CNB_PROCESS_TYPE is not supported in Platform API %s", platformAPI)
cmd.DefaultLogger.Warnf("Run with ENTRYPOINT '%s' to invoke the '%s' process type", pType, pType)
}
process := strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0]))
if _, ok := launchMD.FindProcessType(process); ok {
return process

_, process := filepath.Split(os.Args[0])
processType := strings.TrimSuffix(process, platform.DefaultExecExt)
if _, ok := launchMD.FindProcessType(processType); ok {
return processType
}
return ""
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/BurntSushi/toml v1.1.0
github.com/apex/log v1.9.0
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20220906183739-a13b39e9d86d
github.com/buildpacks/imgutil v0.0.0-20220805205524-56137f75e24d
github.com/buildpacks/imgutil v0.0.0-20220913203928-6accc39f0cf9
github.com/chrismellard/docker-credential-acr-env v0.0.0-20220327082430-c57b701bfc08
github.com/docker/docker v20.10.18+incompatible
github.com/golang/mock v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbz
github.com/blizzy78/varnamelen v0.3.0/go.mod h1:hbwRdBvoBqxk34XyQ6HA0UH3G0/1TKuv5AC4eaBT0Ec=
github.com/bombsimon/wsl/v3 v3.3.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
github.com/breml/bidichk v0.1.1/go.mod h1:zbfeitpevDUGI7V91Uzzuwrn4Vls8MoBMrwtt78jmso=
github.com/buildpacks/imgutil v0.0.0-20220805205524-56137f75e24d h1:06r2+NQ34WRTcqshXDvaQqOSeFDa8QPlxmClEYPdYCY=
github.com/buildpacks/imgutil v0.0.0-20220805205524-56137f75e24d/go.mod h1:S2RQzj190M80SV4VbpoCxeyoVYKjRN8qcIPLXEWNuF0=
github.com/buildpacks/imgutil v0.0.0-20220913203928-6accc39f0cf9 h1:44evShMGyqmWmuy/w6mD2wsuHsIMldOcptV4LjC2MjM=
github.com/buildpacks/imgutil v0.0.0-20220913203928-6accc39f0cf9/go.mod h1:YeEEHF5p5VpTAoVbf8pZ5peFuz50TrElzsNpeNELqgA=
github.com/butuzov/ireturn v0.1.1/go.mod h1:Wh6Zl3IMtTpaIKbmwzqi6olnM9ptYQxxVacMsOEFPoc=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down
21 changes: 21 additions & 0 deletions platform/launch/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package launch

import "path/filepath"

const (
EnvAppDir = "CNB_APP_DIR"
EnvLayersDir = "CNB_LAYERS_DIR"
EnvNoColor = "CNB_NO_COLOR" // defaults to false
EnvPlatformAPI = "CNB_PLATFORM_API"
EnvProcessType = "CNB_PROCESS_TYPE"

DefaultPlatformAPI = "0.3"
DefaultProcessType = "web"

DefaultExecExt = execExt
)

var (
DefaultAppDir = filepath.Join(rootDir, "workspace")
DefaultLayersDir = filepath.Join(rootDir, "layers")
)
9 changes: 9 additions & 0 deletions platform/launch/defaults_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build linux || darwin
// +build linux darwin

package launch

const (
execExt = ""
rootDir = "/"
)
6 changes: 6 additions & 0 deletions platform/launch/defaults_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package launch

const (
execExt = ".exe"
rootDir = `c:\`
)

0 comments on commit 8241b13

Please sign in to comment.