Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Embed wing hash with package variables and templating
Browse files Browse the repository at this point in the history
  • Loading branch information
charlieegan3 committed May 23, 2018
1 parent e4a6bd5 commit 3edc88e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/tarmak_darwin_amd64
/tarmak_local_build
/wing_linux_amd64
/wing_linux_amd64_unversioned
/dist/
/bin/
.DS_Store
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ go_vet:

go_build:
# make sure you add all binaries to the .goreleaser.yml as well
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' -o tarmak_linux_amd64 ./cmd/tarmak
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' -o tarmak_darwin_amd64 ./cmd/tarmak
# The hash of this binary is used to test if wing has changed in the s3 object etag
$(eval WING_HASH := $(shell md5sum wing_linux_amd64_unversioned | awk '{print $$1}'))
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) -X github.com/jetstack/tarmak/pkg/terraform.wingHash=$(WING_HASH) -X main.wingHash=$(WING_HASH)' -o tarmak_linux_amd64 ./cmd/tarmak
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) -X pkg/terraform/templating.wingHash=$$WING_HASH -X main.wingHash=$(WING_HASH)' -o tarmak_darwin_amd64 ./cmd/tarmak

# wing is must come first as it's used in the go-bindata
# wing binaries are used in the go-bindata
go_build_wing:
# make sure you add all binaries to the .goreleaser.yml as well
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' -o wing_linux_amd64 ./cmd/wing
# Build a version of the wing binary without build variables
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -o wing_linux_amd64_unversioned ./cmd/wing
# Build a release wing binary
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w -X main.version=$(CI_COMMIT_TAG) -X main.commit=$(CI_COMMIT_SHA) -X main.date=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)' -o wing_linux_amd64 ./cmd/wing

$(BINDIR)/mockgen:
mkdir -p $(BINDIR)
Expand Down
1 change: 1 addition & 0 deletions cmd/tarmak/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Version struct {
Version string
BuildDate string
Commit string
WingHash string
}

var AppName string = "tarmak"
Expand Down
8 changes: 5 additions & 3 deletions cmd/tarmak/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
)

var (
version string = "dev"
commit string = "unknown"
date string = ""
commit string = "unknown"
date string = ""
version string = "dev"
wingHash string = "unknown"
)

func main() {
cmd.Version.Version = version
cmd.Version.Commit = commit
cmd.Version.BuildDate = date
cmd.Version.WingHash = wingHash
cmd.Execute(os.Args[1:])
}
8 changes: 7 additions & 1 deletion pkg/terraform/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
)

func (t *Terraform) GenerateCode(c interfaces.Cluster) (err error) {

terraformCodePath := t.codePath(c)
if err := utils.EnsureDirectory(
terraformCodePath,
Expand Down Expand Up @@ -96,6 +95,7 @@ func (t *Terraform) GenerateCode(c interfaces.Cluster) (err error) {
cluster: c,
destDir: terraformCodePath,
rootPath: rootPath,
wingHash: wingHash,
}
if err := templ.Generate(); err != nil {
return err
Expand All @@ -109,6 +109,7 @@ type terraformTemplate struct {
cluster interfaces.Cluster
destDir string
rootPath string
wingHash string
}

func (t *terraformTemplate) Generate() error {
Expand Down Expand Up @@ -137,6 +138,10 @@ func (t *terraformTemplate) Generate() error {
if err := t.generateTemplate("jenkins_elb", "modules/jenkins/jenkins_elb"); err != nil {
result = multierror.Append(result, err)
}
// TODO time for a loop over an array of pairs?
if err := t.generateTemplate("wing_s3", "modules/kubernetes/wing_s3"); err != nil {
result = multierror.Append(result, err)
}
if err := t.generateTerraformVariables(); err != nil {
result = multierror.Append(result, err)
}
Expand Down Expand Up @@ -171,6 +176,7 @@ func (t *terraformTemplate) data(module string) map[string]interface{} {
"JenkinsCertificateARN": jenkinsCertificateARN,
"JenkinsInstall": jenkinsInstall,
"Module": module,
"WingHash": t.wingHash,
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import (

const debugShell = "debug-shell"

// wingHash is set by a linker flag to the hash of the lastest wing binary
var wingHash string

type Terraform struct {
*tarmakDocker.App
log *logrus.Entry
Expand Down
6 changes: 0 additions & 6 deletions terraform/amazon/modules/kubernetes/wing_s3.tf

This file was deleted.

6 changes: 6 additions & 0 deletions terraform/amazon/templates/wing_s3.tf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "aws_s3_bucket_object" "wing-binary" {
source = "wing_linux_amd64"
bucket = "${var.secrets_bucket}"
key = "${data.template_file.stack_name.rendered}/wing-{{ .WingHash }}"
etag = "{{ .WingHash }}"
}

0 comments on commit 3edc88e

Please sign in to comment.