Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ can be used with Apache CloudStack 4.0-incubating and above.

For documentation, kindly see the [wiki](https://github.com/apache/cloudstack-cloudmonkey/wiki).

[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/cloudmonkey)

### Development

To develop CloudMonkey, you need Go 1.11 or later and a unix-like
Expand Down
72 changes: 44 additions & 28 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
name: cloudmonkey
version: git
# define the tag anchor on the allowed 'version' field
version: &release_tag 6.4.0
summary: Apache CloudStack CLI
description: |
An CLI and interactive shell that simplifies configuration and management of
A CLI and interactive shell that simplifies configuration and management of
Apache CloudStack, the opensource IAAS cloud computing platform.

base: core18
base: core22
license: Apache-2.0
grade: stable
confinement: strict
adopt-info: cloudmonkey

apps:
cloudmonkey:
command: bin/cmk
plugs:
- home
- network
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
source: &cmk_repo https://github.com/apache/cloudstack-cloudmonkey.git
source-type: git
source-tag: *release_tag
source-depth: 1

build-snaps: [go]
build-packages: [git, file, binutils]

build-environment:
- CMK_REPO: *cmk_repo
- CMK_TAG: *release_tag

override-pull: |
set -euo pipefail
craftctl default
REPO="${CMK_REPO}"
TAG="${CMK_TAG}"
# Try to get the dereferenced commit for annotated tags first
FULL_SHA="$(git ls-remote "${REPO}" "refs/tags/${TAG}^{}" | awk '{print $1}')"
# If not found, fall back to the tag object itself
if [ -z "${FULL_SHA}" ]; then
FULL_SHA="$(git ls-remote "${REPO}" "refs/tags/${TAG}" | awk '{print $1}')"
fi
SHORT_SHA="${FULL_SHA:0:7}"
: "${SHORT_SHA:=unknown}"
echo "${SHORT_SHA}" > "$CRAFT_PART_SRC/.remote-sha"
craftctl set version="${TAG}-${SHORT_SHA}"

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
set -euo pipefail
cd "$CRAFT_PART_SRC"
SHORT_SHA="$(cat .remote-sha 2>/dev/null || echo unknown)"
BUILD_DATE="$(date +%FT%T%z)"
go mod vendor || true
go build -trimpath \
-ldflags "-s -w -X main.GitSHA=${SHORT_SHA} -X main.BuildDate=${BUILD_DATE}" \
-o cmk cmk.go
install -Dm0755 cmk "$CRAFT_PART_INSTALL/bin/cmk"
strip --remove-section=.comment --remove-section=.note "$CRAFT_PART_INSTALL/bin/cmk" || true