Skip to content

Instantly share code, notes, and snippets.

@col
Last active July 4, 2020 17:46
Show Gist options
  • Save col/bcbb36299a5dcd767a30 to your computer and use it in GitHub Desktop.
Save col/bcbb36299a5dcd767a30 to your computer and use it in GitHub Desktop.
Configure Elixir app on Travis CI

Configure Elixir app on Travis CI

Setup Build

  1. Create .travis.yml file in the base dir
  2. Enter the following content:
language: elixir
elixir:
  - 1.2
otp_release:
  - 18.0
sudo: false
  1. Commit
  2. Goto travisci.com and enable your project
  3. Profit!

Setup Deployment

Sources:

###On your local machine:

Generate a new key pair

ssh-keygen

This will prompt for a two things, namely:

  • The output path (use /home/<username>/.ssh/<app_name>)
  • A passphrase (leave it empty)

Now copy the key to the server

cat ~/.ssh/<app_name>.pub | ssh <mydomain> "sudo sshcommand acl-add dokku <app_name>"

Now we can test pushing a project

Since we're not using the default key pair. We'll have to do a bit of local configuration.

Add the following to ~/.ssh/config

Host <app_name>.<mydomain>
  HostName <app_name>.<mydomain>
  User root
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/<app_name>

Note that we're using the private key not <app_name>.pub

Add a remote to the project

git remote add dokku dokku@<app_name>.<mydomain>:<app_name>

Then push

git push dokku master

Install the travis gem

gem install travis

Create a travis directory

mkdir .travis

Create a pem file

openssl rsa -in ~/.ssh/<app_name> -outform pem > .travis/<app_name>.pem

Hide it from git

echo .travis/<app_name>.pem >> .gitignore

Log into travis

travis login --auto

Encrypt the key

travis encrypt-file .travis/<app_name>.pem --add

For some reason travis adds the encrypted key to the root directory lets move that

mv <app_name>.pem.enc .travis

Edit the .travis.yml file to reflect the move. Change -in <app_name>.pem.enc to -in .travis/<app_name>.pem.enc

Add a after_success: section like so

- chmod 600 .travis/<app_name>.pem
- mkdir -p ~/.ssh
- cp .travis/<app_name>.pem ~/.ssh
- cat .travis/host >> ~/.ssh/config
- git remote add production dokku@<mydomain>:<app_name>
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && git push dokku master

Then create a .travis/host to make travis use the correct key:

Host <server address>
    StrictHostKeyChecking no
    IdentityFile ~/.ssh/<app_name>.pem

Then register your project on travis-ci.org and push away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment