Skip to content

Instantly share code, notes, and snippets.

@janlucaklees
Created October 13, 2020 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janlucaklees/35858ef593cd90d265009da3f6b7c54e to your computer and use it in GitHub Desktop.
Save janlucaklees/35858ef593cd90d265009da3f6b7c54e to your computer and use it in GitHub Desktop.
Test a GitLab-CI deploy with env vars
stages:
- deploy
deploy:
stage: deploy
only: [master]
before_script:
# SSH setup
- mkdir -p ~/.ssh
- echo "$DEPLOY_PRIVATEKEY" > ~/.ssh/id_rsa
- echo -e "$DEPLOY_HOSTKEY" | tr -d '\r' > ~/.ssh/known_hosts
- echo -e "Host *\n\tStrictHostKeyChecking no\n\tPort $DEPLOY_PORT\n\n" > ~/.ssh/config
- chmod 700 -R ~/.ssh/
script:
# Now deploy your stuff
define DEPLOY_PRIVATEKEY
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAtAB/tFaS2zHcMYKJpd3evq3fD6ZQOdHwt9tndhyPj/AAAAJBVYylwVWMp
cAAAAAtzc2gtZWQyNTUxOQAAACAtAB/tFaS2zHcMYKJpd3evq3fD6ZQOdHwt9tndhyPj/A
AAAEAkp03Vby1VmGDl3Y3/0eh6P7xAte2bHEvMQ2aWWnnzAi0AH+0VpLbMdwxgoml3d6+r
d8PplA50fC322d2HI+P8AAAAB2V4YW1wbGUBAgMEBQY=
-----END OPENSSH PRIVATE KEY-----
endef
export DEPLOY_PRIVATEKEY
define DEPLOY_HOSTKEY
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC0AH+0VpLbMdwxgoml3d6+rd8PplA50fC322d2HI+P8 example
endef
export DEPLOY_HOSTKEY
define DEPLOY_USERNAME
ssh-user
endef
export DEPLOY_USERNAME
define DEPLOY_HOST
example.host
endef
export DEPLOY_HOST
define DEPLOY_PORT
22
endef
export DEPLOY_PORT
.PHONY: test_deploy
test_deploy:
gitlab-runner exec docker \
--env "DEPLOY_PRIVATEKEY=$$DEPLOY_PRIVATEKEY" \
--env "DEPLOY_HOSTKEY=$$DEPLOY_HOSTKEY" \
--env "DEPLOY_USERNAME=$$DEPLOY_USERNAME" \
--env "DEPLOY_HOST=$$DEPLOY_HOST" \
--env "DEPLOY_PORT=$$DEPLOY_PORT" \
deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment