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

Upload and parse scenarios #1798

Merged
merged 5 commits into from
Apr 25, 2024
Merged

Upload and parse scenarios #1798

merged 5 commits into from
Apr 25, 2024

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Apr 8, 2024

Towards #1797

Hosts an online repository of scenarios, against which solutions may be submitted. This is the foundational layer that may support more structured "tournaments", scenario ranking, or other social activity.

Demo

Live server

http://swarmgame.net/list-games.html

One can use the submit.sh script and see valid uploads reflected live on the website.

Local testing

Automated tests

These are database-agnostic.

scripts/run-tests.sh swarm:test:tournament-host

Manual tests

These test database interactions. It requires first setting up a local Postgres server.

  1. Start tournament/scripts/demo/server-native.sh in one console
  2. Run tournament/scripts/demo/client/test-cases/local/good-submit.sh in another

Features

  • Upload and validates scenarios
  • Download scenarios with solution redacted
  • Submit, validate, execute, and score solutions

Key components

  • Servant server
  • Hosted on AWS in a Docker container
  • Stores to a Postgres database in Amazon RDS
  • Shares some code with the integration tests for evaluating scenarios and solutions

The production database uses IAM to manage logins. The web app uses the AWS API to fetch a "token" which can be used to log in instead of a password. This avoids having to store a password on the server.

TODO

  • User authentication (GitHub OpenID?)

@kostmo kostmo force-pushed the feature/tournament-hosting branch 3 times, most recently from 321a4d1 to 3f8286d Compare April 11, 2024 05:59
@kostmo kostmo force-pushed the feature/tournament-hosting branch from 3f8286d to 6da06aa Compare April 20, 2024 05:37
@kostmo kostmo changed the title [WIP] Upload and parse scenarios Upload and parse scenarios Apr 20, 2024
@kostmo kostmo requested a review from byorgey April 20, 2024 06:13
@kostmo kostmo marked this pull request as ready for review April 20, 2024 06:14
@kostmo kostmo force-pushed the feature/tournament-hosting branch 4 times, most recently from 4720e00 to cf1baf9 Compare April 21, 2024 19:30
@kostmo kostmo changed the base branch from main to refactor/support-tournament-hosting April 21, 2024 19:36
mergify bot pushed a commit that referenced this pull request Apr 22, 2024
Prerequisite to #1798 

## Changes

* Pass the final `TickNumber` count as a member of `Won` constructor so that it can be used in scoring submitted solutions
* Extract a helper function `codeMetricsFromSyntax` that can be reused by tournament server
* `ToJSON` instance for `ScenarioMetadata`
* New script `list-sublibraries.sh` to list the sublibraries defined in a package
@kostmo kostmo changed the base branch from refactor/support-tournament-hosting to main April 22, 2024 19:09
@kostmo kostmo force-pushed the feature/tournament-hosting branch from cf1baf9 to c4c0546 Compare April 22, 2024 19:09
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing! Now I know why I hadn't heard anything from @kostmo in a while. 😉

Besides a few minor comments/questions, I think the biggest issue is that we need to configure things so that by default, doing a cabal build does not build the tournament server, so it does not need to download and build servant, postgresql-simple, etc. Most people building swarm from source will not need all this so we should save them the trouble; anyone who actually wants the server can enable a flag. I think we should be able to do this by creating a flag in the .cabal file and marking relevant libraries + executable stanzas as buildable: false conditional on the flag. Or maybe there is a better way to accomplish this with modern cabal, I'm not sure.

I did not test actually building the server myself but I was able to test uploading a solution to one of the scenarios listed on swarmgame.net.

tournament/web/favicon.ico Outdated Show resolved Hide resolved
app/tournament/Main.hs Show resolved Hide resolved
src/swarm-tournament/Swarm/Web/Tournament/Validate.hs Outdated Show resolved Hide resolved
tournament/scripts/demo/client/submit.sh Show resolved Hide resolved
@@ -429,6 +429,56 @@ library swarm-web
-- See discussion in #415
StrictData

library swarm-tournament
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replying to the toplevel review comment here, so that the discussion can be properly threaded.

I think the biggest issue is that we need to configure things so that by default, doing a cabal build does not build the tournament server, so it does not need to download and build servant, postgresql-simple, etc. Most people building swarm from source will not need all this so we should save them the trouble; anyone who actually wants the server can enable a flag. I think we should be able to do this by creating a flag in the .cabal file and marking relevant libraries + executable stanzas as buildable: false conditional on the flag. Or maybe there is a better way to accomplish this with modern cabal, I'm not sure.

Recall that the main swarm executable already includes servant, from way back in 2022.

postgresql-simple, however, is a new dependency. I think the simplest way to avoid building postgresql-simple is to pass an explicit target argument to cabal:

cabal build swarm:exe:swarm

As a convenience, we may provide a wrapper script (named build-game.sh) that makes the above invocation.

P.s. there seems to be a bug in stack that builds components/executables that are not requested on the command line. So I think our documentation should explicitly recommend cabal in any places where it doesn't already.

Copy link
Member

@byorgey byorgey Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recall that the main swarm executable already includes servant, from way back in 2022.

Ah, good point. But avoiding postgresql-simple when not necessary is especially important since it has external library dependencies. When I tried building I got an error about some thing that wasn't installed. Getting it to work would have required me to go figure out which OS package to install that would provide whatever thing was missing, and we definitely don't want to subject casual players to that kind of installation experience. But in any case, I think you're right that simply specifying a particular target like swarm:exe:swarm is the way to go, I had forgotten about that.

P.s. there seems to be a bug in stack that builds components/executables that are not requested on the command line.

Really? It works for me. e.g. when I do stack build swarm:exe:swarm it only builds the libraries needed for the main swarm executable. By contrast just doing stack build builds other stuff like swarm-scene and swarm-docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? It works for me. e.g. when I do stack build swarm:exe:swarm it only builds the libraries needed for the main swarm executable. By contrast just doing stack build builds other stuff like swarm-scene and swarm-docs.

Try the following:

  1. Add a newline to the end of src/swarm-tournament/Swarm/Web/Tournament/Validate.hs
  2. Run stack build swarm:exe:swarm
  3. Observe that it recompiles swarm-tournament, despite that library not being a dependency of the swarm executable.

Now do the same cycle, but with cabal build swarm:exe:swarm instead, and observe Up to date is printed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you're right.

I think our documentation should explicitly recommend cabal in any places where it doesn't already.

I think I'm convinced. It just means anyone who wants to build from source has to pay more attention to what version of GHC they are using. But these days with ghcup that's pretty trivial.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #1820 to track this.

@kostmo kostmo force-pushed the feature/tournament-hosting branch from 70d5e94 to ddb28f9 Compare April 25, 2024 19:57
@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Apr 25, 2024
@mergify mergify bot merged commit d749c5e into main Apr 25, 2024
9 checks passed
@mergify mergify bot deleted the feature/tournament-hosting branch April 25, 2024 20:11
mergify bot pushed a commit that referenced this pull request May 12, 2024
This is a rework of #1798 to facilitate a simpler web stack.

# Demo

View http://swarmgame.net/

NOTE: Requires IPv6

# Motivation

Hosting cost is a main motivation.  Cost per month for an EC2 instance, RDS, and the requisite other services approaches >$50 per month.  In contrast, the lowest-tier Lightsail instance is $3.50/month.

The deployment process is of course simplified.

An incidental benefit to using SQLite is reduced latency of web requests; we no longer need to fetch credentials from an AWS API to connect to Postgres.

## Changes

Major changes:
* Use `sqlite` instead of `postgres`
* Use Docker to build a statically-linked deployable binary, rather than deploying the app within a Docker image

Fortunately, the API of `sqlite-simple` is near-identical to that of `postgresql-simple`, so most of the code change there is just to rip out AWS-specific stuff and Postgres connection info.  I have no hesitation to delete this code since if we ever want to use the previous stack again, we can just look at #1798.
@byorgey byorgey added the CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. label Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants