Deploy to external server using ssh

Hi guys,

I’m new to Circle.CI. I started to write my config yml file. All is working as expected in my React app, ie. circle install my dependencies with yarn, it builds the app as well. The one step I’m still missing is to deploy it to the external server. I’m using ssh to connect to it. I did upload private key to circle and public key to my server. So that is for sure correct. I think my syntax though is wrong:

    version: 2

defaults: &defaults
  working_directory: /home/circleci/Przygody_front
  docker:
    - image: circleci/node:8.11

jobs:
  dependencies:
    <<: *defaults

    steps:
      - checkout
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          - v1-dependencies-

      - run: yarn install --frozen-lockfile
      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - persist_to_workspace:
          root: /home/circleci
          paths:
            - Przygody_front
    
  build:
    <<: *defaults

    steps:
      - attach_workspace:
          at: /home/circleci

      - run: CI=false yarn build

      - persist_to_workspace:
          root: /home/circleci
          paths:
            - Przygody_front/build

  deploy:
    <<: *defaults

    steps:
      - attach_workspace:
          at: /home/circleci
      - add_ssh_keys
      - run: echo 'THE FINGERPRINT' >> ~/.ssh/known_hosts
      - run: scp /home/circleci/Przygody_front/build ssh -o StrictHostKeyChecking=no votumsma@votumsma.smarthost.pl:/www/malewielkieprzygody.pl -p 222

workflows:
  version: 2
  dependencies_and_build:
    jobs:
      - dependencies
      - build:
          requires:
            - dependencies
      - deploy

I guess the line with scp is wrong, I’m having error:

#!/bin/bash -eo pipefail scp /home/circleci/Przygody_front/build ssh -o StrictHostKeyChecking=no votumsma@votumsma.smarthost.pl:/www/malewielkieprzygody.pl -p 222

222: No such file or directory Exited with code 1

Thank you in advance!

Can you add a debug step to your config?

pwd 
ls -al 

this will help you see what is available in the context of the build while its running. I suspect the build folder is either in a different path, or is non existent at all.

Hi levlaz, thank you for your response. When I do what you suggested I get:

#!/bin/bash -eo pipefail pwd

/home/circleci/Przygody_front

and…

#!/bin/bash -eo pipefail ls -al
total 8 
drwxr-xr-x 2 circleci circleci 4096 Dec 24 10:31 . 
drwxr-xr-x 4 circleci circleci 4096 Dec 24 10:31 ..

So I assume that there is no such a folder as build (Przygody_front is empty), which is something I didn’t expect as I tried to use “persist_to_workspace” command with build. When I’m debugging my build step in ssh mode then I can see that there is build folder and the proper content is inside, doing the same in deploy step shows me that there is not build folder. How can I pass it through steps and how can I copy it to the remote server?

Can you share your config?

Persist to workspace does not necessarily put things into your home folder.

The error you encounter is pretty simple. scp uses -P with a capital P to specifiy the port number. see this stackoverflow post: https://stackoverflow.com/questions/10341032/scp-with-port-number-specified

If that is the only problem you have with all this that might already fix it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.