-
Notifications
You must be signed in to change notification settings - Fork 5
Running saturn locally #920
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
Open
nour-massri
wants to merge
8
commits into
main
Choose a base branch
from
running-saturn-locally
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e46cac0
adding onSaturn command line argument and passing it down to java and…
nour-massri 0df3d1d
adding local file management in google cloud storage file
nour-massri 94e71b2
modifying readSecret to read from a local secret file if locally
nour-massri e64ee81
fixing local gcs
nour-massri 2f8c1cb
allowing local report
nour-massri 2dfc80c
adding development pub/sub image with pubsub client to send messages …
nour-massri 4832f07
adding saturn readme
nour-massri f5d6f23
fixed bash with rlwrap in dockerfile
nour-massri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,6 @@ | |
|
|
||
| # Go workspace file | ||
| go.work | ||
|
|
||
| # Secret file for local dev | ||
| *secret.* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| # Saturn: | ||
|
|
||
|
|
||
|
|
||
| Saturn is a compute cluster designed to efficiently compile competitor bots and execute matches. This system is optimized for rapid job processing and seamless scalability, leveraging Google Cloud's infrastructure for dynamic resource allocation. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## **Core Functionalities** | ||
|
|
||
|
|
||
|
|
||
| Saturn specializes in two primary operations: | ||
|
|
||
|
|
||
|
|
||
| 1. **Compilation of Source Code** | ||
|
|
||
| Converts submitted source code into executable binaries. | ||
|
|
||
| 2. **Match Execution** | ||
|
|
||
| Executes matches between compiled binaries and generates replay file results. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## **Data Flow** | ||
|
|
||
|
|
||
|
|
||
| 1. **Job Requests** | ||
|
|
||
| Received through dedicated Pub/Sub topics. | ||
|
|
||
| 2. **Processing** | ||
|
|
||
| Saturn uses the appropriate pipeline for job execution: compilation or match processing. | ||
|
|
||
| 3. **Code and Engine Retrieval** | ||
|
|
||
| Pulls the scaffold and game engine from GitHub using a Git token stored in Google Secret Manager. | ||
|
|
||
| 4. **Result Storage** | ||
|
|
||
| Results and artifacts are stored in Google Cloud Storage. | ||
|
|
||
| 5. **Report Delivery** | ||
|
|
||
| Result reports are sent back to Siarnaq via HTTP POST. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| # **Local Development Guide for Saturn** | ||
|
|
||
|
|
||
|
|
||
| ## **Overview** | ||
|
|
||
|
|
||
|
|
||
| Simulating Saturn’s distributed system locally can be challenging. To facilitate this, a Docker image with a Pub/Sub emulator is provided in the `development` folder. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## **Development Environment Setup** | ||
|
|
||
|
|
||
|
|
||
| ### **Prerequisites** | ||
|
|
||
|
|
||
|
|
||
| - Docker installed on your local machine | ||
|
|
||
| - Access to Google Secret Manager | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ### **Steps** | ||
|
|
||
|
|
||
|
|
||
| #### 1. Prepare Secret File | ||
|
|
||
| - Access our Google Cloud's Project Secret Manager. | ||
| - Copy the Git token from our production-saturn secret | ||
| - Create a `secret.json` file in the `development` directory containing the required Git token. | ||
|
|
||
|
|
||
|
|
||
| #### 2. Build Docker Image | ||
|
|
||
| Navigate to the `development` directory and run: | ||
|
|
||
| ```bash | ||
|
|
||
| cd development | ||
| docker build -t pubsub-emulator . | ||
nour-massri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
|
|
||
| ## **Running the System** | ||
|
|
||
|
|
||
|
|
||
| Two processes must run simultaneously: | ||
|
|
||
|
|
||
|
|
||
| ### **1. Start Pub/Sub Emulator** | ||
|
|
||
|
|
||
|
|
||
| In the `development` directory, execute: | ||
|
|
||
| ```bash | ||
|
|
||
| docker run -it --rm --network host \ | ||
| -v $(pwd):/development \ | ||
| pubsub-emulator | ||
|
|
||
| ``` | ||
|
|
||
| ### **2. Build and Run Modified Saturn | ||
|
|
||
| In the `saturn` directory: | ||
|
|
||
| Build Saturn Image: | ||
|
|
||
| ```bash | ||
|
|
||
| docker build -t saturn . | ||
|
|
||
| ``` | ||
|
|
||
| Run Saturn Container: | ||
|
|
||
| ```bash | ||
|
|
||
| docker run --network host \ | ||
| -e PUBSUB_EMULATOR_HOST=localhost:8514 \ | ||
| -v $(pwd)/development:/development \ | ||
| saturn -subscription=test -project=mitbattlecode -onsaturn=false \ | ||
| -secret="/development/secret.json" | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## **Interacting with the System** | ||
|
|
||
| When the system starts, the `pubsub-emulator` image runs the `./startpubsub.sh` script, which performs the following tasks: | ||
| 1. Starts the Pub/Sub emulator, listening on port `8514`. | ||
| 2. Creates a topic called `testing-saturn`. | ||
| 3. Creates a subscription called `test` (used to pull messages). | ||
|
|
||
| --- | ||
|
|
||
| ### **Sending Messages to Pub/Sub** | ||
|
|
||
| The Pub/Sub process listens for commands. Execute `./pubsubclient` tool to view the full list of available commands. | ||
| Here are two quick and commonly used commands: | ||
|
|
||
| - **`./pubsubclient pub compile`**: Sends the message defined in `compile.json`. | ||
| - **`./pubsubclient pub execute`**: Sends the message defined in `execute.json`. | ||
|
|
||
|
|
||
| ### **Configuring Messages** | ||
|
|
||
|
|
||
|
|
||
| - Modify the `compile.json` or `execute.json`files to specify different languages and different file paths for source code, binaries and report-url. | ||
|
|
||
| - Set the report path for local storage. | ||
|
|
||
| - Use `/development/<file>` paths in both images for seamless synchronization. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## **File Management** | ||
|
|
||
|
|
||
|
|
||
| - The `development` directory is mounted as `/development` in both images. | ||
|
|
||
| - Any changes made to the `development` directory are automatically reflected in the images. | ||
|
|
||
| - You can create or modify JSON files for the Pub/Sub emulator and add source code for Saturn without rebuilding the Docker images. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## **Security Note** | ||
|
|
||
|
|
||
|
|
||
| Files matching `*secret.*` are included in `.gitignore` to prevent sensitive information from being accidentally committed. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## **Example JSON Files** | ||
|
|
||
|
|
||
|
|
||
| Refer to the `compile.json` and `execute.json` files for examples of messages sent through Pub/Sub. Adjust these files as necessary for testing and development. Don't commit any changes to these files. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Use an official Golang image as a parent image | ||
| FROM golang:1.23 | ||
|
|
||
| # Install Google Cloud SDK | ||
| RUN apt-get update && apt-get install -y curl gnupg rlwrap && \ | ||
| echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ | ||
| curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \ | ||
| apt-get update && apt-get install -y google-cloud-sdk google-cloud-sdk-pubsub-emulator | ||
|
|
||
| # Install Pub/Sub emulator | ||
| RUN apt-get install google-cloud-cli-pubsub-emulator | ||
|
|
||
| # Copy the start script | ||
| COPY startpubsub.sh /usr/local/bin/startpubsub.sh | ||
| RUN chmod +x /usr/local/bin/startpubsub.sh | ||
|
|
||
| # Set the working directory | ||
| WORKDIR /app | ||
|
|
||
| # Copy the Go application code | ||
| COPY . /app | ||
| RUN go mod download | ||
| RUN go build -o pubsubclient pubsubclient.go | ||
| # Expose the Pub/Sub emulator port | ||
| EXPOSE 8514 | ||
|
|
||
| # Run the entry point script | ||
| ENTRYPOINT ["rlwrap", "bash", "/usr/local/bin/startpubsub.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "episode": { | ||
| "name": "bc25python", | ||
| "language": "py3", | ||
| "scaffold": "https://github.com/battlecode/battlecode25-scaffold" | ||
| }, | ||
| "metadata": { | ||
| "report-url": "/development/test/report.txt", | ||
| "task-type": "compile" | ||
| }, | ||
| "details": { | ||
| "source": { | ||
| "bucket": "local", | ||
| "name": "/development/test/python.zip" | ||
| }, | ||
| "binary": { | ||
| "bucket": "local", | ||
| "name": "/development/test/binary.zip" | ||
| }, | ||
| "team-name": "test", | ||
| "package": "examplefuncsplayer" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| { | ||
| "episode": { | ||
| "name": "bc25java", | ||
| "language": "java21", | ||
| "scaffold": "https://github.com/battlecode/battlecode25-scaffold" | ||
| }, | ||
| "metadata": { | ||
| "report-url": "/development/test/report.txt", | ||
| "task-type": "execute" | ||
| }, | ||
| "details": { | ||
| "maps": [ | ||
| "fix", | ||
| "galaxy", | ||
| "gridworld", | ||
| "quack", | ||
| "sierpinski" | ||
| ], | ||
| "replay": { | ||
| "bucket": "local", | ||
| "name": "/development/test/replay.bc25java" | ||
| }, | ||
| "alternate-order": true, | ||
| "a": { | ||
| "source": { | ||
| "bucket": "local", | ||
| "name": "/development/test/source1.zip" | ||
| }, | ||
| "binary": { | ||
| "bucket": "local", | ||
| "name": "/development/test/binary1.zip" | ||
| }, | ||
| "team-name": "test1", | ||
| "package": "examplefuncsplayer" | ||
| }, | ||
| "b": { | ||
| "source": { | ||
| "bucket": "local", | ||
| "name": "/development/test/source2.zip" | ||
| }, | ||
| "binary": { | ||
| "bucket": "local", | ||
| "name": "/development/test/binary2.zip" | ||
| }, | ||
| "team-name": "test2", | ||
| "package": "examplefuncsplayer" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.