Skip to content

Commit

Permalink
fix version flag; fix #24
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Sep 11, 2020
1 parent 4a7a888 commit fabb0e8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -76,6 +76,8 @@ jobs:
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=date::$(date --utc +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
Expand All @@ -92,3 +94,4 @@ jobs:
with:
push: true
tags: ${{ steps.prep.outputs.tags }}
build-args: VERSION=${{ steps.prep.output.version }},COMMIT=${{ github.sha }},DATE=${{ steps.prep.output.date }}
3 changes: 1 addition & 2 deletions .goreleaser.yml
Expand Up @@ -6,8 +6,7 @@ before:
builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
goos:
- linux
goarch:
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Expand Up @@ -6,10 +6,12 @@ COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 go build -o /go/bin/dalga ./cmd/dalga
ARG VERSION
ARG COMMIT
ARG DATE
RUN CGO_ENABLED=0 go build -o /go/bin/dalga -ldflags="-s -w -X main.version=$VERSION -X main.commit=$COMMIT -X main.date=$DATE" ./cmd/dalga

FROM alpine:latest
ARG GO_PROJECT
RUN touch /etc/dalga.toml
COPY --from=0 /go/bin/dalga /bin/dalga
ENTRYPOINT ["/bin/dalga", "-config", "/etc/dalga.toml"]
24 changes: 19 additions & 5 deletions cmd/dalga/main.go
Expand Up @@ -17,18 +17,32 @@ import (
"github.com/knadh/koanf/providers/file"
)

// These variables are set by goreleaser on build.
var (
config = flag.String("config", "dalga.toml", "config file")
version = flag.Bool("version", false, "print version")
version = "0.0.0"
commit = ""
date = ""
)

var (
configFlag = flag.String("config", "dalga.toml", "config file")
versionFlag = flag.Bool("version", false, "print version")
createTables = flag.Bool("create-tables", false, "create table for storing jobs")
debug = flag.Bool("debug", false, "turn on debug messages")
)

func versionString() string {
if len(commit) > 7 {
commit = commit[:7]
}
return fmt.Sprintf("%s (%s) [%s]", version, commit, date)
}

func main() {
flag.Parse()

if *version {
fmt.Println(dalga.Version)
if *versionFlag {
fmt.Println(versionString())
return
}

Expand Down Expand Up @@ -70,7 +84,7 @@ func main() {
func readConfig() (c dalga.Config, err error) {
c = dalga.DefaultConfig
k := koanf.New(".")
err = k.Load(file.Provider(*config), toml.Parser())
err = k.Load(file.Provider(*configFlag), toml.Parser())
if err != nil {
return
}
Expand Down
2 changes: 0 additions & 2 deletions dalga.go
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/cenkalti/dalga/v3/internal/table"
)

const Version = "2.0.0"

// Dalga is a job scheduler.
type Dalga struct {
config Config
Expand Down

0 comments on commit fabb0e8

Please sign in to comment.