Skip to content

Commit

Permalink
Compile time versioning (#42)
Browse files Browse the repository at this point in the history
Compile time versioning
* Add LDFLAGS to CI script, bring everything else in line with that method
* Remove docker-entrypoint.sh
  • Loading branch information
CKarper authored Aug 12, 2019
1 parent 9ae2026 commit 8289fa6
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .goreleaser.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ builds:
goos:
- darwin
- linux
ldflags:
- -s -w
- -X 'github.com/olegsu/iris/pkg/util.BuildVersion={{.Version}}'
- -X 'github.com/olegsu/iris/pkg/util.BuildDate={{.Date}}'
- -X 'github.com/olegsu/iris/pkg/util.BuildCommit={{.ShortCommit}}'
- -X 'github.com/olegsu/iris/pkg/util.BuildBy=goreleaser'
archive:
replacements:
darwin: Darwin
Expand All @@ -17,4 +23,4 @@ changelog:
filters:
exclude:
- '^docs:'
- '^test:'
- '^test:'
9 changes: 8 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ builds:
- darwin
- linux
- windows
ldflags:
- -s -w
- -X 'github.com/olegsu/iris/pkg/util.BuildVersion={{.Version}}'
- -X 'github.com/olegsu/iris/pkg/util.BuildDate={{.Date}}'
- -X 'github.com/olegsu/iris/pkg/util.BuildCommit={{.ShortCommit}}'
- -X 'github.com/olegsu/iris/pkg/util.BuildBy=goreleaser'

archive:
replacements:
darwin: Darwin
Expand All @@ -24,4 +31,4 @@ changelog:
filters:
exclude:
- '^docs:'
- '^test:'
- '^test:'
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
FROM alpine:3.8

RUN apk add --update ca-certificates
RUN apk --no-cache add --update ca-certificates

COPY dist/iris_linux_386/iris /usr/local/bin/
COPY hack/docker_entrypoint.sh /entrypoint.sh
COPY VERSION /VERSION

ENTRYPOINT ["sh", "entrypoint.sh"]
CMD [ "--help" ]
ENTRYPOINT ["/usr/local/bin/iris"]
CMD [ "--help" ]
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.1
0.7.0
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package cmd
// limitations under the License.

import (
"os"
"github.com/olegsu/iris/pkg/util"

"github.com/spf13/cobra"
)
Expand All @@ -27,7 +27,7 @@ var rootCmdOptions struct {
var rootCmd = &cobra.Command{
Use: "iris",
Long: "Watch on Kubernetes events, filter and send them as standard wehbook to any system",
Version: os.Getenv("IRIS_VERSION"),
Version: util.BuildVersion,
}

// Execute - execute the root command
Expand Down
18 changes: 10 additions & 8 deletions codefresh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@ stages:
- Integration
- Delivery


steps:

Prepare:
title: Update Helm package version
title: Update Helm package version
image: alpine:3.8
stage: Integration
commands:
- apk add --no-cache curl jq python py-pip
- pip install yq
- sh ${{CF_VOLUME_PATH}}/iris/hack/.codefresh/push-helm.sh
# ^-- cfexports IRIS_VERSION from VERSION file

Test:
title: Run unit test
image: golang:1.11
stage: Integration
commands:
- make test

PushingHelmChart:
title: Push Helm package to repo
title: Push Helm package to repo
stage: Delivery
image: codefresh/cfstep-helm:2.9.0
environment:
- ACTION=push
- CHART_REF=iris

CreatingGitTag:
title: Push tag to git
image: codefresh/cli
Expand All @@ -44,7 +46,7 @@ steps:
branch:
only:
- master

Releasing:
image: goreleaser/goreleaser
stage: Delivery
Expand All @@ -56,7 +58,7 @@ steps:
branch:
only:
- master

BuildBinaries:
image: goreleaser/goreleaser
stage: Delivery
Expand Down Expand Up @@ -86,7 +88,7 @@ steps:
- ${{CF_BRANCH_TAG_NORMALIZED}}
- ${{IRIS_VERSION}}
registry: dockerhub

PushingToDockerRegistryLatest:
title: Pushing to Docker Registry
type: push
Expand All @@ -97,4 +99,4 @@ steps:
when:
branch:
only:
- master
- master
18 changes: 14 additions & 4 deletions hack/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
OUTFILE=/usr/local/bin/irisctl
go build -o $OUTFILE main.go

chmod +x $OUTFILE
OUTFILE=${1:-/usr/local/bin/irisctl}
BUILD_DATE=$(date)
GIT_TAG=$(git describe --tags)
GIT_COMMIT=$(git rev-parse --short HEAD)

LDFLAGS="-s -w
-X 'github.com/olegsu/iris/pkg/util.BuildVersion=${GIT_TAG}'
-X 'github.com/olegsu/iris/pkg/util.BuildDate=${BUILD_DATE}'
-X 'github.com/olegsu/iris/pkg/util.BuildCommit=${GIT_COMMIT}'
-X 'github.com/olegsu/iris/pkg/util.BuildBy=Makefile'
"

go build -ldflags "$LDFLAGS" -o "$OUTFILE" main.go
5 changes: 0 additions & 5 deletions hack/docker_entrypoint.sh

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/destination/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/olegsu/iris/pkg/kube"
"github.com/olegsu/iris/pkg/logger"
"github.com/olegsu/iris/pkg/util"
"os"
)

const (
Expand All @@ -13,7 +12,7 @@ const (
)

var (
UserAgent = "iris/" + os.Getenv("IRIS_VERSION")
UserAgent = "iris/" + util.BuildVersion
)

type Destination interface {
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
yaml "gopkg.in/yaml.v2"
)

var (
BuildVersion, BuildDate, BuildCommit, BuildBy string
)

func UnmarshalOrDie(in []byte, out interface{}, logger logger.Logger) {
err := yaml.Unmarshal(in, out)
if err != nil {
Expand Down

0 comments on commit 8289fa6

Please sign in to comment.