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?

Stradosphere
  • 103
  • 4

1 Answers1

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.
Bruce Becker
  • 3,783
  • 4
  • 20
  • 41