openfaas / templates

OpenFaaS Classic templates
https://www.openfaas.com
MIT License
279 stars 228 forks source link

Edit java template to allow resources #72

Open ivanayov opened 6 years ago

ivanayov commented 6 years ago

Raised on slack.

Resources, located in funcName/src/main/resources, are not available in the image after build.

Expected Behaviour

All resources should be available in the image.

Possible Solution

Follow Gradle documentation (possibly use SourceSet) and edit build.gradle

Steps to Reproduce (for bugs)

  1. faas-cli new funcName --lang java8
  2. Add resources to /src/main/resources
  3. Build
  4. Check that resources are not available
ivanayov commented 6 years ago

I'm on it

ivanayov commented 5 years ago

This does the work:

sourceSets {
    main {
        resources {
            srcDirs "src/main/resources"
        }
    }

The issue is because model is what's compiled in function's build.gradle config and it takes src/main/resources from model/ template dir.

ivanayov commented 5 years ago

I'm going to update tomorrow

ivanayov commented 5 years ago

The problem occurs while entrypoint distribution is created. The original function.jar contains the resources, but the copied one does not. The gradle build logs say nothing about jar clean-up, nor it's configured within the template:

16:01:58.896 [DEBUG] [org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter] Ensuring parent directory exists for property archivePath (OUTPUT) at /home/app/function/bui
ld/libs/function-1.0.jar
16:01:58.896 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':function:jar'.
16:01:58.897 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute copy for :function:jar' started
16:01:58.900 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute copy for :function:jar'
16:01:58.900 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute copy for :function:jar' completed
16:01:58.900 [DEBUG] [org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository] Snapshotting property archivePath (OUTPUT) for task ':function:jar'
16:01:58.901 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
16:01:58.901 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':function:jar'
16:01:58.901 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Task :function:jar'
16:01:58.901 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :function:jar' completed
16:01:58.901 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :function:jar (Thread[Task worker for ':',5,main]) completed. Took 0.009 secs.

(1) Bad but working solution: replace function.jar within entrypoint distribution after gradle build in Dockerfile

(2) Better approach: Fix within gradle configuration.

I didn't find a working solution for (2) yet. Still on it today.

ivanayov commented 5 years ago

Have the fix in #86