Skip to content

Commit

Permalink
Make r10edocker version more easily set (#10)
Browse files Browse the repository at this point in the history
* Make r10edocker version more easily set

We make the version of `r10edocker` more easily overridable during
build, which reduces the amount of error-prone manual work to allow
better automation.

* Un-dockerignore the .git directory

We need to get the .git directory copied to Docker builder for the version info.

* Update release.yml

With the latest changes, released app version should always be identical
to the tagged version. Therefore, we update the version check failure
message as if it's an assert.
  • Loading branch information
syncom authored Oct 29, 2022
1 parent 3a86367 commit cd50f80
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ r10e-docker/out/
build/
r10e-build/
.github/
.git/
CODEOWNERS
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
cd ${{ github.workspace }}
APP_VERSION="$(r10e-build/r10edocker-linux-amd64 --version | rev | cut -f1 -d' ' | rev)"
if [ "$APP_VERSION" != "$RELEASE_VERSION" ]; then
echo "version (${APP_VERSION}) in version/version.go and tagged version (${RELEASE_VERSION}) mismatch"
echo "This is not supposed to happen. There must be a versioning bug."
exit 1
fi
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build_dir := $(mkfile_dir)/build
r10e_build_dir := $(mkfile_dir)/r10e-build
GOOS ?= $(shell go version | awk '{print $$NF}' | cut -d/ -f1)
GOARCH ?= $(shell go version | awk '{print $$NF}' | cut -d/ -f2)
VERSION ?= $(shell git describe --tags --dirty --always)
bin := $(build_dir)/r10edocker-$(GOOS)-$(GOARCH)
# project_name must match that in config.json
project_name := go-r10e-docker
Expand All @@ -15,7 +16,7 @@ all: build

build:
mkdir -p $(build_dir)
CGO_ENABLED=0 go build -trimpath -o $(bin) $(mkfile_dir)
CGO_ENABLED=0 go build -trimpath -ldflags "-X main.version=$(VERSION)" -o $(bin) $(mkfile_dir)

r10e-build: build
cp $(bin) $(build_dir)/r10edocker
Expand Down
9 changes: 4 additions & 5 deletions cmd/r10e-docker/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (

"github.com/spf13/cobra"
r10edocker "github.com/syncom/r10edocker/pkg/r10e-docker"
"github.com/syncom/r10edocker/version"
)

var configFile string

var rootCmd = &cobra.Command{
Use: "r10edocker",
Version: version.Version,
Short: "r10edocer - make minimum, reproducible Docker container for Go application",
Use: "r10edocker",
Short: "r10edocer - make minimum, reproducible Docker container for Go application",
Long: `r10edocker creates a framework for making reproducible Docker container images
Configure r10edocker in JSON.
Expand All @@ -34,7 +32,8 @@ The resulting Docker container is minimum, in that it contains only the applicat
},
}

func Execute() {
func Execute(version string) {
rootCmd.Version = version
if err := rootCmd.Execute(); err != nil {
log.Fatalf("CLI error:, '%s'", err)
}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
r10edocker "github.com/syncom/r10edocker/cmd/r10e-docker"
)

var version = "development"

func main() {
r10edocker.Execute()
r10edocker.Execute(version)
}
3 changes: 0 additions & 3 deletions version/version.go

This file was deleted.

0 comments on commit cd50f80

Please sign in to comment.