Docker Containers

Containers are the preferred mechanism for deploying applications built with Nstream. This allows the dependencies and Java runtime to be packaged together with known versions.

Considerations

Gradle

Google provides a great plugin called Jib that will build a container as part of your Gradle lifecycle. The following code snippet is from our Cellular application.

    mainClassName = 'swim.cellular.CellularPlane'
    
    jib {
    from {
      image = "openjdk:11"
    }
    to {
      image = "nstream/demo-cellular:${version}"
      auth {
        username = "$System.env.REGISTRY_USERNAME"
        password = "$System.env.REGISTRY_PASSWORD"
      }
    }
    container {
      mainClass = mainClassName
      ports = ['9001/tcp']
      jvmFlags = ['-Dswim.config=/config/server.recon']
    }
    extraDirectories {
      paths {
        path {
          // copies a single-file.xml
          from = 'src/main/resources'
          into = '/config'
          includes = ['*.recon']
        }
      }
    }

Build a local container

gradle jibDockerBuild

Build container for a docker registry.

gradle jib

Maven

Google also provides a plugin for Maven.

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>2.2.0</version>
    <configuration>
        <from>
            <image>openjdk:11</image>
        </from>
        <to>
            <image>nstream/demo-cellular:${project.version}</image>
        </to>
        <container>
            <mainClass>swim.cellular.CellularPlane</mainClass>
            <ports>
                <port>9001/tcp</port>
            </ports>
        </container>
        <extraDirectories>
            <paths>
                <path>
                    <from>src/main/resources</from>
                    <into>/config</into>
                    <includes>*.recon</includes>
                </path>
            </paths>
        </extraDirectories>
    </configuration>
</plugin>

Build a local container

mvn compile jib:dockerBuild

Build container for a docker registry.

mvn compile jib:build