Skip to content

Instantly share code, notes, and snippets.

@vahanNasibyan
Created November 5, 2018 10:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vahanNasibyan/297a257f8e850e735a73f2aea03411da to your computer and use it in GitHub Desktop.
Save vahanNasibyan/297a257f8e850e735a73f2aea03411da to your computer and use it in GitHub Desktop.
pipelines
pipelines:
default:
- step:
script:
- echo "I made a pipeline!"
tags: # add the 'tags' section
release-*: # specify the tag
- step: # define the build pipeline for the tag
#python image with aws-cli installed
image: atlassian/pipelines-awscli
services:
- docker
script:
# aws login
- eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
# docker
- export BUILD_ID=${BITBUCKET_TAG}
- docker build -t ${AWS_REGISTRY_URL}:$BUILD_ID .
- docker push ${AWS_REGISTRY_URL}:$BUILD_ID
hotfix-*: # specify the tag
- step: # define the build pipeline for the tag
#python image with aws-cli installed
image: atlassian/pipelines-awscli
services:
- docker
script:
# aws login
- eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
# docker
- export BUILD_ID=${BITBUCKET_TAG}
- docker build -t ${AWS_REGISTRY_URL}:$BUILD_ID .
- docker push ${AWS_REGISTRY_URL}:$BUILD_ID
feature-*: # specify the tag
- step: # define the build pipeline for the tag
#python image with aws-cli installed
image: atlassian/pipelines-awscli
services:
- docker
script:
# aws login
- eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
# docker
- export BUILD_ID=${BITBUCKET_TAG}
- docker build -t ${AWS_REGISTRY_URL}:$BUILD_ID .
- docker push ${AWS_REGISTRY_URL}:$BUILD_ID
branches:
master:
- step:
#python image with aws-cli installed
image: atlassian/pipelines-awscli
services:
- docker
script:
# aws login
- eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
# docker
- export BUILD_ID=$BITBUCKET_BRANCH.$BITBUCKET_COMMIT
- export BUILD_LATEST=$BITBUCKET_BRANCH.latest
- docker build -t ${AWS_REGISTRY_URL}:$BUILD_ID .
- docker push ${AWS_REGISTRY_URL}:$BUILD_ID
- docker tag ${AWS_REGISTRY_URL}:$BUILD_ID ${AWS_REGISTRY_URL}:$BUILD_LATEST
- docker push ${AWS_REGISTRY_URL}:$BUILD_LATEST
stage:
- step:
#python image with aws-cli installed
image: atlassian/pipelines-awscli
services:
- docker
script:
# aws login
- eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
# docker
- export BUILD_ID=$BITBUCKET_BRANCH.$BITBUCKET_COMMIT
- export BUILD_LATEST=$BITBUCKET_BRANCH.latest
- docker build -t ${AWS_REGISTRY_URL}:$BUILD_ID .
- docker push ${AWS_REGISTRY_URL}:$BUILD_ID
- docker tag ${AWS_REGISTRY_URL}:$BUILD_ID ${AWS_REGISTRY_URL}:$BUILD_LATEST
- docker push ${AWS_REGISTRY_URL}:$BUILD_LATEST
develop:
- step:
#python image with aws-cli installed
image: atlassian/pipelines-awscli
services:
- docker
script:
# aws login
- eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
# docker
- export BUILD_ID=$BITBUCKET_BRANCH.$BITBUCKET_COMMIT
- export BUILD_LATEST=$BITBUCKET_BRANCH.latest
- docker build -t ${AWS_REGISTRY_URL}:$BUILD_ID .
- docker push ${AWS_REGISTRY_URL}:$BUILD_ID
- docker tag ${AWS_REGISTRY_URL}:$BUILD_ID ${AWS_REGISTRY_URL}:$BUILD_LATEST
- docker push ${AWS_REGISTRY_URL}:$BUILD_LATEST
@dapseen
Copy link

dapseen commented Nov 4, 2019

Great stuff here, i feel there are better ways to DRY, by making use of anchor features on bitbucket


   - step: &Go-test
        name: Static code Testing
        script:
          - source bitbucket-pipeline.sh
          - go build .
    - step: &Deploy-ECR
        name: Deploy to ECR
        image: atlassian/pipelines-awscli
        deployment: staging
        services:
          - docker
        script:
          - echo "build step"
        #before this,i created a repo on ECR via aws CLI (ajocardengineering/ajocard-wallet-service)
          # aws login
          - eval $(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)
          # docker
          - echo $REPO_NAME
          - docker build -t ${BITBUCKET_REPO_OWNER}/${REPO_NAME}:$BITBUCKET_BUILD_NUMBER .
          - docker tag ${BITBUCKET_REPO_OWNER}/${REPO_NAME}:$BITBUCKET_BUILD_NUMBER ${AWS_REGISTRY_URL}/${REPO_NAME}:${BITBUCKET_BUILD_NUMBER}
          #the image is created during build and tagged are only pushed to ECR repo, this is due to the unique registry URL and region.
          - docker push ${AWS_REGISTRY_URL}/${REPO_NAME}:${BITBUCKET_BUILD_NUMBER}

-------------------------------

pipelines:
    pull-requests:
        '**': # this runs as default for any branch not elsewhere defined
            - step: *Go-test
    branches:
      staging:
        - step: 
          <<: *Deploy-ECR
          name: Deploy to ECR staging
          Deployment: staging 


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment