mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
fix: copy entrypoint into quest container. Disable mounting for entrypoint & public key. Use Env to pass ssh public key into container.
This commit is contained in:
1 parent
860b257ea7
commit
1888781a47
5 files changed
+32
-23
No files matched your search
+13
-9
@@ -32,13 +32,20 @@ services:
|
|||||||
- ./config:/app/config
|
- ./config:/app/config
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
|
- .env.prod
|
||||||
environment:
|
environment:
|
||||||
- MONGO_URL=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@db:27017/${MONGO_DB}
|
- MONGO_URL=mongodb://${MONGO_USER}:${MONGO_PASS}@db:27017/${MONGO_DB}
|
||||||
- DOCKER_NETWORK=linux-odyssey-players
|
- DOCKER_NETWORK=linux-odyssey-players
|
||||||
- SECRET_KEY=${SECRET_KEY}
|
- SECRET_KEY=${SECRET_KEY}
|
||||||
- TRUSTED_PROXIES=${TRUSTED_PROXIES}
|
- TRUSTED_PROXIES=${TRUSTED_PROXIES}
|
||||||
- BACKEND_URL=http://backend:3000
|
- BACKEND_URL=http://backend:3000
|
||||||
- BASE_URL=${BASE_URL}
|
- BASE_URL=${BASE_URL}
|
||||||
|
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
|
||||||
|
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
|
||||||
|
- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
|
||||||
|
- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
|
||||||
|
- SURVEY_URL=${SURVEY_URL}
|
||||||
|
- BUG_REPORT_URL=${BUG_REPORT_URL}
|
||||||
|
|
||||||
analytics:
|
analytics:
|
||||||
image: linuxodyssey/analytics
|
image: linuxodyssey/analytics
|
||||||
@@ -53,8 +60,11 @@ services:
|
|||||||
- internal
|
- internal
|
||||||
ports:
|
ports:
|
||||||
- '3001:3001'
|
- '3001:3001'
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
- .env.prod
|
||||||
environment:
|
environment:
|
||||||
- MONGO_URL=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@db:27017/${MONGO_DB}
|
- MONGO_URL=mongodb://${MONGO_USER}:${MONGO_PASS}@db:27017/${MONGO_DB}
|
||||||
- ADMIN_USERNAME=${ADMIN_USERNAME}
|
- ADMIN_USERNAME=${ADMIN_USERNAME}
|
||||||
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
|
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
|
||||||
|
|
||||||
@@ -73,14 +83,8 @@ services:
|
|||||||
- MONGO_INITDB_ROOT_USERNAME=admin
|
- MONGO_INITDB_ROOT_USERNAME=admin
|
||||||
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
|
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
|
||||||
- MONGO_USER=${MONGO_USER}
|
- MONGO_USER=${MONGO_USER}
|
||||||
- MONGO_PASS=${MONGO_PASSWORD}
|
- MONGO_PASS=${MONGO_PASS}
|
||||||
- MONGO_DB=${MONGO_DB}
|
- MONGO_DB=${MONGO_DB}
|
||||||
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
|
|
||||||
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
|
|
||||||
- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
|
|
||||||
- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
|
|
||||||
- SURVEY_URL=${SURVEY_URL}
|
|
||||||
- BUG_REPORT_URL=${BUG_REPORT_URL}
|
|
||||||
|
|
||||||
base:
|
base:
|
||||||
image: linuxodyssey/quest-base
|
image: linuxodyssey/quest-base
|
||||||
|
|||||||
+1
-4
@@ -13,15 +13,12 @@ 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
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
- 'host.docker.internal:host-gateway'
|
- 'host.docker.internal:host-gateway'
|
||||||
volumes:
|
|
||||||
# - ./config/ssh_key.pub:/ssh_key.pub:ro
|
|
||||||
- ./quests/entrypoint.sh:/entrypoint.sh:ro
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
internal:
|
internal:
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ RUN rm -f /etc/motd /etc/issue /etc/issue.net /etc/update-motd.d/*
|
|||||||
RUN rm -rf /etc/skel && mkdir -p /etc/skel
|
RUN rm -rf /etc/skel && mkdir -p /etc/skel
|
||||||
RUN mkdir -p /etc/ssh/authorized_keys && chmod 755 /etc/ssh/authorized_keys
|
RUN mkdir -p /etc/ssh/authorized_keys && chmod 755 /etc/ssh/authorized_keys
|
||||||
COPY ./quests/.includes/sshd_config /etc/ssh/sshd_config
|
COPY ./quests/.includes/sshd_config /etc/ssh/sshd_config
|
||||||
|
COPY ./quests/entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 22
|
EXPOSE 22
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ if ! id -u ${USERNAME} >/dev/null 2>&1; then
|
|||||||
find / -name ".gitkeep" -type f -exec rm -f {} +
|
find / -name ".gitkeep" -type f -exec rm -f {} +
|
||||||
|
|
||||||
echo "Adding public key for $USERNAME"
|
echo "Adding public key for $USERNAME"
|
||||||
PUB_KEY=/etc/ssh/authorized_keys/${USERNAME}
|
echo "Public key: $PUB_KEY"
|
||||||
cp /ssh_key.pub ${PUB_KEY}
|
PUB_KEY_PATH=/etc/ssh/authorized_keys/${USERNAME}
|
||||||
chmod 644 ${PUB_KEY}
|
echo $PUB_KEY > ${PUB_KEY_PATH}
|
||||||
|
chmod 644 ${PUB_KEY_PATH}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p /run/sshd
|
mkdir -p /run/sshd
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const newContainerOptions = (
|
|||||||
ExposedPorts: {
|
ExposedPorts: {
|
||||||
'22/tcp': {},
|
'22/tcp': {},
|
||||||
},
|
},
|
||||||
|
Env: [`PUB_KEY=${config.docker.keypair.publicKey}`],
|
||||||
})
|
})
|
||||||
|
|
||||||
export async function createContainer(
|
export async function createContainer(
|
||||||
@@ -32,21 +33,23 @@ export async function createContainer(
|
|||||||
imageId: string
|
imageId: string
|
||||||
): Promise<Docker.Container> {
|
): Promise<Docker.Container> {
|
||||||
let binds: string[] = [
|
let binds: string[] = [
|
||||||
`${config.projectRoot}/config/ssh_key.pub:/ssh_key.pub:ro`,
|
// `${config.docker.hostProjectRoot}/config/ssh_key.pub:/ssh_key.pub:ro`,
|
||||||
`${config.projectRoot}/quests/entrypoint.sh:/entrypoint.sh:ro`,
|
|
||||||
]
|
]
|
||||||
if (await questHomeExists(questId)) {
|
if (await questHomeExists(questId)) {
|
||||||
logger.info('Mounting quest home', questId)
|
logger.info('Mounting quest home', questId)
|
||||||
binds.push(`${config.projectRoot}/quests/${questId}/home:/etc/skel:ro`)
|
binds.push(
|
||||||
|
`${config.docker.hostProjectRoot}/quests/${questId}/home:/etc/skel:ro`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
||||||
logger.info('Mounting quest folder', questId)
|
logger.info('Mounting quest folder', questId)
|
||||||
binds = [
|
binds = [
|
||||||
`${config.projectRoot}/quests/${questId}/home:/home/commander`,
|
`${config.docker.hostProjectRoot}/quests/${questId}/home:/home/commander`,
|
||||||
`${config.projectRoot}/packages/container:/usr/local/lib/container`,
|
`${config.docker.hostProjectRoot}/packages/container:/usr/local/lib/container`,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
const option = newContainerOptions(name, imageId, { binds })
|
const option = newContainerOptions(name, imageId, { binds })
|
||||||
|
console.log('Creating container', option)
|
||||||
await createNetworkIfNotExists(config.docker.network)
|
await createNetworkIfNotExists(config.docker.network)
|
||||||
return engine.createContainer(option)
|
return engine.createContainer(option)
|
||||||
}
|
}
|
||||||
@@ -65,7 +68,9 @@ async function createNetworkIfNotExists(network: string) {
|
|||||||
|
|
||||||
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.docker.hostProjectRoot}/quests/${imageId}/home`
|
||||||
|
)
|
||||||
return stat.isDirectory()
|
return stat.isDirectory()
|
||||||
} catch {
|
} catch {
|
||||||
return false
|
return false
|
||||||
@@ -99,7 +104,8 @@ export async function attachContainer(
|
|||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const stream = await connectToSSH(containerIp, { token })
|
const stream = await connectToSSH(containerIp, { token })
|
||||||
return stream
|
return stream
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
logger.error('Failed to connect to SSH', err)
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, 1000)
|
setTimeout(resolve, 1000)
|
||||||
|
|||||||
Reference in new issue
Block a user