-
-
Save JoshuaChi/24032d3d82c961b8cb20721e2f92fc7f to your computer and use it in GitHub Desktop.
.gitlab.ci.yml for SSH with private key.
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
# Image neeeds to have ssh-client | |
image: docker:git | |
services: | |
- docker:dind | |
stages: | |
- staging | |
before_script: | |
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY | |
- mkdir -p ~/.ssh | |
# Paste the PRIVATE key into a gitlab variable. Pay attention to the linebreak at the end when pasting | |
- echo "$DEPLOY_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa | |
- chmod 600 ~/.ssh/id_rsa | |
- eval "$(ssh-agent -s)" | |
- ssh-add ~/.ssh/id_rsa | |
- ssh-keyscan -H 'your.server.hostname' >> ~/.ssh/known_hosts | |
staging: | |
stage: staging | |
tags: | |
- docker | |
only: | |
- staging | |
script: | |
- docker build --pull -t $CI_REGISTRY_IMAGE:staging . | |
- docker push $CI_REGISTRY_IMAGE:staging | |
# your own server details here | |
- ssh $SERVER_USER@$SERVER_HOSTNAME < deploy.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment