5

Deploy to GitHub repositories in TravisCI Jobs

 2 years ago
source link: https://mlocati.github.io/articles/deploy-to-github-in-travisci-jobs.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Introduction

By using GitHub deploy keys you can safely push to GitHub repositories, or read private GitHub repositories.

Configuration

Let’s assume that:

  • your GitHub user name / organization name is
  • your GitHub repository name is
  • your are going to encrypt the private key with

Generate a private key

  • Install OpenSSH on your system (or in a Virtual Machine, Docker container, WSL, …)
  • Generate an RSA private key without a passphrase:
    ssh-keygen -b 4096 -t rsa -N "" -C "Deploy key for username/reponame" -f github_deploy_key
    
  • Encrypt the private key
    openssl aes-256-cbc -e -in github_deploy_key -pass 'pass:your encryption password' -md sha256 -out github_deploy_key.enc

Add the key to the GitHub deploy keys

Go to https://github.com/username/reponame/settings/keys/new and enter this data:

  • Title
    a name of your choice
  • Key
    paste the contents of the github_deploy_key.pub file
  • Allow write access
    check this if you will need to push to the repository

Add the decryption password to TravisCI

Add the encrypted key to your repository

Add the github_deploy_key.enc file file to your repository.
By default, you can save it as .travis/github_deploy_key.enc

Configure the TravisCI job

  • If you didn’t save the encrypted key as .travis/github_deploy_key.enc, define an environment variable named DEPLOYKEY_FILE whose value is the relative path to the encrypted key
  • Invoke the following code to load the key so that GIT has (write) access to the repository:
    wget -q -O - https://raw.githubusercontent.com/mlocati/travisci-github-deploy-key/master/load-deploy-key.sh | sh
    

Credits

From a great idea by @B3rn475.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK