Skip to content

Latest commit

 

History

History
85 lines (76 loc) · 3.04 KB

deployment-droneci.md

File metadata and controls

85 lines (76 loc) · 3.04 KB

Golang Deployment - Deployment with DroneCI 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-droneci.yml

kind: pipeline
type: docker
name: bookstore

platform:
  os: linux
  arch: amd64

steps:
  - name: build
    image: golang:1.19.5
    commands:
      - go mod download
      - if [ "${DRONE_BRANCH}" = "main" ]; then
          semver=1.0.0-${DRONE_COMMIT_SHA:0:8};
        elif [[ "${DRONE_BRANCH}" == "features/"* ]]; then
          semver=1.0.0-${DRONE_BRANCH#features/}.${DRONE_COMMIT_SHA:0:8};
        elif [[ "${DRONE_BRANCH}" == "bugfix/"* ]]; then
          semver=1.1.0-${DRONE_BRANCH#bugfix/}.${DRONE_COMMIT_SHA:0:8};
        elif [[ "${DRONE_BRANCH}" == "hotfix/"* ]]; then
          semver=1.1.1-${DRONE_BRANCH#hotfix/}.${DRONE_COMMIT_SHA:0:8};
        fi
      - echo "Semantic version: $semver"
      - docker build -t ${PLUGIN_REGISTRY}/${PLUGIN_REPO}:${semver} .
      - docker tag ${PLUGIN_REGISTRY}/${PLUGIN_REPO}:${semver} ${PLUGIN_REGISTRY}/${PLUGIN_REPO}:latest
    environment:
      - PLUGIN_REGISTRY=your-registry-url
      - PLUGIN_REPO=bookstore
    when:
      event:
        - push
        - tag

  - name: publish
    image: plugins/ecr
    settings:
      region: ap-southeast-1
      access_key:
        from_secret: aws_access_key
      secret_key:
        from_secret: aws_secret_key
      repo: ${PLUGIN_REGISTRY}/${PLUGIN_REPO}
      tags: latest,${semver}
    when:
      event:
        - push
        - tag

  - name: deploy
    image: dtzar/helm-kubectl
    settings:
      kubernetes_server: your-kubernetes-server
      kubernetes_cert:
        from_secret: kubernetes_cert
      kubernetes_token:
        from_secret: kubernetes_token
      kubernetes_namespace: bookstore
      command: helmfile sync
    when:
      event:
        - push
        - tag