Skip to the content.

Docker Image for deployment

This image based at Ubuntu and contains:

Setup

You may to setup variables via CI/CD variables

# SSH Private key 
$DEPLOY_KEY=dadaddasdas
# SSH Fingerprints
$SSH_KNOWN_HOSTS=github.com ssh-rsa AAAAB3NzaC1yc2EAAAAB...

Example of .gitlab-ci.yml

image: kromz/deploy-tools:latest

stages:
  - deploy


deploy:
  image: kromz/deploy-tools:latest
  stage: deploy
  only:
    - master
  environment:
    name: Dev
  script:
    - eval $(ssh-agent -s)
    - echo "$DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - ssh $USER@$HOST uname -a
    - rsync -a public $USER@$HOST:/var/www/public

Commands description

Start SSH Agent for authentication by SSH Keys

eval $(ssh-agent -s)

Apply Private SSH Key

echo "$DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null

Apply fingerprints for remote servers

mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts

Generate fingerprints for $SSH_KNOWN_HOSTS

ssh-keyscan <remote SSH server>

Files