feat: update document and remove some debug logging

This commit is contained in:
Justin Lin committed 2024-10-14 18:32:02 +08:00
1 parent 58354b7cd8
commit 91ebaec22c
4 files changed
+33 -7

No files matched your search

+31 -3
View File
@@ -11,7 +11,6 @@
## Known Issues ## Known Issues
- The player's terminal doesn't work correctly on Mac OS and Windows for now. Please use Linux or Virtual Machines. You can track [this issue](https://github.com/linux-odyssey/linux-odyssey/issues/165) for updates.
- MongoDB requires x86 architecture to run for v5+ versions. You can track [this issue](https://github.com/linux-odyssey/linux-odyssey/issues/166) for updates. - MongoDB requires x86 architecture to run for v5+ versions. You can track [this issue](https://github.com/linux-odyssey/linux-odyssey/issues/166) for updates.
## Installation ## Installation
@@ -34,6 +33,16 @@
6. **utils**: other utility code shared between packages 6. **utils**: other utility code shared between packages
7. **game (in the future)**: core logic of game playing, will be extracted from server 7. **game (in the future)**: core logic of game playing, will be extracted from server
## Configuration
The configuration is stored in the `.env` file. You can copy from the sample file.
cp .env.sample .env
The backend will use a SSH key pair to login to the player's container. The private key is on the host, and the public key is copied to the player's container.
The key pair is stored in `./config/ssh_key` and `./config/ssh_key.pub`. If it doesn't exist, the backend will generate a new pair and store them.
## Docker Setup ## Docker Setup
### Docker compose files explaination ### Docker compose files explaination
@@ -62,10 +71,13 @@ Building quest images:
### Build Quest Images in Details ### Build Quest Images in Details
In each quest folder, there is a `game.yml` file, which is the quest definition. And a optional `Dockerfile` can overwrite the base image. If you want to include additional files, put them in a `home` folder. The files in `home` will **not** be copied to the image automatically, you have to copy them in the `Dockerfile`. In each quest folder, there is a `game.yml` file, which is the quest definition.
If you want to include additional files, put them in a `home` folder. The files in `home` will be copied to the user's home on container creation automatically.
quests/ quests/
├── Dockerfile # Base image ├── Dockerfile # Base image
├── entrypoint.sh # Entrypoint for the container
├── discover ├── discover
│ └── game.yml │ └── game.yml
├── helloworld ├── helloworld
@@ -81,17 +93,22 @@ In each quest folder, there is a `game.yml` file, which is the quest definition.
└── home └── home
└── ancient_scroll.txt └── ancient_scroll.txt
An optional `Dockerfile` can overwrite the base image. You can use this to install additional dependencies or modify the environment.
Customized `entrypoint.sh` for each quest is not yet supported.
To build all quests: To build all quests:
yarn build:quests yarn build:quests
The base image is built with docker-compose, so you can use `docker compose build base` to rebuild it. Once you rebuild the base image, you have to rebuild all quests. The base image is built with docker-compose, so you can use `docker compose build base` to rebuild it. Once you rebuild the base image, you have to rebuild all quests.
### Mounting Host Directory ### Optional: Mounting Host Directory
To improve the development experience, we can mount the host directory to the container in the pattern: To improve the development experience, we can mount the host directory to the container in the pattern:
/path/to/linux-odyssey/quests/${quest_id}/home:/home/commander /path/to/linux-odyssey/quests/${quest_id}/home:/home/commander
/path/to/linux-odyssey/packages/container:/usr/local/lib/container
You can edit the files on your host, and the changes will be reflected in the container. This is disabled by default. To enable it, you can set the following environment variables: You can edit the files on your host, and the changes will be reflected in the container. This is disabled by default. To enable it, you can set the following environment variables:
@@ -121,6 +138,10 @@ The default username and password is `alex` and `Alex1234`.
## Testing ## Testing
Unit tests:
yarn test:unit
Run Cypress locally, using the current development containers: Run Cypress locally, using the current development containers:
docker compose up -d docker compose up -d
@@ -145,7 +166,14 @@ Run Cypress in container, create brand-new containers along with it:
# Server side # Server side
docker compose -f docker-compose.prod.yml pull docker compose -f docker-compose.prod.yml pull
yarn build:quests
docker compose -f docker-compose.prod.yml up -d docker compose -f docker-compose.prod.yml up -d
### Necessary Configuration
To enable social login, you should have OAuth client token in a `.env` file: To enable social login, you should have OAuth client token in a `.env` file:
You can copy from `.env.sample` You can copy from `.env.sample`
**YOU MUST CHANGE THE SECRET_KEY** in `.env` file.
SECRET_KEY=your-secret-key
+1
View File
@@ -29,6 +29,7 @@ services:
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
- ./logs:/app/logs - ./logs:/app/logs
- ./config:/app/config
env_file: env_file:
- .env - .env
environment: environment:
+1 -1
View File
@@ -80,7 +80,7 @@ async function connectContainer(socket: Socket, next: (err?: Error) => void) {
next() next()
} catch (err) { } catch (err) {
logger.error(err) logger.error(err)
next(new Error('Failed to start container.')) next(new Error('Failed to connect to container.'))
} }
} }
-3
View File
@@ -11,7 +11,6 @@ export async function connectToSSH(
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
conn conn
.on('ready', () => { .on('ready', () => {
console.log('SSH connection ready')
conn.shell( conn.shell(
{ {
env: { env: {
@@ -26,7 +25,6 @@ export async function connectToSSH(
reject(err) reject(err)
} }
stream.on('close', () => { stream.on('close', () => {
console.log('Stream :: close')
conn.end() conn.end()
}) })
resolve(stream) resolve(stream)
@@ -41,7 +39,6 @@ export async function connectToSSH(
port: 22, port: 22,
username: 'commander', username: 'commander',
privateKey: config.docker.keypair.privateKey, privateKey: config.docker.keypair.privateKey,
debug: console.log,
timeout: 5000, timeout: 5000,
}) })
}) })