Simple SSH Deployment


#1

Hey,

Really enjoyed using CircleCI for my Mocha tests within my Node app. I’m now looking to get a straightforward deployment process using SSH into my dev server, however the docs don’t seem to be clear on this and jumping around StackOverflow and this forum has been a bit of a minefield with mixture of V1 & V2 configs (I think?).

This is what I have, but I think this may be a mix of V1 code in my V2 config? I’m essentially trying to run the following command on build success: ssh ubuntu@xxx.xxx.xxx.xxx ‘sudo git -C /home/app pull origin develop && sudo systemctl restart api.service’

Full config:

version: 2
jobs:
  build:
docker:
  # specify the version you desire here
  - image: circleci/node:8.4.0
    environment:
      NODE_ENV: development
      DEBUG: "*,-express*"
      HOST: "*"
      PORT: 8080
      BCRYPT_SALT_ROUNDS: 10
      TOKEN_SECRET: vkb6cgvlerc7ble78cb;r7b
      UPLOADS_DIR: uploads/

  # Specify service dependencies here if necessary
  # CircleCI maintains a library of pre-built images
  # documented at https://circleci.com/docs/2.0/circleci-images/
  - image: circleci/mongo:3.4.4


working_directory: ~/api

steps:
  - checkout

  # Download and cache dependencies
  - restore_cache:
      keys:
      - v1-dependencies-{{ checksum "app/package.json" }}
      # fallback to using the latest cache if no exact match is found
      - v1-dependencies-

  - run: cd app;npm install

  - save_cache:
      paths:
        - app/node_modules
      key: v1-dependencies-{{ checksum "app/package.json" }}

  # run tests!
  - run: cd app;npm run circleci-test

deployment:
  dev:
    branch: develop
    commands:
      - ssh ubuntu@xxx.xxx.xxx.xxx 'sudo git -C /home/app pull origin develop && sudo systemctl restart api.service'```

#2

This looks fine to me, are you running into an issue here?

This will work as long as an SSH key that you add to our UI is in the .authorized_keys file for the ubuntu user on server xxx.xxx.xxx.xxx.


#3

Hey @levlaz,

Thanks for getting back to me. The key is definitely in there yes but still no progress. Could anything else be at play here?

Do you have any suggestions on how to debug this step? I can find anything related to it after a successful build.

Thanks,
Warren


#4

Is the key encrypted?

i.e. when you ran ssh-keygen did you add a password?


#5

Hey Levlaz,

Key is not encrypted no. Is there somewhere I can debug this within CircleCI?


#6

Hm, thats tough its supposed to just work™

Are you able to pair on this with me? Would love to see what you see.


#7