Code Monkey home page Code Monkey logo

distage-example's Introduction

Build Status License

distage example

Example distage project presented at Functional Scala 2019

Features distage, Bifunctor Tagless Final, ZIO Environment for composing test fixtures, and distage-docker for setting up test containers.

To launch tests that require postgres ensure you have a docker daemon running in the background.

Use sbt test to launch the tests.

You can launch the application with the following command.

./launcher -u scene:managed :leaderboard

Afterwards you can call the HTTP methods:

curl -X POST http://localhost:8080/ladder/50753a00-5e2e-4a2f-94b0-e6721b0a3cc4/100
curl -X POST http://localhost:8080/profile/50753a00-5e2e-4a2f-94b0-e6721b0a3cc4 -d '{"name": "Kai", "description": "S C A L A"}'
# check leaderboard
curl -X GET http://localhost:8080/ladder
# user profile now shows the rank in the ladder along with profile data
curl -X GET http://localhost:8080/profile/50753a00-5e2e-4a2f-94b0-e6721b0a3cc4

Note

If ./launcher command fails for you with some cryptic stack trace, there's most likely an issue with your Docker. First of all, check that you have docker and contrainerd daemons running. If you're using something else than Ubuntu, please stick to the relevant installation page:

sudo systemctl status docker
sudo systemctl status contrainerd

Both of them should have Active: active (running) status. If your problem isn't gone yet, most likely you don't have your user in docker group. Here you can find a tutorial on how to do so. Don't forget to log out of your session or restart your virtual machine before proceeding. If you still have problems, don't hesitate to open an issue.

Videos:

GraalVM Native Image

Use sbt to build a native Linux binary with GraalVM NativeImage under Docker:

sbt GraalVMNativeImage/packageBin

If you want to build the app using local native-image executable (e.g. on a Mac), comment out the graalVMNativeImageGraalVersion key in build.sbt first.

To test the native app with dummy repositories run:

./target/graalvm-native-image/leaderboard -u scene:managed -u repo:dummy :leaderboard

To test the native app with production repositories in Docker run:

./target/graalvm-native-image/leaderboard -u scene:managed -u repo:prod :leaderboard

Notes:

  • Currently, the application builds with GraalVM 22.3. Check other GraalVM images here
  • JNA libraries are just regular Java resources, currently the NI config is generated for x86-64 Linux, you'll have to re-generate or manually edit it to run on different operating systems or architectures.
  • These bugs still may manifest, but it seems like they aren't blockers anymore:
    1. oracle/graal#4797
    2. oracle/graal#4282
  • -Djna.debug_load=true key added to the native app command line might help to debug JNA-related issues
Assisted NI configuration generator

See Native Image docs for details.

Add the following to Java commandline to run the Assisted configuration agent:

-agentlib:native-image-agent=access-filter-file=./ni-filter.json,config-output-dir=./src/main/resources/META-INF/native-image/auto-wip

Notes:

  • The codepaths in docker-java are different for the cold state (when no containers are running) and the hot state. It seems like we've managed to build an exhaustive ruleset for docker-java so it's excluded in ni-filter.json. If something is wrong and you need to generate the rules for docker-java, run the agent twice in both hot and cold state.
  • Only PluginConfig.const works reliably under Native Image. So, ClassGraph analysis is disabled in ni-filter.json. You can't make dynamic plugin resolution working under Native Image.

distage-example's People

Contributors

elijahlamoon avatar neko-kai avatar pshirshov avatar scala-steward avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.