Skip to content

Latest commit

 

History

History
57 lines (52 loc) · 2.94 KB

deployment-bitbucket.md

File metadata and controls

57 lines (52 loc) · 2.94 KB

Golang Deployment - Deployment with Bitbucket Pipeline

Kubernetes Deployment for Simple Golang API

goreport all contributors tags docker pulls download all view clone issues pull requests forks stars license


Example CI/CD Script cicd-bitbucket.yml

pipelines:
  default:
    - step:
        name: Build and Deploy
        image: golang:1.17
        script:
          - go build -o app
          - |
            if [[ "$BITBUCKET_BRANCH" == "features/"* ]]; then
              semver=1.0.0-${BITBUCKET_BRANCH#features/}.${BITBUCKET_COMMIT:0:8}
            elif [[ "$BITBUCKET_BRANCH" == "bugfix/"* ]]; then
              semver=1.1.0-${BITBUCKET_BRANCH#bugfix/}.${BITBUCKET_COMMIT:0:8}
            elif [[ "$BITBUCKET_BRANCH" == "hotfix/"* ]]; then
              semver=1.1.1-${BITBUCKET_BRANCH#hotfix/}.${BITBUCKET_COMMIT:0:8}
            fi
            echo "Semantic version: $semver"
            echo "imageTag=$semver" >> $BITBUCKET_CLONE_DIR/variables.env
            aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
            docker build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME:$semver .
            docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME:$semver
            docker tag $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME:$semver $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME:latest
            docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_NAME:latest
          artifacts:
            - app
        services:
          - docker
        caches:
          - docker
          - go
        deployment: production
        trigger: manual
        environment:
          name: production
          url: $BITBUCKET_DEPLOYMENT_ENVIRONMENT_URL