kind: pipeline
type: kubernetes
name: Build & Push Images

trigger:
  branch:
    - trunk
  event:
    - push

steps:
  - name: Build & Publish Catalog
    image: git.vdhsn.com/barretthousen/drone-kaniko:v1.0.1
    volumes:
      - name: cache
        path: /kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.prod-backend"
      context: "./src"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/service-catalog
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      skip_unused_stages: true
      build_args:
        - "service=catalog"
      tags:
        - ${DRONE_COMMIT_SHA}
        - beta
      custom_labels:
        - com.barretthousen.service=catalog
        - com.barretthousen.version=${DRONE_COMMIT_SHA}
        - com.barretthousen.git-ref=${DRONE_COMMIT_SHA}
        - com.barretthousen.build-date=${DRONE_BUILD_STARTED}
        - com.barrethousen.builder=${DRONE_COMMIT_AUTHOR}
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD

  - name: Build & Publish Runner
    image: plugins/kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.prod-backend"
      context: "./src"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/service-runner
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      snapshot_mode: redo
      skip_unused_stages: true
      build_args:
        - "service=runner"
      tags:
        - ${DRONE_COMMIT_SHA}
      custom_labels:
        - com.barretthousen.service=runner
        - com.barretthousen.version=${DRONE_COMMIT_SHA}
        - com.barretthousen.git-ref=${DRONE_COMMIT_SHA}
        - com.barretthousen.build-date=${DRONE_BUILD_STARTED}
        - com.barrethousen.builder=${DRONE_COMMIT_AUTHOR}
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD

  - name: Build & Publish Auth
    image: plugins/kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.prod-backend"
      context: "./src"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/service-auth
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      snapshot_mode: redo
      skip_unused_stages: true
      build_args:
        - "service=auth"
      tags:
        - ${DRONE_COMMIT_SHA}
        - beta
      custom_labels:
        - com.barretthousen.service=auth
        - com.barretthousen.version=${DRONE_COMMIT_SHA}
        - com.barretthousen.git-ref=${DRONE_COMMIT_SHA}
        - com.barretthousen.build-date=${DRONE_BUILD_STARTED}
        - com.barrethousen.builder=${DRONE_COMMIT_AUTHOR}
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD

  - name: Build & Publish Proxy Admin
    image: plugins/kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.prod-backend"
      context: "./src"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/service-proxy-admin
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      snapshot_mode: redo
      skip_unused_stages: true
      build_args:
        - "service=proxy-admin"
      tags:
        - ${DRONE_COMMIT_SHA}
        - beta
      custom_labels:
        - com.barretthousen.service=proxy-admin
        - com.barretthousen.version=${DRONE_COMMIT_SHA}
        - com.barretthousen.git-ref=${DRONE_COMMIT_SHA}
        - com.barretthousen.build-date=${DRONE_BUILD_STARTED}
        - com.barrethousen.builder=${DRONE_COMMIT_AUTHOR}
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD
    depends_on:
      - Build & Publish Catalog
      - Build & Publish Runner
      - Build & Publish Auth

  - name: Build & Publish Proxy Web
    image: plugins/kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.prod-backend"
      context: "./src"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/service-proxy-web
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      snapshot_mode: redo
      skip_unused_stages: true
      build_args:
        - "service=proxy-web"
      tags:
        - ${DRONE_COMMIT_SHA}
        - beta
      custom_labels:
        - com.barretthousen.service=proxy-web
        - com.barretthousen.version=${DRONE_COMMIT_SHA}
        - com.barretthousen.git-ref=${DRONE_COMMIT_SHA}
        - com.barretthousen.build-date=${DRONE_BUILD_STARTED}
        - com.barrethousen.builder=${DRONE_COMMIT_AUTHOR}
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD
    depends_on:
      - Build & Publish Catalog
      - Build & Publish Runner
      - Build & Publish Auth

  - name: Build & Publish Web Client
    image: plugins/kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.frontend"
      context: "./src/web-client"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/service-proxy-web
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      snapshot_mode: redo
      skip_unused_stages: true
      build_args:
        - "service=proxy-web"
      tags:
        - ${DRONE_COMMIT_SHA}
        - beta
      custom_labels:
        - com.barretthousen.service=proxy-web
        - com.barretthousen.version=${DRONE_COMMIT_SHA}
        - com.barretthousen.git-ref=${DRONE_COMMIT_SHA}
        - com.barretthousen.build-date=${DRONE_BUILD_STARTED}
        - com.barrethousen.builder=${DRONE_COMMIT_AUTHOR}
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD
    depends_on:
      - Build & Publish Catalog
      - Build & Publish Runner
      - Build & Publish Auth
      - Build & Publish Proxy Admin
      - Build & Publish Proxy Web

  - name: Build & Publish Admin Client
    image: plugins/kaniko
    settings:
      verbosity: debug
      dockerfile: "./src/Dockerfile.frontend"
      context: "./src/admin-client"
      target: production
      registry: git.vdhsn.com
      repo: git.vdhsn.com/barretthousen/client-admin-client
      enable_cache: true
      cache_repo: git.vdhsn.com/barretthousen/ci-cache
      snapshot_mode: redo
      skip_unused_stages: true
      build_args:
        - "service=admin-client"
      tags:
        - ${DRONE_COMMIT_SHA}
        - beta
      username:
        from_secret: DOCKER_USERNAME
      password:
        from_secret: DOCKER_PASSWORD
    depends_on:
      - Build & Publish Catalog
      - Build & Publish Runner
      - Build & Publish Auth
      - Build & Publish Proxy Admin
      - Build & Publish Proxy Web

  - name: Build Success Notify
    image: appleboy/drone-discord
    environment:
      DISCORD_WEBHOOK_ID:
        from_secret: DISCORD_WEBHOOK_ID
      DISCORD_WEBHOOK_TOKEN:
        from_secret: DISCORD_WEBHOOK_TOKEN
    settings:
      username: Drone CI
      message: Barretthousen Image Builds Complete
      webhook_id:
        from_secret: DISCORD_WEBHOOK_ID
      webhook_token:
        from_secret: DISCORD_WEBHOOK_TOKEN
    depends_on:
      - Build & Publish Catalog
      - Build & Publish Runner
      - Build & Publish Auth
      - Build & Publish Proxy Admin
      - Build & Publish Proxy Web
      - Build & Publish Web Client
      - Build & Publish Admin Client
---
kind: pipeline
type: kubernetes
name: Promote Beta -> Prod

trigger:
  branch:
    - trunk
  event:
    - promote

steps:
  - name: Promote Services
    image: alpine
    environment:
      REGISTRY_NAME: "https://git.vdhsn.com"
      CONTENT_TYPE: "application/vnd.docker.distribution.manifest.v2+json"
      DOCKER_USERNAME:
        from_secret: DOCKER_USERNAME
      DOCKER_PASSWORD:
        from_secret: DOCKER_PASSWORD
    commands:
      - ./hack/promote.sh barretthousen/catalog beta prod

  - name: Deploy Success
    image: appleboy/drone-discord
    environment:
      DISCORD_WEBHOOK_ID:
        from_secret: DISCORD_WEBHOOK_ID
      DISCORD_WEBHOOK_TOKEN:
        from_secret: DISCORD_WEBHOOK_TOKEN
    settings:
      username: Drone CI
      message: Barretthousen Prod deployment success
      webhook_id:
        from_secret: DISCORD_WEBHOOK_ID
      webhook_token:
        from_secret: DISCORD_WEBHOOK_TOKEN
    depends_on:
      - Promote Services

volumes:
- name: cache
  temp:
    medium: memory
