Created
October 13, 2020 09:54
-
-
Save janlucaklees/35858ef593cd90d265009da3f6b7c54e to your computer and use it in GitHub Desktop.
Test a GitLab-CI deploy with env vars
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
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 |
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
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