# Clone the project by running git clone.
$ git clone <REPO_LINK>
# Install the node dependencies by running
$ npm install
# Create a .env file based on .env.example
$ cp .env.example .env
# Start the React App on localhost:3000
$ npm start
For some basic source code explanation see the wiki page
-
The CyberSim Game comprises two distinct applications: a Node.js-based backend API and a React-based frontend UI. This guide specifically covers the deployment process for the UI React application. For instructions on deploying the backend application, please refer to the CyberSim-Backend README.
-
Main deployment steps in order:
- Set up the S3 bucket for static website hosting
- Set up the CodePipeline
- During setting up the "Build" stage set up the CodeBuild project if it doesn't already exists
The environment component name follows this format: <ACCOUNT_ALIAS>@<COMPONENT_NAME>
.
All local repository changes are pushed to new branches in the GitHub remote repository. These changes are reviewed and merged into the 'master' branch.
A separate CodePipeline project is created for each production environment. The pipeline consists of 3 stages:
- Set the Source provider to "GitHub (Version 2)" and connect to the following repository: nditech/CyberSim-UI. Branch name should be
master
. - Keep the Start the pipeline on source code change option checked to trigger automatic builds on AWS whenever changes are pushed to the
master
branch. (Troubleshooting: Manually trigger a release in CodePipeline) - Leave the Output artifact format on the default "CodePipeline default".
- Set the Build provider to "AWS CodeBuild".
- Select the "CyberSim-Codebuild" build project or create it if it doesn't already exists.
- Add
REACT_APP_API_URL
environment variable here and set its value to the live URL of the corresponding backend API as plaintext. (e.g.: https://cybersimbackend.demcloud.org) - Leave the Build type on "Single build".
- Set the Deploy provider to "Amazon S3".
- Select the bucket you have set up in the first step for static website hosting.. Each environment has its own separate bucket.
- Set Extract file before deploy to "true".
- No Deployment path or additional configurations are needed.
A single CodeBuild project is created to build changes for each environment. After a change is triggered in CodePipeline (manually or automatically), the source code is transferred to CodeBuild, and the steps defined in the buildspec.yml
file are executed. These steps include the installation of Node, npm packages, and the bundling of the React app into static files. Once the build is completed, CodePipeline initiates deployment by transferring the output files in the build directory to S3.
To create the CodeBuild project please follow these steps:
- Leave the Restrict number of concurrent builds this project can start unchecked.
- For Environment settings:
- Use a "Managed image". Please refer to the buildspec.yml file to check the Node version the build uses (currently Node 18) and set up the build image accordingly (recommended:
aws/codebuild/amazonlinux2-x86_64-standard:5.0
). For more information about compatible runtimes, check this table. - Image version should be the latest.
- Recommended Environment type is "Linux EC2" without privileges and no additional settings needed. For more information please refer to this table.
- Leave the Build specification on "Use a buildspec file".
- No batch configuration is needed.
Frequent errors:
npm ci
can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file withnpm install
before continuing.`
Troubleshooting:
- Please check the error log for the specific Node version the build environment uses. (e.g. v18.6.0).
- On your local environment please install the exact same version of node with
nvm install vX.X.X
. After the installation check the currently used version with thenode -v
command. If it doesn't match the just installed version run the following command:nvm use vX.X.X
. - Delete the
package-lock.json
file. - Run
npm install
⚠️ twice⚠️ ! - Push the updated
package-lock.json
and rerun the CodeBuild.
S3 (e.g., [email protected])
A different S3 bucket is created for each environment. Public access is enabled on these buckets, which are configured for static website hosting.
To create a new bucket for static website hosting, follow these steps:
- Set the ACLs to disabled (default).
- Set "Block all public access" (and all its sub-settings) to "false" (Note: Don't forget to acknowledge this setting).
- Disable versioning.
- Encryption type: SSE-S3, disabled bucket key.
After creating the bucket:
- Under the bucket's "Properties" tab, enable static website hosting. The index document should be
index.html
. - Under the bucket's "Permissions" tab, add the following bucket policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/*"
}
]
}
The application relies on a PostgreSQL database, but the initial data is sourced from an Airtable base. If you wish to customize the data for a new game, including events, locations, actions, and more, you can achieve this by modifying the data within the Airtable base.
Before running a new game with modified data, it is essential to perform a "migration" from Airtable to the PostgreSQL database. Follow the step-by-step guide below to complete the migration process:
-
Master Password
- Remember to set the
MIGRATION_PASSWORD
environment variable in the backend application to access the master password needed for the migration process.
- Remember to set the
-
Access Airtable
- Visit https://airtable.com and log in to your Airtable account.
-
Navigate to Developer Hub
- From the Airtable menu, navigate to the "Developer Hub."
-
Generate a Personal Access Token
- Create a new "Personal access token" within the Developer Hub.
-
Retrieve Airtable Base ID
- Go to the Airtable base you wish to migrate from and copy the BASE_ID segment from the page URL. It should look something like this: "https://airtable.com/BASE_ID/TABLE_ID/ETC...".
- Paste the copied BASE_ID into the "Airtable base id" input field on the migration form.
-
Initiate the Migration
- After filling in the relevant Airtable details, click the "Migrate the database" button.
By following these steps, you can successfully migrate data from Airtable to the PostgreSQL database, ensuring that your new game incorporates the customized data you have prepared.
-
@babel include warning message:
-
One of your dependencies, babel-preset-react-app, is importing the "@babel/plugin-proposal-private-property-in-object" package without declaring it in its dependencies. This is currently working because "@babel/plugin-proposal-private-property-in-object" is already in your node_modules folder for unrelated reasons, but it may break at any time.
babel-preset-react-app is part of the create-react-app project, which is not maintianed anymore. It is thus unlikely that this bug will ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to your devDependencies to work around this error. This will make this message go away.
-
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
In the game, mitigations are organized into groups according to their category. You can customize the order of these mitigations using the following steps:
- Access the "purchase_mitigations" table.
- In the toolbar, click on the "Group" option, and then select the "category" field. Airtable will automatically reorganize the mitigations, grouping them just as they appear in the application.
- Within each category, you can rearrange the mitigations according to your preferences using the drag-and-drop feature. The order you set here will reflect how they appear in the actual game.
Currently, the game exclusively accommodates exactly two locations. You have the flexibility to name these locations as you desire within the "locations" table.
Changing the names of the locations in this section will solely impact how they are displayed in the header menu, tabs, and action titles. Role names (e.g., "HQ IT Team") remain distinct and should be configured separately within the ROLES table.
You have the ability to modify the terminology associated with "polls" in this section. For instance, you can replace "poll" or "budget" with alternative words. To introduce a new synonym, simply edit the synonym column as needed.