The Case of the Vanishing Dockerfile

If your serverless platform is Oracle Functions or the open source Fn Project that it is based on, you may have wondered exactly how a function image gets built for one of the standard runtimes.

One clue is that if you're watching closely you may see a Dockerfile appear briefly, then vanish during the build process.

The Fn CLI will create the Dockerfile for the runtime, build the function and then delete it once the build has completed.

You can see the steps of the docker build by running fn build or fn deploy with the --verbose flag specified:

$ fn build --verbose                                  [14:57:34]
Building image fra.ocir.io/oraseemeatechse/crush157/dummy:0.0.1
FN_REGISTRY:  fra.ocir.io/oraseemeatechse/crush157
Current Context:  default
Sending build context to Docker daemon  14.34kB
Step 1/11 : FROM fnproject/fn-java-fdk-build:jdk11-1.0.108 as build-stage
 ---> e3c33b854f29
Step 2/11 : WORKDIR /function
 ---> Using cache
 ---> c0bcff391281
Step 3/11 : ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository
 ---> Using cache
 ---> aae7552e4aed
Step 4/11 : ADD pom.xml /function/pom.xml
 ---> Using cache
 ---> b199c9d67213
Step 5/11 : RUN ["mvn", "package", "dependency:copy-dependencies", "-DincludeScope=runtime", "-DskipTests=true", "-Dmdep.prependGroupId=true", "-DoutputDirectory=target", "--fail-never"]
 ---> Using cache
 ---> da9254c64c68
Step 6/11 : ADD src /function/src
 ---> Using cache
 ---> 4851da59cf62
Step 7/11 : RUN ["mvn", "package"]
 ---> Using cache
 ---> 02bd3419bff8
Step 8/11 : FROM fnproject/fn-java-fdk:jre11-1.0.108
 ---> ea31ad6990fe
Step 9/11 : WORKDIR /function
 ---> Using cache
 ---> 0eb543f603e0
Step 10/11 : COPY --from=build-stage /function/target/*.jar /function/app/
 ---> Using cache
 ---> cc501a8df196
Step 11/11 : CMD ["com.example.fn.HelloFunction::handleRequest"]
 ---> Using cache
 ---> 70c359b81d22
Successfully built 70c359b81d22
Successfully tagged fra.ocir.io/oraseemeatechse/crush157/dummy:0.0.1
 
You can then capture this output to recreate the Dockerfile, say to customise it, using the following command:

fn build --verbose | grep -i Step |> Dockerfile.new cut -d ' ' -f4-


Note the use of case insensitive grep -i Step, as later versions of the Fn CLI output STEP instead of Step.

Since the Fn CLI is writing to Dockerfile, you'll need to create your output file with a different name (e.g. Dockerfile.new), and then rename it to have it used by fn build or fn deploy.

Once you have your Dockerfile, delete the Fn generated func.yaml and run fn init again.  Fn should recognise the Dockerfile and generate a new func.yaml.

$ fn init                                             [15:12:18]
Dockerfile found. Using runtime 'docker'.
func.yaml created.
$ cat func.yaml                                       [15:13:12]
schema_version: 20180708
name: dummy
version: 0.0.1
runtime: docker
Your function will now be built using the Dockerfile, which you can customise as you require.

Comments

Popular posts from this blog

Wot no FDK?

Honey I Shrunk The Container