4

Currently I have a git project in bitbucket that has a web application which is dockerised. I have subsequently created a bitbucket-pipelines.yml file which outlines my entire deployment process.

All of my CI works great, I can build, test and push my production image to the dockerhub registry.

Now to the final stage, deploy. This is where things get messy.

Here's my deploy section of my pipelines config:

image: atlassian/default-image:2

pipelines:
  branches:
    master:

     - step:
          trigger: manual
          deployment: production
          name: Deploy
          services:
            - docker
          script:
            - export IMAGE_VERSION=$BITBUCKET_BUILD_NUMBER
            - export DOCKER_HOST=ssh://root@$IP_ADDRESS
            - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
            - ./cd.sh pull
            - ./cd.sh deploy
            - ./cd.sh migrate
            - ./cd.sh clean

And here is the error from the build:

    + ./cd.sh pull
[240] Failed to execute script docker-compose
Traceback (most recent call last):
  File "site-packages/docker/api/client.py", line 151, in __init__
NameError: name 'SSHAdapter' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 71, in main
  File "compose/cli/main.py", line 124, in perform_command
  File "compose/cli/command.py", line 42, in project_from_options
  File "compose/cli/command.py", line 123, in get_project
  File "compose/cli/command.py", line 94, in get_client
  File "compose/cli/docker_client.py", line 127, in docker_client
  File "site-packages/docker/api/client.py", line 156, in __init__
docker.errors.DockerException: Install paramiko package to enable ssh:// support

I currently have my SSH keys correctly setup so I know that's not the problem. I tested this from my local machine connecting to my staging environment and it worked fine.

I'm guessing this is a limitation in using the default atlassian image? It probably is using an older version of docker or something?

My remote machine basically has docker running on it with only the containers it needs running my services. It doesn't have the git project mounted in or anything.

Does anyone have any idea how to overcome this issue using bitbucket pipelines?

If not, any suggestions on a better deployment strategy?

I'm using docker-compose v3.3.

Thanks.

Mous
  • 131
  • 8

1 Answers1

1

Sorry for the 10 month late replay, I take you came right however, I would recommend putting the ssh onto the server itself and then using something like this to execute the ssh from bitbucket itself

- step:
          name: 'Deploying to QA'
          deployment: qa
          script:
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: '$SSH_USER'
              SERVER: '$SSH_SERVER'
              COMMAND: "sh ./deploy.sh" 

Why don't you install Kubernetes instead? You could get away with installing something like Rancher which is opensource and has a create GUI interface.

EugeneDeWaal
  • 216
  • 2
  • 15