Browse Source

Refactored build and help

pull/10/head
James Mills 3 years ago
parent
commit
1109e5dbf3
Signed by: prologic
GPG Key ID: AC4C014F1440EBD6
  1. 24
      Dockerfile
  2. 24
      Makefile
  3. 1
      cmd/autodock/.gitignore
  4. 1
      go.mod
  5. 2
      go.sum
  6. 65
      main.go
  7. 13
      version/version.go
  8. 3
      version/version_test.go

24
Dockerfile

@ -1,28 +1,16 @@
# Build
FROM golang:alpine AS build
ARG TAG
ARG BUILD
RUN apk add --no-cache -U git make build-base
ENV APP autodock
ENV REPO prologic/$APP
RUN apk add --update git make build-base && \
rm -rf /var/cache/apk/*
WORKDIR /go/src/github.com/$REPO
COPY . /go/src/github.com/$REPO
RUN make TAG=$TAG BUILD=$BUILD build
WORKDIR /src/autodock
COPY . /src/autodock
RUN make install
# Runtime
FROM scratch
ENV APP autodock
ENV REPO prologic/$APP
LABEL autodock.app main
FROM alpine:latest
COPY --from=build /go/src/github.com/${REPO}/cmd/${APP}/${APP} /${APP}
COPY --from=build /go/bin/autodock /autodock
EXPOSE 8000/tcp

24
Makefile

@ -1,26 +1,24 @@
.PHONY: dev build image profile bench test clean
.PHONY: dev build install image profile bench test clean
CGO_ENABLED=0
COMMIT=`git rev-parse --short HEAD`
APP=autodock
REPO?=prologic/$(APP)
TAG?=latest
BUILD?=-dev
COMMIT=$(shell git rev-parse --short HEAD)
all: dev
dev: build
@./cmd/$(APP)/$(APP) -debug
@./autodock -d
build: clean
@echo " -> Building $(TAG)$(BUILD)"
@cd cmd/$(APP) && go build -tags "netgo static_build" -installsuffix netgo \
-ldflags "-w -X github.com/$(REPO)/version.GitCommit=$(COMMIT) -X github.com/$(REPO)/version.Build=$(BUILD)" .
@echo "Built $$(./cmd/$(APP)/$(APP) -v)"
@go build \
-tags "netgo static_build" -installsuffix netgo \
-ldflags "-w -X $(shell go list)/version/.GitCommit=$(COMMIT)" \
.
install: build
@go install
image:
@docker build --build-arg TAG=$(TAG) --build-arg BUILD=$(BUILD) -t $(REPO):$(TAG) .
@echo "Image created: $(REPO):$(TAG)"
@docker build -t prologic/autodock .
profile:
@go test -cpuprofile cpu.prof -memprofile mem.prof -v -bench ./...

1
cmd/autodock/.gitignore vendored

@ -1 +0,0 @@
autodock

1
go.mod

@ -14,6 +14,7 @@ require (
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/common v0.0.0-20181218105931-67670fe90761 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/pflag v1.0.3
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 // indirect
golang.org/x/net v0.0.0-20181220203305-927f97764cc3
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect

2
go.sum

@ -41,6 +41,8 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nL
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=

65
cmd/autodock/main.go → main.go

@ -8,58 +8,45 @@ import (
pkgver "github.com/prologic/autodock/version"
"github.com/namsral/flag"
"github.com/prologic/autodock/config"
"github.com/prologic/autodock/server"
flag "github.com/spf13/pflag"
)
func main() {
var (
dockerurl string
msgbusurl string
var (
dockerurl string
msgbusurl string
tlsverify bool
tlscacert string
tlscert string
tlskey string
tls bool
tlsverify bool
tlscacert string
tlscert string
tlskey string
tls bool
debug bool
version bool
debug bool
version bool
bind string
)
bind string
)
flag.String(flag.DefaultConfigFlagname, "", "path to config file")
flag.BoolVar(&debug, "debug", false, "enable debug logging")
flag.BoolVar(&version, "v", false, "display version information")
func init() {
flag.StringP("config", "c", "", "path to config file")
flag.BoolVarP(&debug, "debug", "d", false, "enable debug logging")
flag.BoolVarP(&version, "version", "v", false, "display version information")
flag.StringVar(
&bind, "bind", "0.0.0.0:8000",
"[int]:<port> to bind to for HTTP",
)
flag.StringVarP(&bind, "bind", "b", "0.0.0.0:8000", "[int]:<port> to bind to for HTTP")
flag.StringVar(&dockerurl, "dockerurl", "", "Docker URL to connect to")
flag.StringVar(&msgbusurl, "msgbusurl", "", "MessageBus URL to connect to")
flag.StringVar(&dockerurl, "docker-url", "", "Docker URL to connect to")
flag.StringVar(&msgbusurl, "msgbus-url", "", "MessageBus URL to connect to")
flag.BoolVar(&tls, "tls", false, "Use TLS; implied by --tlsverify")
flag.StringVar(
&tlscacert, "tlscacert", "",
"Trust certs signed only by this CA",
)
flag.StringVar(
&tlscert, "tlscert", "",
"Path to TLS certificate file",
)
flag.StringVar(
&tlskey, "tlskey", "",
"Path to TLS key file",
)
flag.BoolVar(
&tlsverify, "tlsverify", true,
"Use TLS and verify the remote",
)
flag.StringVar(&tlscacert, "tls-ca-cert", "", "Trust certs signed only by this CA")
flag.StringVar(&tlscert, "tls-cert", "", "Path to TLS certificate file")
flag.StringVar(&tlskey, "tls-key", "", "Path to TLS key file")
flag.BoolVar(&tlsverify, "tls-verify", true, "Use TLS and verify the remote")
}
func main() {
flag.Parse()
if version {

13
version/version.go

@ -1,15 +1,14 @@
package version
var (
Version = "0.1.0"
// Build will be overwritten automatically by the build system
Build = "-dev"
import (
"fmt"
)
// GitCommit will be overwritten automatically by the build system
var (
Version = "0.1.0"
GitCommit = "HEAD"
)
func FullVersion() string {
return Version + Build + " (" + GitCommit + ")"
return fmt.Sprintf("%s@%s", Version, GitCommit)
}

3
version/version_test.go

@ -1,13 +1,14 @@
package version
import (
"fmt"
"testing"
)
func TestFullVersion(t *testing.T) {
version := FullVersion()
expected := Version + Build + " (" + GitCommit + ")"
expected := fmt.Sprintf("%s@%s", Version, GitCommit)
if version != expected {
t.Fatalf("invalid version returned: %s", version)

Loading…
Cancel
Save