From 0d308acd5c6f7baf986d7c3a530a846bafddd1ef Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 16 Jul 2020 22:31:02 +0200 Subject: [PATCH] Ajout script/commande de release --- .gitignore | 3 +- Makefile | 7 +++ misc/script/release | 119 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100755 misc/script/release diff --git a/.gitignore b/.gitignore index 29c0e1b..ea84feb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor /data /bin -/.env \ No newline at end of file +/.env +/release \ No newline at end of file diff --git a/Makefile b/Makefile index 80a6fac..b389300 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ deps: generate cd client && npm install go get ./... +client-dist: + cd client && NODE_ENV=production npm run build + up: build-docker docker-compose up @@ -45,6 +48,10 @@ test: hydra-shell: docker-compose exec hydra /bin/sh +.PHONY: release +release: + ./misc/script/release + clean: down rm -rf client/node_modules bin data .env internal/graph/generated internal/graph/server.go rm -rf vendor diff --git a/misc/script/release b/misc/script/release new file mode 100755 index 0000000..2e2c123 --- /dev/null +++ b/misc/script/release @@ -0,0 +1,119 @@ +#!/bin/bash + +set -eo pipefail + +OS_TARGETS=(linux) +ARCH_TARGETS=${ARCH_TARGETS:-amd64 arm 386} + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +PROJECT_DIR="$DIR/../.." + +function build { + + local name=$1 + local srcdir=$2 + local os=$3 + local arch=$4 + + local dirname="$name-$os-$arch" + local destdir="$PROJECT_DIR/release/$dirname" + + rm -rf "$destdir" + mkdir -p "$destdir" + + echo "building $dirname..." + + CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \ + -ldflags="-s -w -X main.GitCommit=$(current_commit_ref) -X main.ProjectVersion=$(current_version)" \ + -gcflags=-trimpath="${PWD}" \ + -asmflags=-trimpath="${PWD}" \ + -o "$destdir/bin/$name" \ + "$srcdir" + + if [ ! -z "$(which upx)" ]; then + upx --best "$destdir/bin/$name" + fi + +} + +function current_commit_ref { + git rev-list -1 HEAD +} + +function current_version { + local latest_tag=$(git describe --abbrev=0 2>/dev/null) + echo ${latest_tag:-0.0.0} +} + +function copy { + + local name=$1 + local os=$2 + local arch=$3 + local src=$4 + local dest=$5 + + local dirname="$name-$os-$arch" + local destdir="$PROJECT_DIR/release/$dirname" + + echo "copying '$src' to '$destdir/$dest'..." + + mkdir -p "$(dirname $destdir/$dest)" + + cp -rfL $src "$destdir/$dest" + +} + +function dump_default_conf { + # Generate and copy configuration file + local command=$1 + local os=$2 + local arch=$3 + local tmp_conf=$(mktemp) + + go run "$PROJECT_DIR/cmd/$command" -dump-config > "$tmp_conf" + copy "$command" $os $arch "$tmp_conf" "$command.conf" + rm -f "$tmp_conf" +} + +function compress { + + local name=$1 + local os=$2 + local arch=$3 + + local dirname="$name-$os-$arch" + local destdir="$PROJECT_DIR/release/$dirname" + + echo "compressing $dirname..." + tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname" +} + +function release_server { + + local os=$1 + local arch=$2 + + build 'server' "$PROJECT_DIR/cmd/server" $os $arch + + dump_default_conf 'server' $os $arch + + copy 'server' $os $arch "$PROJECT_DIR/README.md" "README.md" + copy 'server' $os $arch "$PROJECT_DIR/client/dist" "public" + + compress 'server' $os $arch + +} + +function main { + + make client-dist + + for os in ${OS_TARGETS[@]}; do + for arch in ${ARCH_TARGETS[@]}; do + release_server $os $arch + done + done +} + +main \ No newline at end of file