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

[WIP] Add softlinks at runtime for every classpath entry #2

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tomcat/add-classpath-entries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

mkdir -p "{{.libDir}}"
while IFS=: read -d: -r path; do
printf "Linking $path to '{{.libDir}}/$(basename $path)'\n"
nebhale marked this conversation as resolved.
Show resolved Hide resolved
ln -s "$path" "{{.libDir}}/$(basename $path)"
done <<< "${CLASSPATH}"
17 changes: 17 additions & 0 deletions tomcat/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (b Base) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to contribute logging\n%w", err)
}

if err := b.ContributeClasspathEntries(layer); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to contribute classpath entries\n%w", err)
}

if b.ExternalConfigurationDependency != nil {
if err := b.ContributeExternalConfiguration(layer); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to contribute external configuration\n%w", err)
Expand Down Expand Up @@ -294,6 +298,19 @@ func (b Base) ContributeLogging(layer libcnb.Layer) error {
return nil
}

func (b Base) ContributeClasspathEntries(layer libcnb.Layer) error {
b.Logger.Bodyf("Adding profile-script 'add-classpath-entries.sh'")

libDir := fmt.Sprintf("%s/lib", layer.Path)
jkbschmid marked this conversation as resolved.
Show resolved Hide resolved
s, err := sherpa.TemplateFile("/add-classpath-entries.sh", map[string]interface{}{"libDir": libDir})
if err != nil {
return fmt.Errorf("unable to load add-classpath-entries.sh\n%w", err)
}

layer.Profile.Add("add-classpath-entries.sh", s)
return nil
}

func (Base) Name() string {
return "catalina-base"
}
9 changes: 9 additions & 0 deletions tomcat/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ printf "Tomcat Access Logging enabled\n"

export JAVA_OPTS="${JAVA_OPTS} -Daccess.logging.enabled=true"
`))
libDir := filepath.Join(layer.Path, "lib")
Expect(layer.Profile["add-classpath-entries.sh"]).To(Equal(fmt.Sprintf(`#!/bin/sh

mkdir -p "%[1]s"
while IFS=: read -d: -r path; do
printf "Linking $path to '%[1]v/$(basename $path)'\n"
ln -s "$path" "%[1]s/$(basename $path)"
done <<< "${CLASSPATH}"
`, libDir)))
Expect(filepath.Join(layer.Path, "lib", "stub-tomcat-lifecycle-support.jar")).To(BeARegularFile())
Expect(filepath.Join(layer.Path, "bin", "stub-tomcat-logging-support.jar")).To(BeARegularFile())
Expect(ioutil.ReadFile(filepath.Join(layer.Path, "bin", "setenv.sh"))).To(Equal([]byte(fmt.Sprintf(`# shellcheck disable=SC2034
Expand Down
2 changes: 1 addition & 1 deletion tomcat/statik/statik.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.