Commit 94707a05 authored by Valencia Vargas, Carlos's avatar Valencia Vargas, Carlos
Browse files

Added setup_push.sh

parent 5bb21f79
......@@ -9,9 +9,9 @@ testing:
- echo "TODO - Add tests"
deploy:
image: ilyasemenov/gitlab-ci-git-push
stage: deploy
only:
- master
script:
- git-push ssh://dokku@cloud-vm-42-75.doc.ic.ac.uk:22/$APP_NAME
- chmod +x ./setup_push.sh
- ./setup_push.sh ssh://dokku@cloud-vm-42-75.doc.ic.ac.uk:22/$APP_NAME master
#!/bin/bash -e
url=$1
branch=$2
if [ -z "$SSH_PRIVATE_KEY" ]; then
>&2 echo "Set SSH_PRIVATE_KEY environment variable"
exit 1
fi
ssh_host=$(echo $url | sed 's/.*@//' | sed 's/[:/].*//')
if [ -z "$ssh_host" ]; then
>&2 echo "Usage: $0 <user@git.host:project | ssh://user@git.host:port/project> [<branch>]"
exit 1
fi
ssh_port=
if [[ $url =~ ^ssh://[^/]+:([0-9]+) ]]; then
ssh_port="-p ${BASH_REMATCH[1]}"
fi
# TODO: skip on multiple runs
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | tr -d '\n' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H $ssh_port "$ssh_host" >> ~/.ssh/known_hosts
git push $url ${CI_COMMIT_SHA:-HEAD}:refs/heads/${branch:-master} $([ -z "$DISABLE_FORCE_PUSH" ] && echo --force)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment