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

Second version of the Leios simulator #6

Merged
43 commits merged into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
46a421e
Add initial scaffolding
dnadales Jun 18, 2024
cf3f6af
Incorporate some simple logic for IB production.
dnadales Jun 18, 2024
c0d079d
Implement a simple outside world model
dnadales Jun 19, 2024
cd6bf43
Implement FFD in the outside world model
dnadales Jun 19, 2024
2aca0fb
Add the notion of node bandwidth
dnadales Jun 19, 2024
39d0e3c
Add EB production logic
dnadales Jun 23, 2024
ce69df0
Change the type of `f_I` and `f_E` to Rational
dnadales Jun 25, 2024
60c7da4
Update the next steps
dnadales Jun 25, 2024
728501b
Connect the new model to the frontend.
dnadales Jun 25, 2024
e7289fa
Incorporate some review comments.
dnadales Jun 25, 2024
5ae15cb
Add support for plotting the IB queue size.
dnadales Jun 26, 2024
17fdbcb
Use a more realistic IB schedule
dnadales Jun 30, 2024
3c5168a
Use a more realistic EB schedule.
dnadales Jun 30, 2024
2ffb137
Minor
dnadales Jun 30, 2024
950a5a0
Add a plot showing: IB created, linked IB, dropped IB x slot.
dnadales Jul 2, 2024
ea77e24
Modify the page layout
dnadales Jul 3, 2024
004e6b9
Correct the id of the `f_I` input field
dnadales Jul 6, 2024
e78277c
Set min/max ranges for the parameters input fields.
dnadales Jul 6, 2024
0058d4a
Run one simulation instance per web-socket connection
dnadales Jul 6, 2024
7f25a27
Fourmulize code
dnadales Jul 6, 2024
fdb4cc3
Try building and pushing docker image
abailly Jul 7, 2024
c1d6fb5
Fix path to leios executable in dockerfile
abailly Jul 7, 2024
2566315
Add an event listener for changing L.
dnadales Jul 9, 2024
c4ea562
Add endpoints for changing the remaining parameters
dnadales Jul 9, 2024
7645fe6
Add input fields for the remaining parameters
dnadales Jul 9, 2024
33a49b9
Connect the parameter input fields to their endpoints
dnadales Jul 9, 2024
395d406
Update UI bounds on `f_I` input field.
dnadales Jul 10, 2024
61c0dd0
Use scatter plot instead of line plot and fix references to parameter…
dnadales Jul 10, 2024
636c0ed
Remove global constants
dnadales Jul 10, 2024
b7c6253
Fix several issues
dnadales Jul 10, 2024
f8dc443
Tried deployment using AWS
abailly Jul 11, 2024
6b38538
Ci pushes to google container registry leios-docker
abailly Jul 11, 2024
b6e66b1
Allow environment variable PORT to override listening port
abailly Jul 11, 2024
4a0d0f1
Add GH action to deploy to Cloud run
abailly Jul 11, 2024
b12c9c6
Add terraform configuration for cloud run
abailly Jul 11, 2024
61d0784
Use wss:// scheme when over https
abailly Jul 11, 2024
8a036b4
Use correct URL for GET/POST
abailly Jul 11, 2024
637ca31
Fix URL construction in client and logging in server
abailly Jul 11, 2024
3819b61
Minor reformatting and linting
abailly Jul 11, 2024
c7eaa22
UI styling changes
abailly Jul 12, 2024
c027066
Added tooltips
abailly Jul 12, 2024
b507480
Serve Leios logo as favicon
abailly Jul 12, 2024
ad37549
Set UTF-8 locale in docker image
abailly Jul 12, 2024
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
131 changes: 131 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: CI
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

on:
pull_request:
push:
Expand Down Expand Up @@ -53,3 +57,130 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN || github.token }}
publish_dir: ./github-pages
cname: leios.cardano-scaling.org

build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4

# Uses the `docker/login-action` action to log in to the
# Container registry registry using the account and password
# that will publish the packages. Once published, the packages
# are scoped to the account defined here.
- name: 🛠️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: 👮 Log in to Google Cloud
id: auth
uses: 'google-github-actions/auth@v2'
with:
token_format: access_token
credentials_json: '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}'
access_token_lifetime: 3600s # need to be long enough for docker build to finish

- name: 👮 Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# This step uses
# [docker/metadata-action](https://github.com/docker/metadata-action#about)
# to extract tags and labels that will be applied to the
# specified image. The `id` "meta" allows the output of this
# step to be referenced in a subsequent step. The `images` value
# provides the base name for the tags and labels.
- name: 🛻 Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# This step uses the `docker/build-push-action` action to build
# the image, based on your repository's `Dockerfile`. If the
# build succeeds, it pushes the image to GitHub Packages. It
# uses the `context` parameter to define the build's context as
# the set of files located in the specified path. For more
# information, see
# "[Usage](https://github.com/docker/build-push-action#usage)"
# in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label
# the image with the output from the "meta" step.
- name: 🏗️ Build and push image to GHCR
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}:cache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}:cache,mode=max

- name: 👮 Login to Artifact Registry
uses: docker/login-action@v1
with:
registry: us-east1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}

- name: 📦 Push to GCR
run: |-
docker pull $image_tag
docker tag $image_tag "us-east1-docker.pkg.dev/iog-hydra/leios-docker/${{ env.IMAGE_NAME}}:$GITHUB_SHA"
docker push "us-east1-docker.pkg.dev/iog-hydra/leios-docker/${{ env.IMAGE_NAME}}:$GITHUB_SHA"
env:
image_id: ${{ steps.push.outputs.imageid }}
image_tag: ${{ steps.meta.outputs.tags }}

# This step generates an artifact attestation for the image,
# which is an unforgeable statement about where and how it was
# built. It increases supply chain security for people who
# consume the image. For more information, see
# "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

# deploy built server to Gcloud run action when pushing to main
deploy-server:
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- build-and-push-image
permissions:
contents: read
packages: read

steps:
- name: 📥 Checkout repository
uses: 'actions/checkout@v4'

- name: 👮 Log in to Google Cloud
id: auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}'

- name: 🚀 Deploy to Cloud Run
id: 'deploy'
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
service: 'leios-server'
image: 'us-east1-docker.pkg.dev/iog-hydra/leios-docker/${{ env.IMAGE_NAME}}:${{ github.sha }}'
region: 'us-east1'

- name: 🔬 'Use output'
run: 'curl -v -L "${{ steps.deploy.outputs.url }}"'
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# inspired by https://github.com/phadej/docker-haskell-example/blob/master/Dockerfile
FROM haskell:9.6.3 AS build

RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libtinfo-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libncursesw5 libtool autoconf

COPY ./cabal.project /app/cabal.project

RUN mkdir /app/leios-sim

COPY ./leios-sim/leios-sim.cabal /app/leios-sim/leios-sim.cabal

WORKDIR /app

RUN cabal update
RUN cabal build --dependencies-only all

COPY . /app

RUN cabal build all

# Make final binary a bit smaller
RUN strip dist-newstyle/build/x86_64-linux/ghc-9.6.3/leios-sim-0.1.0.0/x/leios/build/leios/leios

FROM ubuntu:22.04

# Set up locales
RUN apt-get update && \
apt-get install -y locales && \
rm -rf /var/lib/apt/lists/*
RUN locale-gen en_US.UTF-8 && \
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

WORKDIR /app
EXPOSE 8091

COPY --from=build /app/leios-sim/* /app/
COPY --from=build /app/dist-newstyle/build/x86_64-linux/ghc-9.6.3/leios-sim-0.1.0.0/x/leios/build/leios/leios /app

ENTRYPOINT ["/app/leios"]
21 changes: 21 additions & 0 deletions infra/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
backend "gcs" {
}

required_providers {
google = {
source = "hashicorp/google"
}
googlesiteverification = {
source = "hectorj/googlesiteverification"
version = "0.4.5"
}
}
}

provider "google" {
credentials = file(var.google_service_credentials_json_file)
project = local.google_project_id
region = var.google_region
zone = var.google_zone
}
62 changes: 62 additions & 0 deletions infra/cloud-run.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
resource "google_artifact_registry_repository" "leios-docker" {
location = "us-east1"
repository_id = "leios-docker"
description = "Leios docker repository"
format = "DOCKER"

docker_config {
immutable_tags = true
}
}

resource "google_artifact_registry_repository_iam_member" "member" {
project = google_artifact_registry_repository.leios-docker.project
location = google_artifact_registry_repository.leios-docker.location
repository = google_artifact_registry_repository.leios-docker.name
role = "roles/artifactregistry.admin"
member = "serviceAccount:${var.google_service_account}"
}

resource "google_cloud_run_v2_service" "leios_server" {
name = "leios-server"
location = "us-east1"
client = "terraform"

depends_on = [
google_artifact_registry_repository.leios-docker
]

template {
containers {
image = "us-east1-docker.pkg.dev/iog-hydra/leios-docker/input-output-hk/ouroboros-leios:4d411737776ef5f4b971fa634a32ed0930d6f7c9"
ports {
container_port = 8091
}
}

labels = {
"commit-sha" = "4d411737776ef5f4b971fa634a32ed0930d6f7c9"
"managed-by" = "github-actions"
}
}
}

resource "google_cloud_run_service_iam_member" "noauth" {
location = google_cloud_run_v2_service.leios_server.location
service = google_cloud_run_v2_service.leios_server.name
role = "roles/run.invoker"
member = "allUsers"
}

data "google_project" "project" {}

resource "google_cloud_run_domain_mapping" "leios_server_domain_mapping" {
name = "leios-simulation.cardano-scaling.org"
location = google_cloud_run_v2_service.leios_server.location
metadata {
namespace = data.google_project.project.project_id
}
spec {
route_name = google_cloud_run_v2_service.leios_server.name
}
}
41 changes: 41 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
variable "google_region" {
type = string
description = "The region on GCP"
default = "us-east1"
}

variable "google_zone" {
type = string
description = "The zone on GCP"
default = "us-east1-b"
}

variable "google_service_account" {
type = string
description = "The service account to use for deploying services"
}

variable "google_service_credentials_json_file" {
type = string
description = "The credentials of the GCP service account"
}

variable "terraform_backend_bucket" {
type = string
description = "The bucket to use to store terraform's state"
default = "peras_infra"
}

variable "terraform_backend_prefix" {
type = string
description = "The prefix path to store terraform's state at"
default = "terraform/peras/state"
}

locals {
google_service_credentials_json_file_decoded = jsondecode(file(var.google_service_credentials_json_file))
google_service_account_private_key = local.google_service_credentials_json_file_decoded.private_key
google_project_id = local.google_service_credentials_json_file_decoded.project_id
terraform_backend_prefix = var.terraform_backend_prefix
terraform_backend_bucket = var.terraform_backend_bucket
}
18 changes: 1 addition & 17 deletions leios-sim/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
module Main where

import Control.Concurrent.Class.MonadSTM (newTQueueIO, newTVarIO)
import Control.Monad.Class.MonadAsync (race_)
import Leios.Node (Params (..), runSimulation)
import Leios.Server (runServer)
import Leios.Trace (mkTracer)

main :: IO ()
main = do
params <- newTVarIO baseParams
events <- newTQueueIO
runSimulation (mkTracer events) params
`race_` runServer params events
where
baseParams =
Params
{ λ = 12
, capacity = 10
, seed = 42
, initialRound = 10
}
main = runServer
Binary file added leios-sim/favicon.ico
Binary file not shown.
Loading
Loading