Pipeline using BitBucket and dockerHub

Recently, Attlasian has released a new feature, Pipelines. This allows you to build, run and deploy your projects in a simple and easy way.

How?

In 3 simple steps:

  • Push our code into Git (in this case, Bitbucket)
  • Bitbucket will run the tests tag the images, and push into DockerHub if this success.
  • From AWS we can pull the new image we built.

Configuration

Previous to this configuration, you'll need:

  • A bitbucket account (free) -> BitBucket
  • A dockerhub account (free) -> DockerHub
  • AWS account (free 1st year) -> Amazon AWS

  • Enable Pipelines inside the project's configuration of BitBucket.

  1. Configure project's pipeline to run the test and create the docker-hub image:
options:  
  docker: true

pipelines:  
  default:
    - step:
        script:
          - mvn -B verify  
          - export IMAGE_NAME=$DOCKER_HUB_USERNAME/MyRepo:MyProject:1.0
          - docker build -t $IMAGE_NAME .
          - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
          - docker push $IMAGE_NAME
  1. Configure DockerHub user and psw.

This can be done per project or globally. Settings -> Environment variables:

DOCKER_HUB_USERNAME : your user
DOCKER_HUB_PASSWORD : your psw

Done !

Once you push your code into your repository Pipeline will automatically run and push your code into docker-hub. Later on, you can pull the images from AWS using many alternatives or just using docker-compose