Bitbucket pipelines to docker on DigitalOcean

Hamid Farmani
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 20, 2022

I'm trying to connect my bitbucket project, to a DigitalOcean droplet. 
This is my pipeline.

```

# Template docker-push

# This template allows you to build and push your docker image to a Docker Hub account.
# The workflow allows running tests, code linting and security scans on feature branches (as well as master).
# The docker image will be validated and pushed to the docker registry after the code is merged to master.

# Prerequisites: $DOCKERHUB_USERNAME, $DOCKERHUB_PASSWORD setup as deployment variables

image: atlassian/default-image:3
definitions:
  services:
    docker:
      memory: 3072


pipelines:
  default:
    - parallel:
        - step:
            name: Build and Test
            script:
              - IMAGE_NAME=$BITBUCKET_REPO_SLUG
              - docker build . --file Dockerfile --tag ${IMAGE_NAME}
            services:
              - docker
            caches:
              - docker
        - step:
            name: Lint the Dockerfile
            image: hadolint/hadolint:latest-debian
            script:
              - hadolint Dockerfile
  branches:
    development:
      - step:
          name: Deploy to droplet
          script:
          - export IMAGE_NAME=$USER/$PROJECT:$BITBUCKET_COMMIT
          - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $SSH_USER
              SERVER: $SSH_SERVER
              COMMAND: >
                docker stop $CONTAINERS_TO_STOP
                docker run --publish $SERVER_PORT:$SERVER_PORT --detach $IMAGE_NAME
          services:
          - docker
    master:
      - step:
          name: Build and Test
          script:
            - IMAGE_NAME=$BITBUCKET_REPO_SLUG
            - docker build . --file Dockerfile --tag ${IMAGE_NAME}
            - docker save ${IMAGE_NAME} --output "${IMAGE_NAME}.tar"
          services:
            - docker
          caches:
            - docker
          artifacts:
            - "*.tar"
      - step:
          name: Deploy to Production
          deployment: Production
          script:
            - echo ${DOCKERHUB_PASSWORD} | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
            - IMAGE_NAME=$BITBUCKET_REPO_SLUG
            - docker load --input "${IMAGE_NAME}.tar"
            - VERSION="prod-0.1.${BITBUCKET_BUILD_NUMBER}"
            - IMAGE=${DOCKERHUB_NAMESPACE}/${IMAGE_NAME}
            - docker tag "${IMAGE_NAME}" "${IMAGE}:${VERSION}"
            - docker push "${IMAGE}:${VERSION}"
          services:
            - docker

 

```

When I push to my development branch, I get the following error:

 

unknown flag: --publish
See 'docker stop --help'.
Connection to ${IP} closed.
✖ Execution failed.

 

What am I missing/doing wrong here?

1 answer

1 accepted

0 votes
Answer accepted
Hamid Farmani
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 21, 2022
I changed this section:
          - pipe: atlassian/ssh-run:0.4.1
            variables:
              SSH_USER: $SSH_USER
              SERVER: $SSH_SERVER
              COMMAND: 'docker stop $CONTAINERS_TO_STOP; docker run --publish $SERVER_PORT:$SERVER_PORT --detach $IMAGE_NAME'
AzimLord
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 22, 2023

Can confirm this is working. Not sure why 

 - pipe: atlassian/ssh-run:0.2.2
            variables:
              SSH_USER: $SSH_USER
              SERVER: $SSH_SERVER
              COMMAND: >
                docker stop $CONTAINERS_TO_STOP
                docker run --publish $SERVER_PORT:$SERVER_PORT --detach $IMAGE_NAME

Any idea why this is not working?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events