Search code examples
gitsshopenshiftpublic-keyopenshift-client-tools

Deploy an ssh repository to Openshift NextGen


I'm an OpenShift newbie and I'm trying to deploy a Rails app to the Openshift NextGen from a private BitBucket repository. I followed this page and gave in the generated ssh key to BitBucket.

Now the point is, according to that page you must create the app in OpenShift in order to assign it the BuildConfig object in the last step with

oc patch buildConfig <app> -p '{"spec":{"source":{"sourceSecret":{"name":"sshsecret"}}}}'

So before this I ran the command

oc new-app --name=<app> ruby~git@bitbucket.org:<username>/<repository>

to create the Rails app hosted in the BitBucket repository. But if I run oc status, it appears that the app failed to build:

bc/<app> source builds ssh://git@bitbucket.org/<username>/<repository> on openshift/ruby:2.3
  build #1 failed 47 minutes ago
deployment #1 waiting on image or update

Errors:
  * build/<app>-1 has failed.

Am I missing something?

Edit: oc logs build/<app>-1 shows the following output.

Pulling image "registry.ops.openshift.com/rhscl/ruby-23-rhel7@sha256:d89fc‌​0753fbace518d433f3a9‌​95149d70fef69be06a4c‌​e350745277a8ac68e91" ... 
Pulling image "registry.ops.openshift.com/rhscl/ruby-23-rhel7@sha256:d89fc‌​0753fbace518d433f3a9‌​95149d70fef69be06a4c‌​e350745277a8ac68e91" ... 
Cloning "ssh://git@bitbucket.org/<username>/<repository>.git" ... 
error: build error: Host key verification failed. 
fatal: Could not read from remote repository. 
Please make sure you have the correct access rights and the repository exists.

Edit 2: I reproduced the problem by connecting to a GitHub ssh repository in oc. Again same procedure, I uploaded my ssh public key to GitHub and oc fails to build with the same error. So to this point it's not a problem related to either BitBucket or GitHub anymore, there must be something that has to do with the way OpenShift or Git recognizes the keys, if not even my machine...

Edit 3: I wanted to point out that the command oc patch buildConfig <app> -p '{"spec":{"source":{"sourceSecret":{"name":"sshsecret"}}}}' has no value, since I ran it after the app creation and then rebuilt the app with oc start-build --from-build=<app>-1 immediately afterwards, but it fails again with the same result. I'm also not sure if the previous command is the right one to rebuild the app correctly.

Any help will be appreciated a lot, thanks in advance.


Solution

  • Solved. I just created a new secret connected to a new key with

    oc secrets new-sshauth sshsecret2 --ssh-privatekey=$HOME/.ssh/id_rsa
    

    so changing the name from sshsecret to sshsecret2 and repeated the above process. Apparently the previous secret was not configured properly.

    I would also like to thank the Upwork freelancer Dwi Prihandi for having contributed to the problem.