diff --git a/docker/multistage/Dockerfile b/docker/multistage/Dockerfile index a7f783d..417ba0a 100644 --- a/docker/multistage/Dockerfile +++ b/docker/multistage/Dockerfile @@ -1,12 +1,11 @@ # Builds Request Baskets service using multi-stage builds -# Version 1.1 +# Version 1.2 # Stage 1. Building service FROM golang:latest as builder WORKDIR /go/src/rbaskets COPY . . -RUN set -e \ - && GIT_VERSION="$(git describe)" \ +RUN GIT_VERSION="$(git describe || git symbolic-ref -q --short HEAD)" \ && GIT_COMMIT="$(git rev-parse HEAD)" \ && GIT_COMMIT_SHORT="$(git rev-parse --short HEAD)" \ && set -x \ diff --git a/build.sh b/scripts/build/build.sh similarity index 59% rename from build.sh rename to scripts/build/build.sh index fe98cd1..fd66754 100755 --- a/build.sh +++ b/scripts/build/build.sh @@ -3,12 +3,14 @@ # exit if any step fails set -e -# change current dir to the script dir +# change current dir to the script dir and then switch to project root cd "$(dirname "$0")" +cd ../.. +# collect git version information GIT_VERSION="$(git describe)" GIT_COMMIT="$(git rev-parse HEAD)" GIT_COMMIT_SHORT="$(git rev-parse --short HEAD)" -# build service with version information +# build (and install) service with version information from project root for default architecture go get -ldflags "-X main.GitVersion=${GIT_VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.GitCommitShort=${GIT_COMMIT_SHORT}" diff --git a/scripts/build/build_docker.sh b/scripts/build/build_docker.sh new file mode 100755 index 0000000..3c67dad --- /dev/null +++ b/scripts/build/build_docker.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# change current dir to the script dir and then switch to project root +cd "$(dirname "$0")" +cd ../.. + +# build docker container from project root +docker build -t request-baskets . diff --git a/scripts/build/build_linux.sh b/scripts/build/build_linux.sh new file mode 100755 index 0000000..a7bf9c1 --- /dev/null +++ b/scripts/build/build_linux.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# exit if any step fails +set -e + +# change current dir to the script dir and then switch to project root +cd "$(dirname "$0")" +cd ../.. + +# collect git version information +GIT_VERSION="$(git describe)" +GIT_COMMIT="$(git rev-parse HEAD)" +GIT_COMMIT_SHORT="$(git rev-parse --short HEAD)" + +# build service with version information from project root for Linux +env GOOS=linux GOARCH=amd64 go build -ldflags "-X main.GitVersion=${GIT_VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.GitCommitShort=${GIT_COMMIT_SHORT}"