Created
April 1, 2023 14:32
-
-
Save jontey/25de496f4aad2d677693b10b2f58072d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:latest | |
RUN apk add --no-cache openssh-client | |
COPY ./entrypoint.sh /bin/ | |
ENTRYPOINT [ "/bin/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -d /root/.ssh ]; then | |
chmod -R 600 /root/.ssh | |
fi | |
if [ -z "$SSH_PORT" ]; then | |
SSH_PORT=22 | |
fi | |
if [ -z "$REMOTE_IP" ]; then | |
REMOTE_IP=* | |
fi | |
echo "$(date +"%Y-%m-%d %H:%m:%S%z") [INFO] opening tunnel at ${SSH_LOGIN} (port ${SSH_PORT})" | |
while true; do | |
# bind logstash at localhost:5044 of remote host | |
ssh -N \ | |
-o UserKnownHostsFile=/dev/null \ | |
-o StrictHostKeyChecking=no \ | |
-o ExitOnForwardFailure=yes \ | |
-o ServerAliveInterval=500 \ | |
-o ServerAliveCountMax=3 \ | |
-R ${REMOTE_IP}:${REMOTE_PORT}:${CONTAINER_HOST}:${CONTAINER_PORT} \ | |
-p ${SSH_PORT} ${SSH_LOGIN}; | |
echo "$(date +"%Y-%m-%d %H:%m:%S%z") [INFO] connection closed. reconnecting in 3 seconds.." | |
sleep 3; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment