feat(IaC-Docker-Compose) Add workaround for broken-ssh-connections

This commit is contained in:
Marcel Feix 2022-05-10 10:00:54 +02:00
parent c208448907
commit e70980a2fb
No known key found for this signature in database
GPG Key ID: 04D016E104A25F03
2 changed files with 15 additions and 2 deletions

View File

@ -46,6 +46,10 @@ echo SOME_PASSWORD="$SOME_PASSWORD" >>.env
| URL of the remote server. | URL of the remote server.
| - | -
| SSH_PORT
| SSH port of the remote server.
| 22
| SSH_USER | SSH_USER
| The user that is used to login into the remote maschine. | The user that is used to login into the remote maschine.
| - | -

View File

@ -7,6 +7,7 @@
COMPOSE_EXTRA_ARGS: "" COMPOSE_EXTRA_ARGS: ""
SSH_URL: "" SSH_URL: ""
SSH_USER: "" SSH_USER: ""
SSH_PORT: "22"
DOCKER_REGISTRY: "$CI_REGISTRY" DOCKER_REGISTRY: "$CI_REGISTRY"
ENV_SETUP_FILE: "setup_env.sh" ENV_SETUP_FILE: "setup_env.sh"
SSH_PRIVATE_KEY_DEPLOY: $SSH_PRIVATE_KEY SSH_PRIVATE_KEY_DEPLOY: $SSH_PRIVATE_KEY
@ -28,7 +29,15 @@
- chmod +x /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose
script: script:
- if [[ -n "$SCP_SOURCE" && -n "$SCP_DESTINATION" ]]; then scp -rp $SCP_SOURCE $SSH_USER@$SSH_URL:$SCP_DESTINATION; fi - if [[ -n "$SCP_SOURCE" && -n "$SCP_DESTINATION" ]]; then scp -rp $SCP_SOURCE $SSH_USER@$SSH_URL:$SCP_DESTINATION; fi
- DOCKER_HOST=ssh://$SSH_USER@$SSH_URL docker-compose $COMPOSE_EXTRA_ARGS up -d --remove-orphans - DOCKER_HOST=ssh://$SSH_USER@$SSH_URL:$SSH_PORT docker-compose $COMPOSE_EXTRA_ARGS up -d --remove-orphans
.broken-ssh-connection-workaround: &broken-ssh-connection-workaround
- if [[ -n "$SCP_SOURCE" && -n "$SCP_DESTINATION" ]]; then scp -rp $SCP_SOURCE $SSH_USER@$SSH_URL:$SCP_DESTINATION; fi
# Tunnel Docker socket from remote Maschine to local Maschine. This should be more stable than the current SSH Implementation of Docker
- rm -f /tmp/docker.sock
- ssh -M -S docker-ctrl-socket -fnNT -L /tmp/docker.sock:/var/run/docker.sock "$SSH_USER@$SSH_URL" -p $SSH_PORT -o ControlPersist=no
- DOCKER_HOST=unix:///tmp/docker.sock docker-compose $COMPOSE_EXTRA_ARGS up -d --remove-orphans
.docker-compose-validate: .docker-compose-validate:
image: docker:20.10.14-alpine3.15 image: docker:20.10.14-alpine3.15