Stateful Functions applications can be packaged as either standalone applications or Flink jobs that can be submitted to a cluster.
The recommended deployment mode for Stateful Functions applications is to build a Docker image. This way, user code does not need to package any Apache Flink components. The provided base image allows teams to package their applications with all the necessary runtime dependencies quickly.
Below is an example Dockerfile for building a Stateful Functions image with both an [embedded module]({{ site.baseurl }}/sdk/modules.html#embedded-module) and a [remote module]({{ site.baseurl }}/sdk/modules.html#remote-module) for an application called statefun-example
.
{% highlight dockerfile %} FROM flink-statefun:{{ site.version }}
RUN mkdir -p /opt/statefun/modules/statefun-example RUN mkdir -p /opt/statefun/modules/remote
COPY target/statefun-example*jar /opt/statefun/modules/statefun-example/ COPY module.yaml /opt/statefun/modules/remote/module.yaml {% endhighlight %}
{% if site.is_stable %}
<code class="language-dockerfile" data-lang="dockerfile"> <span class="k">FROM</span><span class="s"> ververica/flink-statefun:{{ site.version }}</span> </code> You can follow the status of Docker Hub contribution <a href="https://github.com/docker-library/official-images/pull/7749">here</a>.
<code class="language-dockerfile" data-lang="dockerfile"> <span class="s">tools/docker/README.md</span> </code>
If you prefer to package your job to submit to an existing Flink cluster, simply include statefun-flink-distribution
as a dependency to your application.
{% highlight xml %} org.apache.flink statefun-flink-distribution {{ site.version }} {% endhighlight %}
It includes all of Stateful Functions' runtime dependencies and configures the application's main entry-point.
{% highlight bash %} ./bin/flink run -c org.apache.flink.statefun.flink.core.StatefulFunctionsJob ./statefun-example.jar {% endhighlight %}
The following configurations are strictly required for running StateFun application.
{% highlight yaml %} classloader.parent-first-patterns.additional: org.apache.flink.statefun;org.apache.kafka;com.google.protobuf {% endhighlight %}