mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: use entrypoint to create user account and copy ssh key
This commit is contained in:
1 parent
261c6fc029
commit
be22a121c8
4 files changed
+26
-14
No files matched your search
@@ -19,6 +19,9 @@ services:
|
|||||||
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:
|
||||||
|
|||||||
+2
-12
@@ -21,19 +21,9 @@ RUN yarn install --modules-folder /usr/src/node_modules
|
|||||||
ENV NODE_PATH=/usr/src/node_modules
|
ENV NODE_PATH=/usr/src/node_modules
|
||||||
COPY ./packages/container /usr/local/lib/container
|
COPY ./packages/container /usr/local/lib/container
|
||||||
COPY ./quests/.includes/zshrc /etc/zsh/zshrc
|
COPY ./quests/.includes/zshrc /etc/zsh/zshrc
|
||||||
|
|
||||||
ENV USERNAME=commander
|
|
||||||
|
|
||||||
RUN adduser --disabled-password --gecos '' --shell /bin/zsh ${USERNAME}
|
|
||||||
COPY ./quests/sshd_config /etc/ssh/sshd_config
|
|
||||||
COPY ./config/ssh_key.pub /home/${USERNAME}/.ssh/authorized_keys
|
|
||||||
RUN chmod 600 /home/${USERNAME}/.ssh/authorized_keys \
|
|
||||||
&& chmod 700 /home/${USERNAME}/.ssh \
|
|
||||||
&& chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
|
|
||||||
RUN rm -f /etc/motd /etc/issue /etc/issue.net /etc/update-motd.d/*
|
RUN rm -f /etc/motd /etc/issue /etc/issue.net /etc/update-motd.d/*
|
||||||
|
COPY ./quests/sshd_config /etc/ssh/sshd_config
|
||||||
RUN service ssh start
|
|
||||||
|
|
||||||
EXPOSE 22
|
EXPOSE 22
|
||||||
|
|
||||||
CMD [ "/usr/sbin/sshd", "-D" ]
|
ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
USERNAME=commander
|
||||||
|
|
||||||
|
if ! id -u ${USERNAME} >/dev/null 2>&1; then
|
||||||
|
adduser --disabled-password --gecos '' --shell /bin/zsh ${USERNAME} && \
|
||||||
|
mkdir -p /home/${USERNAME}/.ssh && \
|
||||||
|
cp /ssh_key.pub /home/${USERNAME}/.ssh/authorized_keys && \
|
||||||
|
chmod 600 /home/${USERNAME}/.ssh/authorized_keys && \
|
||||||
|
chmod 700 /home/${USERNAME}/.ssh && \
|
||||||
|
chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir /run/sshd
|
||||||
|
echo "Starting SSH server"
|
||||||
|
/usr/sbin/sshd -D -e
|
||||||
@@ -29,7 +29,10 @@ export function createContainer(
|
|||||||
name: string,
|
name: string,
|
||||||
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.projectRoot}/quests/entrypoint.sh:/entrypoint.sh:ro`,
|
||||||
|
]
|
||||||
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
||||||
logger.info('Mounting quest folder', imageId)
|
logger.info('Mounting quest folder', imageId)
|
||||||
binds = [
|
binds = [
|
||||||
@@ -53,7 +56,7 @@ export async function getAndStartContainer(
|
|||||||
await container.start()
|
await container.start()
|
||||||
}
|
}
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, 1000)
|
setTimeout(resolve, 2000)
|
||||||
})
|
})
|
||||||
return container
|
return container
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user