Skip to content

Commit

Permalink
Update go version, dependencies, build process
Browse files Browse the repository at this point in the history
  • Loading branch information
fydrah committed Nov 6, 2021
1 parent 30bc829 commit eacfed7
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 258 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ jobs:
- name: Check go fmt has been run
run: |
echo 'Check if go fmt has been run'
make gofmt
make go_fmt
[[ "$(git diff --name-only | wc -l)" -eq "0" ]]
- name: Build
run: make build
- name: Build static
run: make build-static
run: make
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM quay.io/fydrah/golang:1.13-alpine AS build
FROM quay.io/fydrah/golang:1.17-alpine3.13 AS build
ARG REPO=github.com/fydrah/loginapp

RUN apk add --no-cache git build-base
COPY . /go/src/${REPO}
WORKDIR /go/src/${REPO}
RUN make build-static
RUN make go_build_static

FROM scratch
ARG REPO=github.com/fydrah/loginapp
Expand Down
85 changes: 48 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Dirs
BUILDDIR := build
BUILDDIR := build
CMDDIR := cmd

# Git
GIT_REPOSITORY := github.com/fydrah/loginapp
GIT_COMMIT_ID := $(shell git log -n 1 --pretty=format:%h)
GIT_TAG := $(shell git describe --tags)
GIT_TAG := $(shell git describe --tags)

# Go
GOFLAGS :=
LDFLAGS = -w -s -X "$(GIT_REPOSITORY)/cmd.GitVersion=$(GIT_TAG)" -X "$(GIT_REPOSITORY)/cmd.GitHash=$(GIT_COMMIT_ID)"
LDFLAGS = -w -s -X "$(GIT_REPOSITORY)/cmd.GitVersion=$(GIT_TAG)" -X "$(GIT_REPOSITORY)/cmd.GitHash=$(GIT_COMMIT_ID)" -extldflags "-static"
PACKR_VERSION := $(shell awk '/packr/ {print $$2}' go.mod)

# Docker
DOCKERFILE := Dockerfile
Expand All @@ -18,45 +19,55 @@ DOCKER_BIN := $(shell which docker || which podman || echo "docker")
DOCKER_BUILD := $(DOCKER_BIN) build -f $(DOCKERFILE) .

.PHONY: all
all: build

.PHONY: packr2
packr2:
which packr2 || go get -u github.com/gobuffalo/packr/v2/packr2
# packr2 still requires GO111MODULE var
GO111MODULE=on packr2 clean
GO111MODULE=on packr2

.PHONY: vendor
vendor:
go mod vendor

.PHONY: build
build: clean vendor packr2
packr2 clean
go build -mod=vendor -o $(BUILDDIR)/loginapp $(GOFLAGS) -ldflags '$(LDFLAGS)' $(GIT_REPOSITORY)

.PHONY: build-static
build-static: LDFLAGS += -extldflags "-static"
build-static: vendor packr2
all: go_build

.PHONY: go_packr2
go_packr2:
# Go: install packr2
@which packr2 >/dev/null || go install github.com/gobuffalo/packr/v2/packr2@$(PACKR_VERSION)
@# packr2 still requires GO111MODULE var
# Go: run packr2 (embded assets)
@packr2 clean
@GO111MODULE=on packr2

.PHONY: go_fmt
go_fmt:
# Go: fmt
@go fmt ./...

.PHONY: go_mod_vendor
go_mod_vendor:
# Go: vendor
@go mod vendor

.PHONY: go_build
go_build: go_mod_vendor go_packr2
# Go: build
CGO_ENABLED=0 go build -mod=vendor -o $(BUILDDIR)/loginapp $(GOFLAGS) -ldflags '$(LDFLAGS)' $(GIT_REPOSITORY)

.PHONY: docker-tmp
docker-tmp:
$(DOCKER_BUILD) -t $(DOCKER_REPOSITORY):$(GIT_COMMIT_ID)
.PHONY: docker_build
docker_build:
# Docker: build image
@$(DOCKER_BUILD) -t $(DOCKER_REPOSITORY):$(GIT_COMMIT_ID)

.PHONY: gofmt
gofmt:
go fmt ./...
.PHONY: docker_push
docker_push: docker_build
# Docker: push image
@$(DOCKER_BIN) push $(DOCKER_REPOSITORY):$(GIT_COMMIT_ID)

.PHONY: helmdoc
helmdoc:
chart-doc-gen -d docs/chart.yaml -v=helm/loginapp/values.yaml > ./helm/loginapp/README.md
.PHONY: helm_doc
helm_doc:
# Helm: doc
@chart-doc-gen -d docs/chart.yaml -v=helm/loginapp/values.yaml > ./helm/loginapp/README.md

.PHONY: helmpackage
helmpackage: helmdoc
helm package helm/loginapp -d $(BUILDDIR)
.PHONY: helm_package
helm_package: helm_doc
# Helm: package chart
@helm package -u helm/loginapp -d $(BUILDDIR)

.PHONY: clean
clean:
rm -f $(BUILDDIR)/loginapp
# Clean: binaries
@rm -f $(BUILDDIR)/loginapp
@rm -f $(BUILDDIR)/loginapp-*.tgz
@rm -f $(BUILDDIR)/index.yaml
28 changes: 19 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
module github.com/fydrah/loginapp

go 1.13
go 1.15

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/fsnotify/fsnotify v1.4.9
github.com/fsnotify/fsnotify v1.5.1
github.com/gobuffalo/logger v1.0.4 // indirect
github.com/gobuffalo/packr/v2 v2.8.1
github.com/julienschmidt/httprouter v1.3.0
github.com/karrick/godirwalk v1.16.1 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
github.com/pquerna/cachecontrol v0.0.0-20201205024021-ac21108117ac // indirect
github.com/prometheus/client_golang v1.8.0
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.1
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.31.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
golang.org/x/oauth2 v0.0.0-20201203001011-0b49973bad19
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
github.com/spf13/viper v1.9.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20211007125505-59d4e928ea9d // indirect
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)
Loading

0 comments on commit eacfed7

Please sign in to comment.