0

I was looking to setup automated docker builds when a push is made to our bitbucket server. The only issue is that our Bitbucket is not cloud based, its an on premise private server. Is there a way to configure automated builds for the docker hub when a push is made to our private server? Obviously Docker can't see our private server, but is there a way to accomplish the same thing using web hooks in the private bitbucket repo?

1

I would use a Packer template, specifically with a Docker builder to do this. Triggering this build can be done with hooks (either BitBucket webhooks, or git server post-receive hooks.

Building a Docker image from a Packer template has some benefits, but requires Docker Engine installed - so, doing the build with a Dockerfile would also be an option.

The tricky part would be the management of credentials. Building the image does not require credentials, nor does tagging -- however you need to be authenticated to push the image to the registry. If the build happens on the same server that is hosting BitBucket, you could keep them in a protected file and execute the build via the post-receive hook in a shell script. This would be a lightweight option, especially if the server itself is locked down.

So, in summary :

  1. Install Docker Engine on the BitBucket Server
  2. Write a script which can consume registry username and password, to build the image, either from a Dockerfile or from a Packer template.
  3. Add a server-side git hook to execute this script to build, tag and push the image.
2
  • 1
    Thank you for the response, I will look into leveraging Packer. I understand the process though as you described and I believe it makes sense for my scenario. Jul 25 '19 at 16:18
  • 1
    Glad to be of help :) We typically follow the pattern of having a .pipeline directory, with all of the things necessary for shipping the product- a .travis.yml, a Dockerfile, Packer template, etc. This keeps the code of the app clean, and yet keeps all the configuration for deployment in the same repo. Hope this helps. Jul 25 '19 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.