Skip to content

Commit

Permalink
Update .gitignore and Makefile
Browse files Browse the repository at this point in the history
- Add *.yaml and README.pdf to .gitignore
- Update PLATFORMS variable in Makefile to include darwin/arm64
- Update VERSION variable in Makefile to use git describe --tags --exact-match
- Update docker image tag in docker-build and docker-buildx targets in Makefile
- Remove README.* and $(REPO_NAME)-* binaries in clean target in Makefile
- Add zip target in Makefile to zip binaries with README.pdf
- Update config file parsers in newServeCommand and newRunCommand functions in main.go
- Update go.mod to require gopkg.in/yaml.v2 v2.4.0
  • Loading branch information
igolaizola committed Sep 13, 2024
1 parent c284511 commit 4286ccc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ bin
.history
.vscode
*.conf
*.yaml
README.pdf
28 changes: 18 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/bash

SHELL = /bin/bash
PLATFORMS ?= linux/amd64 darwin/amd64 windows/amd64
PLATFORMS ?= linux/amd64 darwin/amd64 darwin/arm64 windows/amd64
IMAGE_PREFIX ?= igolaizola
REPO_NAME ?= goobar
REPO_NAME ?= goobar
COMMIT_SHORT ?= $(shell git rev-parse --verify --short HEAD)
VERSION ?= $(COMMIT_SHORT)
VERSION_NOPREFIX ?= $(shell echo $(VERSION) | sed -e 's/^[[v]]*//')
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || echo $(COMMIT_SHORT))

# Build the binaries for the current platform
.PHONY: build
Expand All @@ -28,13 +27,14 @@ app-build:
if [ "$$os" == "windows" ]; then \
ext=".exe"; \
fi; \
file=./bin/$(REPO_NAME)-$(VERSION_NOPREFIX)-$$(echo $$platform | tr / -)$$ext; \
file=./bin/$(REPO_NAME)-$(COMMIT_SHORT)-$$(echo $$platform | tr / -)$$ext; \
GOOS=$$os GOARCH=$$arch GOARM=$$arm CGO_ENABLED=0 \
go build \
-a -x -tags netgo,timetzdata -installsuffix cgo -installsuffix netgo \
-ldflags " \
-X main.Version=$(VERSION_NOPREFIX) \
-X main.GitRev=$(COMMIT_SHORT) \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT_SHORT) \
-X main.date=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
" \
-o $$file \
./cmd/$(REPO_NAME); \
Expand All @@ -55,7 +55,7 @@ docker-build:
echo "Multi-arch build not supported"; \
exit 1; \
fi; \
docker build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(VERSION) .; \
docker build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(COMMIT_SHORT) .; \
if [ $$? -ne 0 ]; then \
exit 1; \
fi
Expand All @@ -66,9 +66,17 @@ docker-build:
docker-buildx:
@platforms=($(PLATFORMS)); \
platform=$$(IFS=, ; echo "$${platforms[*]}"); \
docker buildx build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(VERSION) .
docker buildx build --platform $$platform -t $(IMAGE_PREFIX)/$(REPO_NAME):$(COMMIT_SHORT) .

# Clean binaries
.PHONY: clean
clean:
rm -rf bin
rm -rf bin/README.*
rm -rf bin/$(REPO_NAME)-*

# Zip the binaries
.PHONY: zip
zip: clean build
cp README.pdf bin/; \
cd bin; \
zip -r $(REPO_NAME)-$(shell date -u +'%Y%m%d-%H%M').zip README.pdf $(REPO_NAME)-*; \
5 changes: 3 additions & 2 deletions cmd/goobar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/igolaizola/goobar"
"github.com/peterbourgon/ff/v3"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/peterbourgon/ff/v3/ffyaml"
)

// Build flags
Expand Down Expand Up @@ -90,7 +91,7 @@ func newServeCommand() *ffcli.Command {
ShortUsage: fmt.Sprintf("goobar %s [flags] <key> <value data...>", cmd),
Options: []ff.Option{
ff.WithConfigFileFlag("config"),
ff.WithConfigFileParser(ff.PlainParser),
ff.WithConfigFileParser(ffyaml.Parser),
ff.WithEnvVarPrefix("GOOBAR"),
},
ShortHelp: fmt.Sprintf("goobar %s command", cmd),
Expand All @@ -114,7 +115,7 @@ func newRunCommand() *ffcli.Command {
ShortUsage: fmt.Sprintf("goobar %s [flags] <key> <value data...>", cmd),
Options: []ff.Option{
ff.WithConfigFileFlag("config"),
ff.WithConfigFileParser(ff.PlainParser),
ff.WithConfigFileParser(ffyaml.Parser),
ff.WithEnvVarPrefix("GOOBAR"),
},
ShortHelp: fmt.Sprintf("goobar %s command", cmd),
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ module github.com/igolaizola/goobar
go 1.22

require github.com/peterbourgon/ff/v3 v3.3.0

require gopkg.in/yaml.v2 v2.4.0 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
github.com/peterbourgon/ff/v3 v3.3.0 h1:PaKe7GW8orVFh8Unb5jNHS+JZBwWUMa2se0HM6/BI24=
github.com/peterbourgon/ff/v3 v3.3.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

0 comments on commit 4286ccc

Please sign in to comment.