name: cloudmonkey
version: git
summary: Apache CloudStack CLI
description: |
  An CLI and interactive shell that simplifies configuration and management of
  Apache CloudStack, the opensource IAAS cloud computing platform.

base: core18
license: Apache-2.0
grade: stable
confinement: strict

apps:
  cloudmonkey:
    command: bin/cmk
    plugs:
    - home
    - network

parts:
  cloudmonkey:
    source: .
    source-type: git
    source-tag: 6.1.0
    plugin: go
    go-importpath: github.com/apache/cloudstack-cloudmonkey
    build-packages:
      - gcc
      - make
      - file
      - git
    override-build: |
      set -eu
      go version
      go mod vendor
      git checkout -- .
      git status
      git rev-parse HEAD
      go build -mod=vendor -ldflags="-s -w -X main.GitSHA=$(git rev-parse --short HEAD) -X main.BuildDate=$(date +%FT%T%z)" -o cmk cmk.go
      file cmk
      chmod +x cmk
      ./cmk -v
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin
      mv cmk $SNAPCRAFT_PART_INSTALL/bin/
      strip --remove-section=.comment --remove-section=.note $SNAPCRAFT_PART_INSTALL/bin/cmk
