mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: auto create config folder and player network
This commit is contained in:
1 parent
91ebaec22c
commit
b449d84c54
5 files changed
+25
-2
No files matched your search
@@ -67,6 +67,7 @@ This will start the db. it will automatically restarts by Docker.
|
|||||||
|
|
||||||
Building quest images:
|
Building quest images:
|
||||||
|
|
||||||
|
docker compose build base
|
||||||
yarn build:quests
|
yarn build:quests
|
||||||
|
|
||||||
### Build Quest Images in Details
|
### Build Quest Images in Details
|
||||||
|
|||||||
+2
-2
@@ -12,8 +12,8 @@ services:
|
|||||||
|
|
||||||
base:
|
base:
|
||||||
image: linuxodyssey/quest-base
|
image: linuxodyssey/quest-base
|
||||||
# networks:
|
networks:
|
||||||
# - players
|
- players
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./quests/Dockerfile
|
dockerfile: ./quests/Dockerfile
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
USERNAME=commander
|
USERNAME=commander
|
||||||
|
|
||||||
|
echo "Initializing container for $USERNAME"
|
||||||
|
|
||||||
if ! id -u ${USERNAME} >/dev/null 2>&1; then
|
if ! id -u ${USERNAME} >/dev/null 2>&1; then
|
||||||
|
echo "Adding user $USERNAME"
|
||||||
adduser --disabled-password --gecos '' --shell /bin/zsh ${USERNAME} && \
|
adduser --disabled-password --gecos '' --shell /bin/zsh ${USERNAME} && \
|
||||||
find / -name ".gitkeep" -type f -exec rm -f {} +
|
find / -name ".gitkeep" -type f -exec rm -f {} +
|
||||||
|
|
||||||
|
echo "Adding public key for $USERNAME"
|
||||||
PUB_KEY=/etc/ssh/authorized_keys/${USERNAME}
|
PUB_KEY=/etc/ssh/authorized_keys/${USERNAME}
|
||||||
cp /ssh_key.pub ${PUB_KEY}
|
cp /ssh_key.pub ${PUB_KEY}
|
||||||
chmod 644 ${PUB_KEY}
|
chmod 644 ${PUB_KEY}
|
||||||
|
|||||||
@@ -47,9 +47,22 @@ export async function createContainer(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
const option = newContainerOptions(name, imageId, { binds })
|
const option = newContainerOptions(name, imageId, { binds })
|
||||||
|
await createNetworkIfNotExists(config.docker.network)
|
||||||
return engine.createContainer(option)
|
return engine.createContainer(option)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createNetworkIfNotExists(network: string) {
|
||||||
|
const dockerNetworks = await engine.listNetworks({
|
||||||
|
filters: {
|
||||||
|
name: [network],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (dockerNetworks.length === 0) {
|
||||||
|
console.log('Creating player network', network)
|
||||||
|
await engine.createNetwork({ Name: network })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function questHomeExists(imageId: string) {
|
async function questHomeExists(imageId: string) {
|
||||||
try {
|
try {
|
||||||
const stat = await fs.stat(`${config.projectRoot}/quests/${imageId}/home`)
|
const stat = await fs.stat(`${config.projectRoot}/quests/${imageId}/home`)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
import ssh2 from 'ssh2'
|
import ssh2 from 'ssh2'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -17,6 +18,10 @@ export function loadOrCreateKeyPair(privateKeyPath: string): KeyPair {
|
|||||||
const publicKey = fs.readFileSync(publicKeyPath, 'utf8')
|
const publicKey = fs.readFileSync(publicKeyPath, 'utf8')
|
||||||
return { privateKey, publicKey }
|
return { privateKey, publicKey }
|
||||||
}
|
}
|
||||||
|
const dir = path.dirname(privateKeyPath)
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
fs.mkdirSync(dir, { recursive: true })
|
||||||
|
}
|
||||||
const keyPair = generateKeyPair()
|
const keyPair = generateKeyPair()
|
||||||
fs.writeFileSync(privateKeyPath, keyPair.privateKey, {
|
fs.writeFileSync(privateKeyPath, keyPair.privateKey, {
|
||||||
mode: 0o600,
|
mode: 0o600,
|
||||||
|
|||||||
Reference in new issue
Block a user