Skip to content

Instantly share code, notes, and snippets.

@kdetony
Forked from yannhowe/.gitlab.ci.yml
Created August 13, 2020 05:14
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 kdetony/7fee72dfb98075d388b07c3adec30dae to your computer and use it in GitHub Desktop.
Save kdetony/7fee72dfb98075d388b07c3adec30dae to your computer and use it in GitHub Desktop.
.gitlab.ci.yml for SSH with private key.
# 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