#!/usr/bin/env bash set -e PROJECT_NAME=packer DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIST_DIR="$DIR/../dist" rm -rf "$DIST_DIR" mkdir -p "$DIST_DIR" function build { local version=$(get_version) local dir_name="$PROJECT_NAME-${2}-${version}-${GOOS}-${GOARCH}${GOARM}" local dest_dir="$DIST_DIR/$dir_name" echo "Building $PROJECT_NAME for ${GOOS}-${GOARCH}${GOARM}..." mkdir "$dest_dir" go build -ldflags="-s -X 'main.projectVersion=${version}' -extldflags '-static'" \ -o "$dest_dir/${PROJECT_NAME}-${2}${FILE_EXT}" \ "${1}" wait cp "$DIR/../README.md" "$dest_dir/" echo "Creating $PROJECT_NAME archive for ${GOOS}-${GOARCH}${GOARM}..." ( cd "$DIST_DIR" && tar -czf "$dir_name.tar.gz" "$dir_name" ) wait } function get_version { local tags=($(git tag -l --points-at HEAD)) if [ ! -z "$tags" ]; then echo ${tags[0]} return fi latest_tag=$( ( git describe --abbrev=0 --tags 2>/dev/null || exit ) ) local latest_branch_commit=$(git log --pretty=format:'%h' -n 1) echo "${latest_tag:-0.0.0}-dev+rev.$latest_branch_commit" } dep ensure -v export CGO_ENABLED=0 export GO_EXTLINK_ENABLED=0 if [ -z "${GOOS}" ] && [ -z "${GOARCH}" ]; then FILE_EXT= GOOS=linux GOARCH=amd64 build ./cmd/post-processor/image-template post-processor-opennebula-image-template FILE_EXT= GOOS=linux GOARCH=386 build ./cmd/post-processor/image-template post-processor-opennebula-image-template FILE_EXT= GOOS=linux GOARCH=arm GOARM=7 build ./cmd/post-processor/image-template post-processor-opennebula-image-template else build ./cmd/server ./cmd/post-processor/image-template post-processor-opennebula-image-template fi