Skip to content

Commit 6df68a4

Browse files
authored
Merge pull request #445 from hellofresh/patch/simplified-build
EES-574 Simplified application build
2 parents 49b5ce3 + d17035b commit 6df68a4

File tree

6 files changed

+24
-34
lines changed

6 files changed

+24
-34
lines changed

Makefile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ OK_COLOR=\033[32;01m
33
ERROR_COLOR=\033[31;01m
44
WARN_COLOR=\033[33;01m
55

6-
# The import path is the unique absolute name of your repository.
7-
# All subpackages should always be imported as relative to it.
8-
# If you change this, run `make clean`.
9-
PKG_SRC := github.com/hellofresh/janus
6+
.PHONY: all lint test-unit test-integration test-features build
107

11-
.PHONY: all clean lint test-unit build
12-
13-
all: clean lint test-unit test-integration test-features lint build
8+
all: test-unit build
149

1510
build:
1611
@echo "$(OK_COLOR)==> Building... $(NO_COLOR)"
17-
@/bin/sh -c "JANUS_BUILD_ONLY_DEFAULT=$(JANUS_BUILD_ONLY_DEFAULT) PKG_SRC=$(PKG_SRC) VERSION=$(VERSION) ./build/build.sh"
12+
@/bin/sh -c "JANUS_BUILD_ONLY_DEFAULT=$(JANUS_BUILD_ONLY_DEFAULT) VERSION=$(VERSION) ./build/build.sh"
1813

1914
test-unit:
2015
@echo "$(OK_COLOR)==> Running unit tests$(NO_COLOR)"
@@ -25,17 +20,12 @@ test-integration: _mocks
2520
@go test -cover -tags=integration -coverprofile=coverage.txt -covermode=atomic ./...
2621

2722
test-features: _mocks
28-
@/bin/sh -c "JANUS_BUILD_ONLY_DEFAULT=1 PKG_SRC=$(PKG_SRC) ./build/build.sh"
23+
@/bin/sh -c "JANUS_BUILD_ONLY_DEFAULT=1 ./build/build.sh"
2924
@/bin/sh -c "./build/features.sh"
3025

3126
lint:
3227
@echo "$(OK_COLOR)==> Linting with golangci-lint running in docker container$(NO_COLOR)"
3328
@docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.30.0 golangci-lint run -v
3429

35-
clean:
36-
@echo "$(OK_COLOR)==> Cleaning project$(NO_COLOR)"
37-
@go clean
38-
@rm -rf bin $GOPATH/bin
39-
4030
_mocks:
4131
@/bin/sh -c "./build/mocks.sh"

build/build.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ rm -f dist/janus*
77

88
# Check if VERSION variable set and not empty, otherwise set to default value
99
if [ -z "$VERSION" ]; then
10-
VERSION="0.0.1-dev"
10+
VERSION="0.0.1-dev"
1111
fi
1212
echo "Building application version $VERSION"
1313

1414
echo "Building default binary"
15-
CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X github.com/hellofresh/janus/cmd.version=${VERSION}" -o "dist/janus" $PKG_SRC
15+
CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X main.version=${VERSION}" -o "dist/janus"
1616

1717
if [ ! -z "${JANUS_BUILD_ONLY_DEFAULT}" ]; then
1818
echo "Only default binary was requested to build"
@@ -23,18 +23,18 @@ fi
2323
OS_PLATFORM_ARG=(linux darwin windows freebsd openbsd)
2424
OS_ARCH_ARG=(386 amd64)
2525
for OS in ${OS_PLATFORM_ARG[@]}; do
26-
for ARCH in ${OS_ARCH_ARG[@]}; do
27-
echo "Building binary for $OS/$ARCH..."
28-
GOARCH=$ARCH GOOS=$OS CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X github.com/hellofresh/janus/cmd.version=${VERSION}" -o "dist/janus_$OS-$ARCH" $PKG_SRC
29-
done
26+
for ARCH in ${OS_ARCH_ARG[@]}; do
27+
echo "Building binary for $OS/$ARCH..."
28+
GOARCH=$ARCH GOOS=$OS CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X main.version=${VERSION}" -o "dist/janus_$OS-$ARCH"
29+
done
3030
done
3131

3232
# Build arm binaries
3333
OS_PLATFORM_ARG=(linux)
3434
OS_ARCH_ARG=(arm arm64)
3535
for OS in ${OS_PLATFORM_ARG[@]}; do
36-
for ARCH in ${OS_ARCH_ARG[@]}; do
37-
echo "Building binary for $OS/$ARCH..."
38-
GOARCH=$ARCH GOOS=$OS CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X main.version=${VERSION}" -o "dist/janus_$OS-$ARCH" $PKG_SRC
39-
done
36+
for ARCH in ${OS_ARCH_ARG[@]}; do
37+
echo "Building binary for $OS/$ARCH..."
38+
GOARCH=$ARCH GOOS=$OS CGO_ENABLED=0 go build -ldflags "-s -w" -ldflags "-X main.version=${VERSION}" -o "dist/janus_$OS-$ARCH"
39+
done
4040
done

cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
var configFile string
1010

1111
// NewRootCmd creates a new instance of the root command
12-
func NewRootCmd() *cobra.Command {
12+
func NewRootCmd(version string) *cobra.Command {
1313
ctx := context.Background()
1414

1515
cmd := &cobra.Command{
@@ -26,8 +26,8 @@ Complete documentation is available at https://hellofresh.gitbooks.io/janus`,
2626
cmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "Config file (default is $PWD/janus.toml)")
2727

2828
cmd.AddCommand(NewCheckCmd(ctx))
29-
cmd.AddCommand(NewVersionCmd(ctx))
30-
cmd.AddCommand(NewServerStartCmd(ctx))
29+
cmd.AddCommand(NewVersionCmd(ctx, version))
30+
cmd.AddCommand(NewServerStartCmd(ctx, version))
3131

3232
return cmd
3333
}

cmd/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ type ServerStartOptions struct {
3333
}
3434

3535
// NewServerStartCmd creates a new http server command
36-
func NewServerStartCmd(ctx context.Context) *cobra.Command {
36+
func NewServerStartCmd(ctx context.Context, version string) *cobra.Command {
3737
opts := &ServerStartOptions{}
3838

3939
cmd := &cobra.Command{
4040
Use: "start",
4141
Short: "Starts a Janus web server",
4242
RunE: func(cmd *cobra.Command, args []string) error {
43-
return RunServerStart(ctx, opts)
43+
return RunServerStart(ctx, opts, version)
4444
},
4545
}
4646

@@ -51,7 +51,7 @@ func NewServerStartCmd(ctx context.Context) *cobra.Command {
5151
}
5252

5353
// RunServerStart is the run command to start Janus
54-
func RunServerStart(ctx context.Context, opts *ServerStartOptions) error {
54+
func RunServerStart(ctx context.Context, opts *ServerStartOptions, version string) error {
5555
// all the logging configurations are initialised in initLog() later,
5656
// but we try to initialise Writer (STDIN/STDERR/etc.) as early as possible manually
5757
// to avoid loosing logs in systems heavily relying on them (e.g. running in docker)

cmd/version.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9-
var version = "0.0.0-dev"
10-
119
// NewVersionCmd creates a new version command
12-
func NewVersionCmd(ctx context.Context) *cobra.Command {
10+
func NewVersionCmd(ctx context.Context, version string) *cobra.Command {
1311
return &cobra.Command{
1412
Use: "version",
1513
Short: "Print the version information",

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
log "github.com/sirupsen/logrus"
88
)
99

10+
var version = "0.0.0-dev"
11+
1012
func main() {
11-
rootCmd := cmd.NewRootCmd()
13+
rootCmd := cmd.NewRootCmd(version)
1214

1315
if err := rootCmd.Execute(); err != nil {
1416
log.WithError(err).Error(err.Error())

0 commit comments

Comments
 (0)