|
| 1 | +# Saturn: |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## **Core Functionalities** |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +Saturn specializes in two primary operations: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +1. **Compilation of Source Code** |
| 22 | + |
| 23 | +Converts submitted source code into executable binaries. |
| 24 | + |
| 25 | +2. **Match Execution** |
| 26 | + |
| 27 | +Executes matches between compiled binaries and generates replay file results. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +## **Data Flow** |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +1. **Job Requests** |
| 40 | + |
| 41 | +Received through dedicated Pub/Sub topics. |
| 42 | + |
| 43 | +2. **Processing** |
| 44 | + |
| 45 | +Saturn uses the appropriate pipeline for job execution: compilation or match processing. |
| 46 | + |
| 47 | +3. **Code and Engine Retrieval** |
| 48 | + |
| 49 | +Pulls the scaffold and game engine from GitHub using a Git token stored in Google Secret Manager. |
| 50 | + |
| 51 | +4. **Result Storage** |
| 52 | + |
| 53 | +Results and artifacts are stored in Google Cloud Storage. |
| 54 | + |
| 55 | +5. **Report Delivery** |
| 56 | + |
| 57 | +Result reports are sent back to Siarnaq via HTTP POST. |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +# **Local Development Guide for Saturn** |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +## **Overview** |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +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. |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +## **Development Environment Setup** |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +### **Prerequisites** |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +- Docker installed on your local machine |
| 90 | + |
| 91 | +- Access to Google Secret Manager |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +### **Steps** |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +#### 1. Prepare Secret File |
| 104 | + |
| 105 | +- Access Google Secret Manager. |
| 106 | + |
| 107 | +- Create a `secret.json` file in the `development` directory containing the required Git token. |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +#### 2. Build Docker Image |
| 112 | + |
| 113 | +Navigate to the `development` directory and run: |
| 114 | + |
| 115 | +```bash |
| 116 | + |
| 117 | +cd development |
| 118 | + |
| 119 | +docker build -t pubsub-emulator . |
| 120 | + |
| 121 | +``` |
| 122 | + |
| 123 | +## **Running the System** |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +Two processes must run simultaneously: |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +### **1. Start Pub/Sub Emulator** |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +In the `development` directory, execute: |
| 136 | + |
| 137 | +```bash |
| 138 | + |
| 139 | +docker run -it --rm --network host \ |
| 140 | + |
| 141 | +-v $(pwd):/development \ |
| 142 | + |
| 143 | +pubsub-emulator |
| 144 | + |
| 145 | +``` |
| 146 | + |
| 147 | +### **2. Build and Run Modified Saturn |
| 148 | + |
| 149 | +In the `saturn` directory: |
| 150 | + |
| 151 | +Build Saturn Image: |
| 152 | + |
| 153 | +```bash |
| 154 | + |
| 155 | +docker build -t saturn . |
| 156 | + |
| 157 | +``` |
| 158 | + |
| 159 | +Run Saturn Container: |
| 160 | + |
| 161 | +```bash |
| 162 | + |
| 163 | +docker run --network host \ |
| 164 | + |
| 165 | +-e PUBSUB_EMULATOR_HOST=localhost:8514 \ |
| 166 | + |
| 167 | +-v $(pwd)/development:/development \ |
| 168 | + |
| 169 | +saturn -subscription=test -project=mitbattlecode -onsaturn=false \ |
| 170 | + |
| 171 | +-secret="/development/secret.json" |
| 172 | + |
| 173 | +``` |
| 174 | + |
| 175 | + |
| 176 | +## **Interacting with the System** |
| 177 | + |
| 178 | +When the system starts, the `pubsub-emulator` image runs the `./startpubsub.sh` script, which performs the following tasks: |
| 179 | +1. Starts the Pub/Sub emulator, listening on port `8514`. |
| 180 | +2. Creates a topic called `testing-saturn`. |
| 181 | +3. Creates a subscription called `test` (used to pull messages). |
| 182 | + |
| 183 | +--- |
| 184 | + |
| 185 | +### **Sending Messages to Pub/Sub** |
| 186 | + |
| 187 | +The Pub/Sub process listens for commands. Execute `./pubsubclient` tool to view the full list of available commands. |
| 188 | +Here are two quick and commonly used commands: |
| 189 | + |
| 190 | +- **`./pubsubclient pub compile`**: Sends the message defined in `compile.json`. |
| 191 | +- **`./pubsubclient pub execute`**: Sends the message defined in `execute.json`. |
| 192 | + |
| 193 | + |
| 194 | +### **Configuring Messages** |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | +- Modify the `compile.json` or `execute.json`files to specify different languages and different file paths for source code, binaries and report-url. |
| 199 | + |
| 200 | +- Set the report path for local storage. |
| 201 | + |
| 202 | +- Use `/development/<file>` paths in both images for seamless synchronization. |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | +--- |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +## **File Management** |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | +- The `development` directory is mounted as `/development` in both images. |
| 215 | + |
| 216 | +- Any changes made to the `development` directory are automatically reflected in the images. |
| 217 | + |
| 218 | +- You can create or modify JSON files for the Pub/Sub emulator and add source code for Saturn without rebuilding the Docker images. |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | +--- |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | +## **Security Note** |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | +Files matching `*secret.*` are included in `.gitignore` to prevent sensitive information from being accidentally committed. |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | +--- |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | +## **Example JSON Files** |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | +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. |
0 commit comments