Skip to content
No description, website, or topics provided.
Scala Dockerfile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project Add GitLab CI integration Aug 11, 2019
src Add test case for null JSON values Aug 11, 2019
.gitignore Initial commit Aug 10, 2019
.gitlab-ci.yml Add GitLab CI integration Aug 11, 2019
.jvmopts Test api endpoints Aug 10, 2019
Dockerfile Add GitLab CI integration Aug 11, 2019
README.md Provide an execution sample Aug 11, 2019
REQUIREMENTS.md Add GitLab CI integration Aug 11, 2019
build.sbt Add GitLab CI integration Aug 11, 2019
scalaVersion.sbt Add GitLab CI integration Aug 11, 2019
version.sbt Release 1.0.0 Aug 11, 2019

README.md

Snowplow JSON validator

Implementation of Snowplow engineering technical test instructions - JSON validation service

pipeline status coverage report

Assumptions

  • GET /schema/id returns a status message with a getSchema action, not just the schema itself
  • Calling POST /schema/id twice with the same id is an error and does therefore not override the existing schema
  • Error messages may differ from the examples in the instructions document

Implementation remarks

  • Simple file system storage seems sufficient for this task and allows me to avoid the complexity of a database. The feature can however be added easily by providing a respective SchemaStorage implementation.
  • I picked release candidate / milestone dependencies as an opportunity to take a look at new features such as the cats-effect Blocker. In a real-world production scenario I would of course choose stable releases.
  • The usage of json-schema-validator and circe is a bit of a mess causing me to go back and forth between JSON ASTs. Circe is however the JSON library I am most comfortable with, so I only fall back to json-schema-validator / jackson for schema specific use cases.
  • Cleaning JSON documents off null-values is treated as a json-schema-validator implementation detail.
  • The payload response may contain "message": null. Changing the behavior would require to override http4s-circe fields.

Building an running

sbt

✓ sbt
✓ Java
✗ Docker

If sbt is available, running sbt run is sufficient to build and start the app. The server will become available on http://localhost:8080/.

For a more interactive feedback loop (primarily intended for development), sbt-revolver is available via sbt reStart.

docker

✗ sbt
✗ Java
✓ Docker

Docker is primarily intended for CI purposes but can also be used to build the app when sbt is not available.

  1. Build the image, named spjv

    docker build -t spjv . 
    
  2. Start a container with the app mapped to port 8080

    docker run -it \
      -v $PWD:/root/spjv/ \
      -p 8080:8080 \
      --entrypoint /bin/bash \
      spjv \
      sbt run /path/to/storage
    
  3. Server will become available on http://localhost:8080/

Running the executable

Instead of building the app yourself, you may as well just use the executable that is generated as part of the CI process with sbt-assembly. The JAR file can be downloaded from every CI pipeline.

java -jar spjv-1.0.0.jar /path/to/storage

The storage path is optional. When omitted a temporary directory is used. Depending on your setup, that might not persist across app restarts though.

Sample

> java -jar spjv-1.0.0.jar &
> curl -d @src/test/resources/config-schema.json http://localhost:8080/schema/config-schema
> curl -d @src/test/resources/config.json http://localhost:8080/validate/config-schema
> curl -d @src/test/resources/config-invalid.json http://localhost:8080/validate/config-schema

Continuous Integration

Setting up CI for a project like this is probably out of scope and not expected. I do however believe that CI is an integral component of every software project and should never be an afterthought. This is why every project of mine relies on my sbt-houserules plugin, enabling GitLab CI setup in a matter of minutes.

The CI takes care of these tasks:

  • Run test suite
  • Generate code coverage report
  • Check that the build triggers no warning messages
  • Validate code format
  • Publish code coverage HTML report
  • Publish executable artifact

You can access the CI pipelines on the GitLab mirror.

You can’t perform that action at this time.