Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Add Dockerfile for Scala Stream Collector (closes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacox authored and BenFradet committed Oct 3, 2017
1 parent 4b6acc8 commit 246d364
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ script:
env:
matrix:
- IMG=base
- IMG=scala-stream-collector/0.10.0
global:
# BINTRAY_SNOWPLOW_DOCKER_USER
- secure: IcBMTopBAIzGlWNgS7dw0iNmvFhd2dgSn/Y1mt6hXnzLrr7SDryRuxPqemsCBLIlf4xtpgHvuOoo+7jYywtAOqyHQ+EOnR5eU8/28v+Z8zd/Djnw0Sv10RV5oMS6ejh9gGS4WDNPvf9M1sfP5p+0gA0p68dNeObLDT4TwpG2pdpeEuqQ3RMGCQc+tb3Q26K6aUPXeIgAHUyIEgHtzxxfgrGNwSmxdb6npsWTUttKpQkJudGRk17xXW67Dd0PKLWJkDpien/lbkLIBK8MlwaH03NMawGcTChgM2njcqElqz1b46wxl1ATcVV2T7A6YPYZxb012P8j/KUZ6MLhdDFNhmz/jIk6caEZ3x4AH2Q0qN8C9Hn70yMN8gAliBeUN4pjLpKnD8t5HgCE+90EufppcQRCfCJhSk9xmegTaikan3QZCN09vwSctIBu4AeWYqctql6bLhNWguakbRIyk9feogmxqbn2HSoFpRrAEqXXv9jFKJrKm2UNKuLbXCvyoYqjAhxTPn7OMAY30wqsVSUu5gSt1fO0Pd+5H8yq44Ul3jROgYKM5NlLWUY+u8qp6KKm2zXQ2LFlr8rzZ2ar5pI9zZiABDMnRRUdAXDTnpDw2HtBvngGXhyfr/irrzach0z/f5YwHL7WVf9Wu7MqoVpexdDqThNGip4ansIikrC57LE=
Expand Down
26 changes: 26 additions & 0 deletions scala-stream-collector/0.10.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM snowplow/base:0.1.0
LABEL maintainer="Snowplow Analytics Ltd. <[email protected]>"

# The version of the collector to download.
ENV COLLECTOR_VERSION="0.10.0"

# The name of the archive to download.
ENV ARCHIVE="snowplow_scala_stream_collector_${COLLECTOR_VERSION}.zip"

# Install the Scala Stream Collector.
RUN mkdir -p /tmp/build && \
cd /tmp/build && \
wget -q http://dl.bintray.com/snowplow/snowplow-generic/${ARCHIVE} && \
unzip -d ${SNOWPLOW_BIN_PATH} ${ARCHIVE} && \
cd /tmp && \
rm -rf /tmp/build

# Port used by the collector.
EXPOSE 80

# Defines an entrypoint script delegating the lauching of the collector to the snowplow user.
# The script uses dumb-init as the top-level process.
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT [ "docker-entrypoint.sh" ]

CMD [ "--usage" ]
12 changes: 12 additions & 0 deletions scala-stream-collector/0.10.0/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/dumb-init /bin/sh
set -e

# If the config directory has been mounted through -v, we chown it.
if [ "$(stat -c %u ${SNOWPLOW_CONFIG_PATH})" != "$(id -u snowplow)" ]; then
chown snowplow:snowplow ${SNOWPLOW_CONFIG_PATH}
fi

# Make sure we run the collector as the snowplow user
exec su-exec snowplow:snowplow /usr/bin/java \
$SP_JAVA_OPTS \
-jar ${SNOWPLOW_BIN_PATH}/snowplow-stream-collector-${COLLECTOR_VERSION}.jar "$@"
89 changes: 89 additions & 0 deletions scala-stream-collector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Scala Stream Collector

This folder contains the Docker image for [the Snowplow Scala Stream Collector][ssc]

## Introduction

This image is based on [the base image][base-image] which leverages
[the Java 8 Alpine image][alpine-image].

The Scala Stream Collector runs under [dumb-init][dumb-init] which handles reaping zombie processes
and forwards signals on to all processes running in the container. This image also uses
[su-exec][su-exec], as a sudo replacement, to run the collector as the non-root `snowplow` user.

The container exposes the `/snowplow/config` volume to store the collector configuration. If this
folder is bind mounted then ownership will be changed to the `snowplow` user.

The container exposes the port 80 to be able to receive requests.

The `-XX:+UnlockExperimentalVMOptions` and `-XX:+UseCGroupMemoryLimitForHeap` JVM options will be
automatically provided when launching the collector in order to make the JVM adhere to the memory
limits imposed by Docker. For more information, see [this article][jvm-docker-article] for more
information.

Additional JVM options can be set through the `SP_JAVA_OPTS` environment variable.

## Usage

Running the container without arguments will print out its usage:

```bash
$ docker run snowplow/scala-stream-collector:latest

snowplow-stream-collector 0.x.0
Usage: snowplow-stream-collector [options]

--help
--version
--config <filename>
```

Alternatively, we can mount a configuration folder, publish port 80, and run the collector:

```bash
$ docker run \
-d \
-v config:/snowplow/config \
-p 80:80 \
snowplow/scala-stream-collector:latest \
--config /snowplow/config/config.hocon
```

If we want to specify additional JVM options, we can add the `SP_JAVA_OPTS` environment variable:

```bash
$ docker run \
-d \
-v config:/snowplow/config \
-p 80:80 \
-e 'SP_JAVA_OPTS=-Xms512m -Xmx512m' \
snowplow/scala-stream-collector:latest \
--config /snowplow/config/config.hocon
```

For a more complete example, check out [the docker compose example][docker-compose-example].

## Copyright and license

The Scala Stream Collector image is copyright 2017-2017 Snowplow Analytics Ltd.

Licensed under the [Apache License, Version 2.0][license] (the "License");
you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

[base-image]: https://github.com/snowplow/snowplow-docker/tree/master/base
[docker-compose-example]: https://github.com/snowplow/snowplow-docker/tree/master/example
[alpine-image]: https://github.com/docker-library/openjdk/blob/master/8-jre/alpine/Dockerfile

[ssc]: https://github.com/snowplow/snowplow/tree/master/2-collectors/scala-stream-collector
[dumb-init]: https://github.com/Yelp/dumb-init
[su-exec]: https://github.com/ncopa/su-exec

[jvm-docker-article]: https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits

[license]: http://www.apache.org/licenses/LICENSE-2.0

0 comments on commit 246d364

Please sign in to comment.