Skip to content

Commit d5c849e

Browse files
author
Chris Every
authored
Merge pull request #170 from ovotech/move-ldflags-to-build-pkg
Move ldflags to build pkg
2 parents 0ee301c + 709f94a commit d5c849e

File tree

7 files changed

+88
-41
lines changed

7 files changed

+88
-41
lines changed

.circleci/config.yml

+4-27
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ jobs:
1212
steps:
1313
- checkout
1414

15+
- setup_remote_docker:
16+
docker_layer_caching: true
17+
1518
- run:
1619
name: goreleaser
1720
command: |
21+
echo $DOCKER_PASS | docker login -u=$DOCKER_USER --password-stdin
1822
curl -sL https://git.io/goreleaser | VERSION=v0.116.0 bash
1923
release_cloudfunction_zip:
2024
docker:
@@ -29,27 +33,6 @@ jobs:
2933
ZIP_NAME=cloud-key-rotator_${VERSION}_cloudfunction.zip
3034
zip -R ${ZIP_NAME} '*.go' 'go.mod'
3135
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} ${CIRCLE_TAG} ${ZIP_NAME}
32-
docker_build_and_push:
33-
<<: *defaults
34-
35-
docker:
36-
- image: circleci/golang
37-
38-
steps:
39-
- checkout
40-
41-
- setup_remote_docker:
42-
docker_layer_caching: true
43-
44-
- run:
45-
name:
46-
command: |
47-
export GO111MODULE=on
48-
go mod download
49-
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cloud-key-rotator ./cmd
50-
docker build -t ovotech/cloud-key-rotator:latest .
51-
echo $DOCKER_PASS | docker login -u=$DOCKER_USER --password-stdin
52-
docker push ovotech/cloud-key-rotator
5336
5437
go_fmt:
5538
<<: *defaults
@@ -153,12 +136,6 @@ workflows:
153136
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
154137
branches:
155138
ignore: /.*/
156-
- docker_build_and_push:
157-
filters:
158-
tags:
159-
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
160-
branches:
161-
ignore: /.*/
162139
pr_pipeline:
163140
jobs:
164141
- go_fmt:

.goreleaser.yml

+22-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,34 @@ builds:
2727
- amd64
2828
ldflags:
2929
- -s -w
30-
- -X github.com/ovotech/cloud-key-rotator/cmd/cobra.version={{.Version}}
31-
- -X github.com/ovotech/cloud-key-rotator/cmd/cobra.commit={{.ShortCommit}}
32-
- -X github.com/ovotech/cloud-key-rotator/cmd/cobra.date={{.Date}}
33-
- -X github.com/ovotech/cloud-key-rotator/cmd/cobra.osArch={{.Os}}/{{.Arch}}
30+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.Version={{.Version}}
31+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.Commit={{.ShortCommit}}
32+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.Date={{.Date}}
33+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.OsArch={{.Os}}/{{.Arch}}
3434
- id: lambda-build
3535
binary: cloud-key-rotator
3636
main: ./cmd/
3737
goos:
3838
- linux
3939
goarch:
4040
- amd64
41+
ldflags:
42+
- -s -w
43+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.Version={{.Version}}
44+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.Commit={{.ShortCommit}}
45+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.Date={{.Date}}
46+
- -X github.com/ovotech/cloud-key-rotator/pkg/build.OsArch={{.Os}}/{{.Arch}}
4147
checksum:
4248
name_template: "{{ .ProjectName }}_checksums.txt"
49+
dockers:
50+
-
51+
goos: linux
52+
goarch: amd64
53+
binaries:
54+
- cloud-key-rotator
55+
image_templates:
56+
- "ovotech/cloud-key-rotator:{{ .Tag }}"
57+
- "ovotech/cloud-key-rotator:v{{ .Major }}"
58+
- "ovotech/cloud-key-rotator:v{{ .Major }}.{{ .Minor }}"
59+
- "ovotech/cloud-key-rotator:latest"
60+

cloudfunction.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 OVO Technology
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package cloudfunction
216

317
import (

cmd/cobra/rotate.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var (
2626
Short: "Rotate some cloud keys",
2727
Long: `Rotate some cloud keys`,
2828
Run: func(cmd *cobra.Command, args []string) {
29-
logger.Info("cloud-key-rotator rotate called")
3029
var err error
3130
var c config.Config
3231
if c, err = config.GetConfig(configPath); err == nil {

cmd/cobra/version.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1+
// Copyright 2019 OVO Technology
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package cmd
216

317
import (
418
"fmt"
519
"strconv"
620

21+
"github.com/ovotech/cloud-key-rotator/pkg/build"
722
"github.com/spf13/cobra"
823
)
924

1025
var (
11-
defaultLdFlag = "-"
12-
version = defaultLdFlag
13-
commit = defaultLdFlag
14-
date = defaultLdFlag
15-
osArch = defaultLdFlag
1626
versionField = "Version"
1727
gitCommitField = "Git commit"
1828
builtField = "Built"
1929
osArchField = "OS/Arch"
2030
ldFlags = map[string]string{
21-
versionField: version,
22-
gitCommitField: commit,
23-
builtField: date,
24-
osArchField: osArch}
31+
versionField: build.Version,
32+
gitCommitField: build.Commit,
33+
builtField: build.Date,
34+
osArchField: build.OsArch}
2535
//map insertion order isn't maintained, so use a slice for that
2636
ldFlagOrder = []string{versionField, gitCommitField, builtField, osArchField}
2737
formatString = "%-" + strconv.Itoa(maxLength(ldFlagOrder)+2) + "v%s\n"

pkg/build/build.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019 OVO Technology
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package build
16+
17+
var (
18+
defaultLdFlag = "-"
19+
//Version ldflag
20+
Version = defaultLdFlag
21+
//Commit ldflag
22+
Commit = defaultLdFlag
23+
//Date ldflag
24+
Date = defaultLdFlag
25+
//OsArch ldflag
26+
OsArch = defaultLdFlag
27+
)

pkg/rotate/rotatekeys.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
keys "github.com/ovotech/cloud-key-client"
3030

31+
"github.com/ovotech/cloud-key-rotator/pkg/build"
3132
"github.com/ovotech/cloud-key-rotator/pkg/config"
3233
"github.com/ovotech/cloud-key-rotator/pkg/cred"
3334
"github.com/ovotech/cloud-key-rotator/pkg/location"
@@ -93,6 +94,7 @@ func keysOfProviders(account, provider, project string, c config.Config) (accoun
9394
func Rotate(account, provider, project string, c config.Config) (err error) {
9495
defer logger.Sync()
9596

97+
logger.Infof("cloud-key-rotator %s rotate called", build.Version)
9698
if err = validateFlags(account, provider, project); err != nil {
9799
return
98100
}

0 commit comments

Comments
 (0)