Automated deployment from my repo to remote private server
Asked by Poobalan Maniam:

Hi guys, i have enabled BB pipeline and wanted to auto deploy to my staging remote server when a commit happens either sftp or ssh method.

The problem now here is my staging server in GCP do not have a public IP. Currently i will perform git pull from server each time my dev perform a commit.

I want to keep my server as private and please suggest how i can push the commit to remote server automatically from my BB cloud.

Thanks


Answers:
author: Norbert C
body: Hi Poobalan,

Thank you for contacting Atlassian Community! I'm Norbert from Bitbucket Cloud Support, it's nice to meet you! Also, welcome to the Atlassian Community :)

I'd like to inform you that in case your staging server doesn't have a public IP, unfortunately Bitbucket Pipelines will not be able to connect as Bitbucket Pipelines needs an accessible IP in order to connect to your instance.

As a workaround what I'd like to suggest you is to host the Bitbucket Pipelines in your own environment using [Pipelines Runners](https://support.atlassian.com/bitbucket-cloud/docs/runners/)

With Pipelines Runners, you don't need to have a public IP and in case you run the builds in your own internal network, you will be able to access the other IPs within your network.

Please let us know if you have any further question?

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support

comments: author: Poobalan Maniam
body: Hi Norbert, Thanks for the feedback and alternative method. I will test it out.

Also as additional info for you, i can connect to my remote server with openVpn and ssh. So it there a way to integrate the pipeline with the OpenVpn or can i modify the deployment yaml file so the push happens via vpn to my private remote server. im just checking if i can use my existing pipeline with this method.

Thanks!


author: Norbert C
body: Hi Poobalan,

Unfortunately it's not possible to connect Bitbucket Pipelines to a VPN.   

Currently we have a feature request for this as you can see in the link below:  

[BCLOUD-12753 - Allow customers to connect the pipelines builds to their own VPN server](https://jira.atlassian.com/browse/BCLOUD-12753)

Our development team will give a first-hand update on that ticket if there's any progress made so I would suggest keeping a watch and vote for it.

Do note however that there's no ETA on enhancement request, and all enhancements are implemented with this policy in mind: [Implementation of New Features Policy](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html)  

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support  


author: Poobalan Maniam
body: Hi Norbert, noted on the vpn feature.

About the pipeline runner, all i need to do is add runner in my repo, and then set up a server with docker and run the token command to register it?

The question, can i have this runner host in my private network? similar to my remote server network? can please enlighten me on this or share some guides?


author: Poobalan Maniam
body: Hi Norbert, ignore my previous reply.

Here is the goof update, i have successfully setup configure my pipeline runner and its online now.

So all i wanted to happen is, when ever a commit to master branch i want this pipeline to be run my deploy.sh script which sits in my remote server via ssh. (my deploy.sh will perform git pull from my BB repo).

So the clarity is, where should i configure the ssh access to my remote server? In my bitbucket repo or in my runner host?

if you have a sample script/guide please share and enlighten with me.

Thanks!


author: Norbert C
body: Hi Poobalan,

Based on your description, I believe the following Atlassian Pipes in suitable for you: <https://bitbucket.org/atlassian/ssh-run/src/master/>

What this Atlassian Pipes does is that it connects to your server via SSH and then you can setup that it runs a script on the remote server. A sample script would be the following:

```
script:  - pipe: atlassian/ssh-run:0.4.0    variables:      SSH_USER: 'user'      SERVER: 'IP of the server'
      SSH_KEY: $MY_SSH_KEY      MODE: 'command'      COMMAND: './deploy.sh'
```

Regarding the SSH key, what I would like to suggest you is to encode the private SSH key to a base64 format and use it as an [environmental variable](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/) in your Pipelines.  

Please let me know if it was successful :).

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support


Tags: bitbucket-cloud

bitbucket-pipelines

cloud