Skip to content

Instantly share code, notes, and snippets.

@abatilo
Last active June 1, 2024 18:23
Show Gist options
  • Save abatilo/2b0c99d8536476f0219de2b8cc038870 to your computer and use it in GitHub Desktop.
Save abatilo/2b0c99d8536476f0219de2b8cc038870 to your computer and use it in GitHub Desktop.
Start a training process with sshd - https://sliceofexperiments.com
FROM ubuntu:22.04
# Install sshd and xz to unzip the s6-overlay tarball
RUN <<EOF
apt-get update;
apt-get install -yq openssh-server xz-utils;
EOF
# Install s6-overlay
ADD https://github.com/just-containers/s6-overlay/releases/download/v3.1.6.2/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v3.1.6.2/s6-overlay-x86_64.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz
# Define sshd as a long running s6 service
COPY <<EOF /etc/s6-overlay/s6-rc.d/sshd/type
longrun
EOF
# Define entrypoint for sshd
# Create sshd's required directory
# Daemon applications tend to log to stderr, so redirect it to stdout
# Start sshd in the foreground
COPY --chmod=700 <<EOF /etc/s6-overlay/s6-rc.d/sshd/run
#!/bin/sh
mkdir -p /var/run/sshd
/usr/sbin/sshd -D -e
EOF
# Register sshd as a service for s6 to manage
RUN touch /etc/s6-overlay/s6-rc.d/user/contents.d/sshd
# Copy my ssh public keys to the container
ADD https://github.com/abatilo.keys /root/.ssh/authorized_keys
# Define training as a one shot s6 service
WORKDIR /app
COPY --chmod=700 <<EOF /app/training.sh
#!/bin/sh
echo "Training started"
sleep 5
echo "Training finished"
EOF
ENTRYPOINT ["/init"]
CMD ["/app/training.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment