playframework - Getting started
Posted on August 14, 2024
by Mandla Mbuli
Helloworld
Just go to playframework website
Using the giter8 template sbt new…
sbt new playframework/play-scala-seed.g8
configured like
name [play-scala-seed]: playpen
organization [com.example]: me.mandla
play_version [3.0.5]:
scala_version [2.13.14]: 3.5.0
sbt_giter8_scaffold_version [0.16.2]:
Then run it with:
sbt run
Nice and easy
Get it to deploy
I use NixOS for running my services. I chose nix because I remembered Ansible being a pain to learn and not having enough Python for my liking. Nix has also been rather difficult to learn and has no Python. It has the advantage that I have more general experience now. My threshold for: “this is impossible” is much higher.
The code runs on Nix, I deploy via SSH using nixops
stateDiagram-v2 direction LR [*] --> Suifeng Suifeng --> NixOps NixOps --> Tamayo Tamayo --> [*]
Suifeng is my personal laptop Tamayo is the whatever I deploy stateless content to Kochi is whatever I deploy stateful content to
- nixops
- Make sure there is multiple ssh keys
- OCI container (specifically podman)
-containers = virtualisation.ocilet ngiyeza = import ./ngiyeza/web.nix pkgs; in { containers = { ngiyeza = { image = "ngiyeza:latest"; ports = [ "127.0.0.1:9000:9000" ]; imageFile = pkgs.dockerTools.buildImage { name = "ngiyeza"; tag = "latest"; fromImage = pkgs.dockerTools.pullImage { imageName = "eclipse-temurin"; imageDigest = "sha256:b18dabf509aeeb700d9525cdebf6bdbededb06536c6e233a3a21e6fb04d2be8c"; finalImageName = "eclipse-temurin"; finalImageTag = "21"; sha256 = "0aHcVCwAwMQdnXHGlPHtZo2rvzhnhgqhXcjJ5bTfuS0="; }; fromImageName = "eclipse-temurin"; fromImageTag = "21"; runAsRoot = '' mkdir -p /data ''; config = { Cmd = [ "${ngiyeza}/bin/ngiyeza" "-Dconfig.file=${ngiyeza}/conf/production.conf" ]; WorkingDir = "/data"; Volumes = { "/data" = { }; }; }; }; }; }; };
Get it running
Settings
"application"
include
.http.secret.key="super-secret-no-one-can-guess"
play.filters.hosts {
play= ["ngiyeza.mandla.me"]
allowed }
.server.pidfile.path=/data/RUNNING_PID play
- gitcrypt
- All protected using git-crypt cause… I am lazy. Setting up things like bitwarden seems like overkill.
- css does not go through the template engine
- fonts need to escape @
@@font-face
- for whatever reason Android doesn’t show the fonts if defined in the file anyway, so defined in a style tag
- when a URL is needed, it needs to be in the *.scala.html
...<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/ngiyeza/main.css")"> <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")"> <style> @@font-face { : "Abel"; font-family: url(@routes.Assets.versioned("stylesheets/ngiyeza/fonts/abel/Abel-Regular.ttf")); src }.abel { font-family: "Abel", sans-serif; font-weight: 400; font-style: normal; }</style> </head> <body style="background-image: url(@routes.Assets.versioned("images/bg.jpg"))"> ...
- fonts need to escape @
Conclusion
Looks pretty simple and so far, not really Scala yet. The routes thing looks cool The template engine looks cool