diff options
Diffstat (limited to 'gitolite')
| -rw-r--r-- | gitolite/Dockerfile | 30 | ||||
| -rw-r--r-- | gitolite/docker-entrypoint.sh | 44 |
2 files changed, 74 insertions, 0 deletions
diff --git a/gitolite/Dockerfile b/gitolite/Dockerfile new file mode 100644 index 0000000..f6749f7 --- /dev/null +++ b/gitolite/Dockerfile @@ -0,0 +1,30 @@ +FROM alpine:3.23.3 + +# Install OpenSSH server and Gitolite +# Unlock the automatically-created git user +RUN set -x \ + && apk add --no-cache openrc fail2ban gitolite openssh + +RUN apk update && apk update + +RUN rc-update add fail2ban + +RUN git config --system advice.defaultBranchName false + +# Volume used to store SSH host keys, generated on first run +VOLUME /etc/ssh/keys + +# Volume used to store all Gitolite data (keys, config and repositories), initialized on first run +VOLUME /var/lib/git + +# Entrypoint responsible for SSH host keys generation, and Gitolite data initialization +COPY docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT ["/docker-entrypoint.sh"] + +# Expose port 22 to access SSH +EXPOSE 22 + +# Default command is to run the SSH server + +CMD ["sshd"] diff --git a/gitolite/docker-entrypoint.sh b/gitolite/docker-entrypoint.sh new file mode 100644 index 0000000..94717eb --- /dev/null +++ b/gitolite/docker-entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +set -ex + +# if command is sshd, set it up correctly +if [ "${1}" = 'sshd' ]; then + set -- /usr/sbin/sshd -D + + # Setup SSH HostKeys if needed + for algorithm in rsa ecdsa ed25519 + do + keyfile=/etc/ssh/keys/ssh_host_${algorithm}_key + [ -f $keyfile ] || ssh-keygen -q -N '' -f $keyfile -t $algorithm + grep -q "HostKey $keyfile" /etc/ssh/sshd_config || echo "HostKey $keyfile" >> /etc/ssh/sshd_config + done + # Disable unwanted authentications + perl -i -pe 's/^#?((?!Kerberos|GSSAPI|Password)\w*Authentication)\s.*/\1 no/; s/^(PubkeyAuthentication) no/\1 yes/' /etc/ssh/sshd_config + perl -i -pe 's/^#?(PermitRootLogin)\s.*/\1 no/' /etc/ssh/sshd_config + # Disable sftp subsystem + perl -i -pe 's/^(Subsystem\ssftp\s)/#\1/' /etc/ssh/sshd_config +fi + +# Fix permissions at every startup +chown -R git:git ~git + +# Setup gitolite admin +if [ ! -f ~git/.ssh/authorized_keys ]; then + if [ -n "$SSH_KEY" ]; then + [ -n "$SSH_KEY_NAME" ] || SSH_KEY_NAME=admin + echo "$SSH_KEY" > "/tmp/$SSH_KEY_NAME.pub" + su - git -c "gitolite setup -pk \"/tmp/$SSH_KEY_NAME.pub\"" + rm "/tmp/$SSH_KEY_NAME.pub" + else + echo "You need to specify SSH_KEY on first run to setup gitolite" + echo "You can also use SSH_KEY_NAME to specify the key name (optional)" + echo 'Example: docker run -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" -e SSH_KEY_NAME="$(whoami)" jgiannuzzi/gitolite' + exit 1 + fi +# Check setup at every startup +else + su - git -c "gitolite setup" +fi + +exec "$@" |
