# What is the best way to deploy to a remote server

**URL:** <https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313>\
**Category:** Deployments\
**Created:** [March 21, 2022, 1:55pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313 "2022-03-21T13:55:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grasmachien](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Grasmachien](https://discuss.circleci.com/u/Grasmachien)\
**Post date:** [March 21, 2022, 1:55pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/1 "2022-03-21T13:55:48Z")

</div>

Hi everyone,

Our team currently uploads files manually to the server which causes some problems because there is a lot of room for human error.  
So I’m looking into continuous deployment via CircleCi.

We use bitbucket for version control and would like the option to either auto deploy when pushing to a specific branch or deploy by clicking on a button in the CircleCi interface. Not sure if this is possible tbh.  
We have a dedicated server with plesk to which we want to deploy.

I tried looking for some deployment examples but it just keeps getting more confusing.  
Should I use FTP or ssh deployments?  
Why is there no infrastructure on CircleCi to deploy? It seems like everything needs to be build by scratch.

Any examples to a simple deployment script are appreciated.

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [March 21, 2022, 4:03pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/2 "2022-03-21T16:03:55Z")

</div>

Any project you define in CircleCI can run scripts - so the starting point would be to just write a script that follows the same steps as you currently follow with your manual process.

Once you can perform the manual process, by just executing the Project within the CircleCI dashboard you can then start to enhance the process with whatever tools you wish to use. Doing it this way also means you have a working baseline that you understand and can always go back to.

---

<div class="post-metadata">

**Author:** ![Grasmachien](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Grasmachien](https://discuss.circleci.com/u/Grasmachien)\
**Post date:** [March 23, 2022, 3:03pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/3 "2022-03-23T15:03:11Z")

</div>

So what I understand is that after years there are no best practices or recommendations on how to get started?  
Everything seems straight forward when you want to upload to AWS of Heroku but when you want to deploy to a normal server nobody seems to know what to do.

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [March 23, 2022, 5:43pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/4 "2022-03-23T17:43:26Z")

</div>

It is more the fact that I build docker containers with CircleCI so there is nothing I can provide for a general deployment process.

If you provide some detail about your environment and toolset someone may be able to provide some details on how they do things in a similar environment.

---

<div class="post-metadata">

**Author:** ![Grasmachien](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Grasmachien](https://discuss.circleci.com/u/Grasmachien)\
**Post date:** [March 24, 2022, 2:09pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/5 "2022-03-24T14:09:05Z")

</div>

This is the config I’m currently trying to get to work:

```auto
version: 2.1

executors:
  my-executor:
    docker:
      - image: cimg/node:14.18.2

jobs:
  build:
    executor: my-executor

    steps:
      - checkout

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

      - run: npm install

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

      - run: npm run build --prod
  deploy:
    executor: my-executor
    steps:
      - add_ssh_keys:
          fingerprints:
            - $SSH_FINGERPRINT
      - run: sudo apt install rsync
      - run:
          name: Deploy Over SSH
          command: |
            rsync -a $LOCAL_PATH $SSH_USER@$SSH_HOST:$REMOTE_PATH
      - run: ssh $SSH_USER@$SSH_HOST 'chmod -R 755 $REMOTE_PATH'

workflows:
  version: 2.1
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build

```

The build job is working, however I think that the build is not being kept for the next job.  
But at least it does not fail.  
The deploy step however does not work .

The error I’m getting is this:

```auto
#!/bin/bash -eo pipefail
sudo apt install rsync
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package rsync

Exited with code exit status 100
CircleCI received exit code 100

```

Which is weird because rsync is being installed.

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [March 24, 2022, 2:28pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/6 "2022-03-24T14:28:48Z")

</div>

I do not have an exact answer, but the error you are getting back is from the apt install command, so rsync is not being correctly installed.

The first thing to try will be to use

```
   sudo apt install -y rsync

```

As the -y is normally rather important for automated tasks.

---

<div class="post-metadata">

**Author:** ![Grasmachien](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Grasmachien](https://discuss.circleci.com/u/Grasmachien)\
**Post date:** [March 24, 2022, 2:53pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/7 "2022-03-24T14:53:40Z")

</div>

It seems like the issue is caused by something else.  
Unfortunately there are no useful results when searching the web for example configurations with rsync.

```auto
#!/bin/bash -eo pipefail
sudo apt install -y rsync
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package rsync

Exited with code exit status 100
CircleCI received exit code 100

```

---

<div class="post-metadata">

**Author:** ![rit1010](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rit1010/32/34738_2.png) [@rit1010](https://discuss.circleci.com/u/rit1010)\
**Post date:** [March 24, 2022, 4:19pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/8 "2022-03-24T16:19:33Z")

</div>

> [@Grasmachien](#):
>
> `received exit code 100`

It would be worth dropping a “sudo apt-get update” into your script so that it is using up to date set of repositories.

---

<div class="post-metadata">

**Author:** ![oliver-subs](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/oliver-subs/32/28695_2.png) [@oliver-subs](https://discuss.circleci.com/u/oliver-subs)\
**Post date:** [March 28, 2022, 6:31pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/9 "2022-03-28T18:31:36Z")

</div>

Artifacts built in a job do not automatically persist to the next job. You need to save such artifacts to a workspace at end of job, and load them at beginning of next job. Search for save workspace and you should get to examples pretty quickly.

---

<div class="post-metadata">

**Author:** ![Grasmachien](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Grasmachien](https://discuss.circleci.com/u/Grasmachien)\
**Post date:** [April 4, 2022, 11:36am UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/10 "2022-04-04T11:36:45Z")

</div>

Hi Oliver,

Yeah I have disabled them so I can focus on the deployment.  
The build step can be changed later but the deployment itself is more important atm.

Could you point me to a working example on how to use rsync with circleci?

---

<div class="post-metadata">

**Author:** ![schollii](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/schollii/32/29830_2.png) [@schollii](https://discuss.circleci.com/u/schollii)\
**Post date:** [April 4, 2022, 7:19pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/11 "2022-04-04T19:19:56Z")

</div>

@Grasmachien sorry I do not. I don’t know enough about your situation, but I have a feeling that using rsync is not the way to go. I presume you are trying to install some private ssh keys onto the circleci machine? Can you use AWS Secrets or similar? If so, you could put the private keys there. Alternatively, put the keys in AWS S3 and retrieve from circleci (Azure and GCP have their equivalents of Secrets and S3).

---

<div class="post-metadata">

**Author:** ![Grasmachien](https://avatars.discourse-cdn.com/v4/letter/g/8e8cbc/32.png) [@Grasmachien](https://discuss.circleci.com/u/Grasmachien)\
**Post date:** [April 5, 2022, 7:44am UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/12 "2022-04-05T07:44:06Z")

</div>

@schollii Why would rsync not be the way to go?  
We have a normal dedicated server.  
No AWS or anything like that.

I just found out the main reason why my attempts always fail. We can only access our server via a VPN or on our whitelisted IP at the office. I contacted my hosting provider and was told that connecting to the VPN might prove to be hard because they work with a specific VPN client. We might want to use [IP ranges](https://circleci.com/docs/2.0/ip-ranges/) to whitelist circle ci in the firewall of the server.

---

<div class="post-metadata">

**Author:** ![glebsts](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/glebsts/32/29623_2.png) [@glebsts](https://discuss.circleci.com/u/glebsts)\
**Post date:** [April 11, 2022, 9:43am UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/13 "2022-04-11T09:43:22Z")

</div>

> normal server  
> AWS is new normality 😃  
> As to providing keys to job, easiest way would be use CircleCI contexts - zero overhead on getting them to the job. Second option is getting them from AWS/GCP key storage (if you know how to use them).

---

<div class="post-metadata">

**Author:** ![neoswf](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/neoswf/32/34054_2.png) [@neoswf](https://discuss.circleci.com/u/neoswf)\
**Post date:** [October 31, 2023, 8:38pm UTC](https://discuss.circleci.com/t/what-is-the-best-way-to-deploy-to-a-remote-server/43313/14 "2023-10-31T20:38:56Z")

</div>

Thanks man! This did the job!
