Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

akka-cluster-typed 2.6 with jackson serialization; server docker deployment; and more #524

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
017a716
update com.typesafe:config:1.4.1 for sbt building code
giabao Aug 12, 2021
5994003
update scala-js 1.7.0
giabao Jul 29, 2021
ecbf6fc
Update sbt-native-packager 1.9.2
giabao Jul 29, 2021
29cd0b5
update sbt-assembly 1.0.0
giabao Aug 9, 2021
7f83141
update sbt-docker 1.8.2
giabao Jul 29, 2021
91cc388
remove outdated sbt-docker workarounds
giabao Jul 29, 2021
eeeb955
update sbt-revolver 0.9.1
giabao Jul 29, 2021
8196b8b
update sbt-buildinfo 0.10.0
giabao Aug 5, 2021
c2d5d35
update scalatest 3.2.9
giabao Aug 5, 2021
00ea7f0
update codemirror 5.50.0 -> 5.62.2
giabao Aug 12, 2021
d1a4b4e
update scalajs-react 1.7.6 -> 1.7.7
giabao Aug 12, 2021
6ca8f79
update akka 2.6.15 and akka-http 10.2.5
giabao Jul 29, 2021
44a06fc
update play-json 2.6.14 and 2.10.0-RC5
giabao Aug 10, 2021
52f4f0e
clean code: Fix a scalas 2.13 deprecated warnings
giabao Jul 29, 2021
044fa6f
clean code: DispatchActor.connectRunner
giabao Jul 29, 2021
d66bbb5
clean code: DispatchActor.remoteSbtSelections
giabao Aug 1, 2021
8068c72
Fix akka-http 10.2 deprecated warnings
giabao Aug 9, 2021
950de9e
sbtRunner: fix handling of output because sbt java process not output…
giabao Aug 3, 2021
df1f9b4
Fix storate/ listSnippets test case
giabao Aug 9, 2021
72182aa
Rename sbtRunner's application.conf to reference.conf
giabao Aug 9, 2021
3f9caa2
Migrate to akka-typed and use cluster instead of remote only
giabao Aug 9, 2021
2062051
Add PlayJson (de)serializer test
giabao Aug 10, 2021
acc5cff
Add a special test case for PlayJsonDeserializer
giabao Aug 10, 2021
8c204aa
Use play-json's JsValueDeserializer
giabao Aug 10, 2021
5e3dacf
Copy code from play-json's JsValueDeserializer before modifying
giabao Aug 10, 2021
ca0ac20
PlayJsonDeserializer: Don't consume all input source
giabao Aug 10, 2021
7bc8df6
logback.xml use ASYNC appender as recommended by akka
giabao Aug 12, 2021
741aedc
Add ShowConfigTest
giabao Aug 9, 2021
6fef919
sbt: Remove sbt-assembly, use adoptopenjdk and add server/docker
giabao Jul 28, 2021
e3b1329
sbt: Reimplement sbt Deployment code
giabao Jul 28, 2021
6f9d1a3
mongoUri configurable and `snippets-container` config break change
giabao Aug 16, 2021
00e3f13
ServerMain: Don't support passing port as args.head
giabao Aug 16, 2021
f40e70a
ShowConfig: Remove overridden support
giabao Aug 16, 2021
54d448d
Remove writing RUNNING_PID
giabao Aug 16, 2021
cf4b0c3
Simplify SbtProcess's params
giabao Aug 16, 2021
f93d7db
Change config web|sbt.production => embedded-url-base|remapSourceMapU…
giabao Aug 16, 2021
cff758b
sbt: dockerCompose task
giabao Aug 16, 2021
e4f4266
.gitignore
giabao Aug 16, 2021
6435fb6
Update CONTRIBUTING.md & remove unused scripts
giabao Aug 13, 2021
4cf0d9e
Remove an unused folder server/src/main/univarsal
giabao Aug 16, 2021
0e2caf7
Do not flood the console log when asking SnippetProgress
giabao Aug 17, 2021
459088c
Use vagrant to test production deployment
giabao Aug 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ bin/.coursier
bin/drone
local/
metals.sbt
.bsp/
.bsp/
/docker-compose.yml
/.vagrant
42 changes: 24 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ You are more than welcome to contribute any PR regardless if it's listed or not.

### How to install prerequisites via nix

```
```shell
curl https://nixos.org/nix/install | sh
nix-shell -A scastie
```

### How to install prerequisites on Mac
```
```shell
brew install openjdk sbt nodejs yarn
```

### How to install prerequisites on Windows

Assuming you use Git for Windows >= 2.16.2.1 (note this will erase uncommitted changes):
```
```shell
git config --add core.symlinks true
git reset --hard HEAD
```
```
```shell
choco install nvm yarn sbt jdk8 python3
nvm install 8.9.1
nvm use 8.9.1
Expand Down Expand Up @@ -107,7 +107,7 @@ If you have any questions join us in the [gitter channel](https://gitter.im/scal

## Quick

```
```shell
ssh scastie@alaska.epfl.ch
ssh scastie@scastie.scala-lang.org
ssh scastie@scastie-sbt.scala-lang.org
Expand All @@ -122,10 +122,10 @@ deploy
```

## Check logs
```
```shell
ssh scastie@alaska.epfl.ch
ssh scastie@scastie.scala-lang.org
tail -F -n1000 output.log
docker logs -f scastie-server
ssh scastie@scastie-sbt.scala-lang.org
~/log.sh
```
Expand Down Expand Up @@ -162,7 +162,7 @@ These people have access:

In case anything goes wrong:

```
```shell
ssh scastie@alaska.epfl.ch
ssh scastie@scastie.scala-lang.org
ssh scastie@scastie-sbt.scala-lang.org
Expand All @@ -171,18 +171,24 @@ exit
./server.sh
```

# Running with docker locally
# Run/test `deploy` task on development machine using vagrant & virtualbox
See guide in [Vagrantfile]

# Running with docker locally
There are 2 options:
1. Using [docker-compose](https://docs.docker.com/compose/install/)
```shell
sbt dockerCompose
```
git commit

sbt "sbtRunner/docker"
`dockerCompose` task will build scastie docker images and create `docker-compose.yml`
and run `docker-compose down;docker-compose up`.
See `dockerCompose` alias defined in `build.sbt` for more info.

docker run \
--network=host \
-e RUNNER_PORT=5150 \
-e RUNNER_HOSTNAME=127.0.0.1 \
-e RUNNER_RECONNECT=false \
-e RUNNER_PRODUCTION=true \
scalacenter/scastie-sbt-runner:`git rev-parse --verify HEAD`
2. Let `sbt` run `docker` commands directly instead of using `docker-compose`
```shell
sbt deployLocal
```
`deployLocal` task will build scastie docker images and deploy deployment files into `local` folder
and run the `*.sh` file in that folder.
See `deployLocal` alias defined in `build.sbt` for more info.
127 changes: 127 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# This `Vagrantfile` is used to test/run sbt deploy task on development machine
# using deployment/production.conf to ensure everything is ok before deploying to production env.
# Steps:
# 0. Install vagrant and virtualbox
# 1. `vagrant up` in this `scastie` directory to create & start 2 ubuntu VMs
# which will be used to run sbt-runners and server (and mongodb)
# 2. You should (optional) use static LAN IP. In this guide, we use `192.168.86.147`
# 3. Run [docker registry](https://docs.docker.com/registry/) locally
# `docker run -d -p 5000:5000 --name registry registry:2`
# 4. Add `"insecure-registries": ["192.168.86.147:5000"]` into your
# [docker daemon config](https://docs.docker.com/config/daemon/#configure-the-docker-daemon)
# Then restart your docker daemon
# 5. Change `ImageName` in `docker / imageNames` in project/DockerHelper.scala, add:
# registry = Some("192.168.86.147:5000")
# 6. Add to your ~/.ssh/config:
# Host scastie-sbt.scala-lang.org
# HostName 192.168.33.10
# User scastie
# IdentityFile ~/.vagrant.d/insecure_private_key
# CheckHostIP no
# StrictHostKeyChecking no
# PasswordAuthentication no
# IdentitiesOnly yes
# UserKnownHostsFile /dev/null
# Host scastie.scala-lang.org
# HostName 192.168.33.12
# ... same as above
#
# Note: 192.168.33.10, 192.168.33.12 are IPs of `runner`, `server` VMs as defined bellow.
#
# 7. Confirm that you can ssh to the VMs (and not the actual production servers):
# ```
# ssh scastie.scala-lang.org 'ip -4 -brief addr | grep 192.168'
# ssh scastie-sbt.scala-lang.org 'ip -4 -brief addr | grep 192.168'
# ```
# The output must not empty and contains `192.168.33.10`, `192.168.33.12`
#
# 8. Change deployment/production.conf: sbt-runners.ports-size = 2
# 9. If you don't have access to `github.com/scalacenter/scastie-secrets`:
# Change `secretsFile` to `SecretsFile.local(..)` in
# deployRunnersQuick, deployServerQuick taskDefs in project/Deployment.scala
# 10. Run `sbt deploy` to deploy scastie to VMs
# To speedup the redeployment process, you can see:
# + The `deploy` command alias defined in build.sbt
# + The comment about `addInstructions` in project/DockerHelper.runnerDockerfile
# 11. You should revert step 6, 8 after done testing/ deploying with vagrant
#
Vagrant.configure("2") do |config|
# config.ssh.username = "scastie"
config.vm.box = "ubuntu/focal64"

# disable box_check_update and synced_folder to speed up
config.vm.box_check_update = false
config.vm.synced_folder ".", "/vagrant", disabled: true
config.ssh.insert_key = false

config.vm.provision "shell", inline: <<-SHELL
# Install docker
apt-get update
apt-get install -y apt-transport-https curl
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io

# Add user `scastie` with group `scastie` and supplementary groups `docker`
groupadd -g 433 scastie
useradd scastie --uid 433 --gid 433 --create-home --shell /bin/bash --groups docker

# Setup ssh and sudo for user `scastie`
cp -pr /home/vagrant/.ssh /home/scastie/
chown -R scastie:scastie /home/scastie/.ssh
echo "%scastie ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/scastie

# add my own registry
echo '{ "insecure-registries": ["192.168.86.147:5000"] }' > /etc/docker/daemon.json
service docker restart

echo "192.168.33.10 scastie-sbt.scala-lang.org" >> /etc/hosts
echo "192.168.33.12 scastie.scala-lang.org" >> /etc/hosts
SHELL

config.vm.define "runner" do |c|
c.vm.network "private_network", ip: "192.168.33.10"
c.vm.hostname = "runner"
c.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.memory = "2560"
end
end

config.vm.define "server" do |c|
c.vm.network "private_network", ip: "192.168.33.12"
c.vm.hostname = "server"
c.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.memory = "2560"
end

# upload to /home/vagrant/.ssh/
c.vm.provision "file",
source: "~/.vagrant.d/insecure_private_key",
destination: "~/.ssh/insecure_private_key"

c.vm.provision "shell", inline: <<-SHELL
# config ssh so scastie on server can ssh runner
echo "Host scastie-sbt.scala-lang.org
IdentityFile ~/.ssh/insecure_private_key
CheckHostIP no
StrictHostKeyChecking no
PasswordAuthentication no
IdentitiesOnly yes
UserKnownHostsFile /dev/null" > /home/scastie/.ssh/config
chmod 600 /home/scastie/.ssh/config

install -m 600 \
/home/vagrant/.ssh/insecure_private_key \
/home/scastie/.ssh/insecure_private_key
chown -R scastie:scastie /home/scastie/.ssh

# run mongodb on `server`
docker run -d --restart=always --name mongo --network=host -v /opt/mongo_data:/data/db mongo
SHELL
end
end
6 changes: 0 additions & 6 deletions api/src/main/scala/com.olegych.scastie.api/ApiModels.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ package com.olegych.scastie.api

import play.api.libs.json._

case object SbtPing
case object SbtPong

case class SbtRunnerConnect(hostname: String, port: Int)
case object ActorConnected

object SnippetSummary {
implicit val formatSnippetSummary: OFormat[SnippetSummary] =
Json.format[SnippetSummary]
Expand Down
12 changes: 11 additions & 1 deletion api/src/main/scala/com.olegych.scastie.api/SnippetProgress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ object SnippetProgress {
implicit val formatSnippetProgress: OFormat[SnippetProgress] = Json.format[SnippetProgress]
}

// note: ProgressActor.Message alias to this
trait ProgressMessage

case class SnippetProgress(
ts: Option[Long],
id: Option[Long],
Expand All @@ -39,8 +42,15 @@ case class SnippetProgress(
isTimeout: Boolean,
isSbtError: Boolean,
isForcedProgramMode: Boolean
) {
) extends ProgressMessage {
def isFailure: Boolean = isTimeout || isSbtError || runtimeError.nonEmpty || compilationInfos.exists(_.severity == Error)

override def toString: String = Json.toJsObject(this).toString()

def logMsg: String = Json.toJsObject(
copy(
scalaJsContent = this.scalaJsContent.map(_ => "..."),
scalaJsSourceMapContent = this.scalaJsSourceMapContent.map(_ => "...")
)
).toString()
}
24 changes: 16 additions & 8 deletions balancer/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
com.olegych.scastie {
# default parent dir of:
# + snippets-container.{snippets-dir, old-snippets-dir, type = files}
# + web.oauth2.{users-file, sessions-file}
data-dir = ./target
data-dir = ${?DATA_DIR}
}
com.olegych.scastie.balancer {
snippets-container = files
snippets-dir = ./target/snippets/
old-snippets-dir = ./target/old-snippets/

remote-hostname = "127.0.0.1"
remote-sbt-ports-start = 5150
remote-sbt-ports-size = 1
snippets-container {
type = files
snippets-dir = ${com.olegych.scastie.data-dir}/snippets/
old-snippets-dir = ${com.olegych.scastie.data-dir}/old-snippets/
}
}

akka.actor.warn-about-java-serializer-usage = false
akka {
actor.provider = cluster
cluster.downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider"
}
Loading