#!/usr/bin/env bash # Copyright (c) 2019 Alex aka mailoman # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # @author Alex aka mailoman # @copyright Copyright (c) 2019 Alex aka mailoman # @since 18.12.2019 path=$(pwd) dir="${path%/*}" path=${dir} repo="${dir##*/}" dir="${dir%/*}" username=${dir##*/} dir="${dir%/*}" domain=${dir##*/} image="go2dep" image_exists=$(docker images|grep ${image}) volume_cache="-v ${path}/.cache:/go/pkg" if [[ -z ${image_exists} ]];then echo "building image ${image}" docker build -t ${image} . fi if [[ ! -d ${path}/vendor ]];then echo "dep init" docker run --rm ${volume_cache} -v ${path}:/go/src/$domain/$username/$repo -w="/go/src/$domain/$username/$repo" ${image} dep init fi echo "Building $domain/$username/$repo/examples/main.go" #buildVersion=$(git tag|tail -n1) #buildHash=$(git log -1 --pretty=format:"%h") #buildTime=$(date) #buildFlags="-X '$domain/$username/$repo/version.BuildVersion=${buildVersion}' -X '$domain/$username/$repo/version.BuildHash=${buildHash}' -X '$domain/$username/$repo/version.BuildTime=${buildTime}'" buildFlags="" echo " build flags: ${buildFlags}" docker run --rm ${volume_cache} -v ${path}:/go/src/$domain/$username/$repo -v ${path}/bin:/go/bin -w="/go/src/$domain/$username/$repo" -e GOOS=linux -e GOARCH=amd64 -e CGO_ENABLED=0 ${image} go build -ldflags="${buildFlags}" -o /go/bin/example-main-x64.linux ./examples/ docker run --rm ${volume_cache} -v ${path}:/go/src/$domain/$username/$repo -v ${path}/bin:/go/bin -w="/go/src/$domain/$username/$repo" -e GOOS=darwin -e GOARCH=amd64 -e CGO_ENABLED=0 ${image} go build -ldflags="${buildFlags}" -o /go/bin/example-main-x64.macos ./examples/ docker run --rm ${volume_cache} -v ${path}:/go/src/$domain/$username/$repo -v ${path}/bin:/go/bin -w="/go/src/$domain/$username/$repo" -e GOOS=windows -e GOARCH=amd64 -e CGO_ENABLED=0 ${image} go build -ldflags="${buildFlags}" -o /go/bin/example-main-x64.exe ./examples/