Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit 7799d9c

Browse files
committed
Use goreleaser
* Keep version information very short * Build docker images with goreleaser * Adds github workflow Signed-off-by: Chuck Ha <[email protected]>
1 parent 5aa99cd commit 7799d9c

File tree

11 files changed

+113
-143
lines changed

11 files changed

+113
-143
lines changed

.github/main.workflow

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/release.workflow

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
workflow "Release" {
2+
on = "push"
3+
resolves = ["Setup Google Cloud"]
4+
}
5+
6+
action "Setup Google Cloud" {
7+
uses = "actions/gcloud/auth@master"
8+
secrets = ["GCLOUD_AUTH"]
9+
}
10+
11+
action "is-tag" {
12+
uses = "actions/bin/filter@master"
13+
args = "tag"
14+
}
15+
16+
action "goreleaser" {
17+
uses = "docker://goreleaser/goreleaser"
18+
secrets = []
19+
args = "release"
20+
needs = ["is-tag", "Setup Google Cloud"]
21+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ kind-test
44

55
# vscode
66
.vscode
7+
8+
# goland
9+
.idea
10+
11+
# ignore build output
12+
dist

.goreleaser.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
builds:
5+
-
6+
id: capdctl
7+
env:
8+
- CGO_ENABLED=0
9+
main: ./cmd/capdctl/main.go
10+
binary: capdctl
11+
ldflags:
12+
- -s
13+
- -w
14+
- -X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.version={{.Version}}
15+
- -X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.shortHash={{.ShortCommit}}
16+
goos:
17+
- linux
18+
- darwin
19+
goarch:
20+
- amd64
21+
-
22+
id: capd-manager
23+
env:
24+
- CGO_ENABLED=0
25+
main: ./cmd/capd-manager/main.go
26+
binary: capd-manager
27+
goos:
28+
- linux
29+
goarch:
30+
- amd64
31+
archives:
32+
- replacements:
33+
darwin: Darwin
34+
linux: Linux
35+
amd64: x86_64
36+
checksum:
37+
name_template: 'checksums.txt'
38+
snapshot:
39+
name_template: "{{ .Tag }}-next"
40+
dockers:
41+
- goos: linux
42+
goarch: amd64
43+
binaries:
44+
- capd-manager
45+
image_templates:
46+
- "gcr.io/kubernetes1-226021/capd-manager:{{.Version}}"
47+
- "gcr.io/kubernetes1-226021/capd-manager:{{.Major}}.{{.Minor}}"
48+
- "gcr.io/kubernetes1-226021/capd-manager:latest"

Dockerfile

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.12.6
16-
WORKDIR /cluster-api-provider-docker
17-
ADD go.mod .
18-
ADD go.sum .
19-
RUN go mod download
20-
RUN curl -L https://dl.k8s.io/v1.14.3/kubernetes-client-linux-amd64.tar.gz | tar xvz
21-
ADD cmd cmd
22-
ADD actuators actuators
23-
ADD kind kind
24-
ADD third_party third_party
25-
26-
RUN go install -v ./cmd/capd-manager
15+
FROM golang:1.12.7
16+
WORKDIR /tmp
17+
RUN curl -L https://dl.k8s.io/v1.14.4/kubernetes-client-linux-amd64.tar.gz | tar xvz
18+
RUN mv /tmp/kubernetes/client/bin/kubectl /usr/local/bin
2719
RUN curl https://get.docker.com | sh
20+
COPY capd-manager /usr/local/bin
2821

29-
FROM golang:1.12.5
30-
COPY --from=0 /cluster-api-provider-docker/kubernetes/client/bin/kubectl /usr/local/bin
31-
COPY --from=0 /go/bin/capd-manager /usr/local/bin
32-
COPY --from=0 /usr/bin/docker /usr/local/bin
3322
ENTRYPOINT ["capd-manager"]

cmd/capd-manager/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ func main() {
7272
os.Exit(1)
7373
}
7474

75-
clusterLogger := log.WithName("cluster-actuator")
75+
clusterLogger := klogr.New().WithName("cluster-actuator")
7676
clusterActuator := actuators.Cluster{
7777
Log: clusterLogger,
7878
}
7979

80-
machineLogger := log.WithName("machine-actuator")
81-
80+
machineLogger := klogr.New().WithName("machine-actuator")
8281
machineActuator := actuators.Machine{
8382
Core: k8sclientset.CoreV1(),
8483
ClusterAPI: cs.ClusterV1alpha1(),

cmd/versioninfo/versioninfo.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,27 @@ package versioninfo
1818

1919
import (
2020
"fmt"
21-
"strings"
21+
)
22+
23+
const (
24+
defaultVersion = "v0.0.0"
25+
defaultShortHash = "0000000"
2226
)
2327

2428
var (
25-
// GitBranch is the branch from which this binary was built
26-
GitBranch string
27-
// GitReleaseTag is the git tag from which this binary is released
28-
GitReleaseTag string
29-
// GitReleaseCommit is the commit corresponding to the GitReleaseTag
30-
GitReleaseCommit string
31-
// GitTreeState indicates if the git tree, from which this binary was built, was clean or dirty
32-
GitTreeState string
33-
// GitCommit is the git commit at which this binary binary was built
34-
GitCommit string
35-
// GitMajor is the major version of the release
36-
GitMajor string
37-
// GitMinor is the minor version of the release
38-
GitMinor string
29+
// version is the version being released
30+
version string
31+
// ShortHash is the short form of the git hash of the commit being built
32+
shortHash string
3933
)
4034

4135
// VersionInfo returns version information for the supplied binary
4236
func VersionInfo(binName string) string {
43-
var vi strings.Builder
44-
vi.WriteString(fmt.Sprintf("%s version info:\n", binName))
45-
vi.WriteString(fmt.Sprintf("GitReleaseTag: %q, Major: %q, Minor: %q, GitRelaseCommit: %q\n", GitReleaseTag, GitMajor, GitMinor, GitReleaseCommit))
46-
vi.WriteString(fmt.Sprintf("Git Branch: %q\n", GitBranch))
47-
vi.WriteString(fmt.Sprintf("Git commit: %q\n", GitCommit))
48-
vi.WriteString(fmt.Sprintf("Git tree state: %q\n", GitTreeState))
49-
50-
return vi.String()
37+
if version == "" {
38+
version = defaultVersion
39+
}
40+
if shortHash == "" {
41+
shortHash = defaultShortHash
42+
}
43+
return fmt.Sprintf("%s %s+%s\n", binName, version, shortHash)
5144
}

hack/set-workspace-status.sh

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,8 @@ set -o errexit
1717
set -o nounset
1818
set -o pipefail
1919

20-
GIT_COMMIT="$(git describe --always --dirty --abbrev=14)"
20+
# Override by passing in VERSION
21+
VERSION=${VERSION:-$(git tag --sort taggerdate | tail -n 1)}
2122

22-
if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then
23-
GIT_TREE_STATE="clean"
24-
else
25-
GIT_TREE_STATE="dirty"
26-
fi
27-
28-
# mostly stolen from k8s.io/hack/lib/version.sh
29-
# Use git describe to find the version based on tags.
30-
if GIT_VERSION=$(git describe --tags --abbrev=14 2>/dev/null); then
31-
# This translates the "git describe" to an actual semver.org
32-
# compatible semantic version that looks something like this:
33-
# v1.1.0-alpha.0.6+84c76d1142ea4d
34-
#
35-
# TODO: We continue calling this "git version" because so many
36-
# downstream consumers are expecting it there.
37-
DASHES_IN_VERSION=$(echo "${GIT_VERSION}" | sed "s/[^-]//g")
38-
if [[ "${DASHES_IN_VERSION}" == "---" ]] ; then
39-
# We have distance to subversion (v1.1.0-subversion-1-gCommitHash)
40-
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\-\2/")
41-
elif [[ "${DASHES_IN_VERSION}" == "--" ]] ; then
42-
# We have distance to base tag (v1.1.0-1-gCommitHash)
43-
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-g\([0-9a-f]\{14\}\)$/-\1/")
44-
fi
45-
if [[ "${GIT_TREE_STATE}" == "dirty" ]]; then
46-
# git describe --dirty only considers changes to existing files, but
47-
# that is problematic since new untracked .go files affect the build,
48-
# so use our idea of "dirty" from git status instead.
49-
GIT_VERSION+="-dirty"
50-
fi
51-
52-
53-
# Try to match the "git describe" output to a regex to try to extract
54-
# the "major" and "minor" versions and whether this is the exact tagged
55-
# version or whether the tree is between two tagged versions.
56-
if [[ "${GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?([-].*)?([+].*)?$ ]]; then
57-
GIT_MAJOR=${BASH_REMATCH[1]}
58-
GIT_MINOR=${BASH_REMATCH[2]}
59-
fi
60-
61-
# If GIT_VERSION is not a valid Semantic Version, then refuse to build.
62-
if ! [[ "${GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
63-
GIT_VERSION=v0.0.0+${GIT_VERSION}
64-
GIT_MAJOR=0
65-
GIT_MINOR=0
66-
fi
67-
else
68-
GIT_VERSION="UNKNOWN_GIT_VERSION"
69-
GIT_MAJOR="UNKNOWN_GIT_MAJOR_VERSION"
70-
GIT_MINOR="UNKNOWN_GIT_MINOR_VERSION"
71-
fi
72-
73-
if GIT_RELEASE_TAG=$(git describe --abbrev=0 --tags 2> /dev/null); then
74-
GIT_RELEASE_COMMIT=$(git rev-list -n 1 ${GIT_RELEASE_TAG} | head -c 14)
75-
else
76-
GIT_RELEASE_TAG="UNKNOWN_RELEASE"
77-
GIT_RELEASE_COMMIT="UNKNOWN_RELEAE_COMMIT"
78-
fi
79-
80-
GIT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
23+
# Override by passing in SHORT
24+
SHORT=${SHORT:-$(git rev-parse --short "${VERSION}")}

hack/verify-docker-build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ source "$(dirname "$0")/utils.sh"
2323
# check if manager docker image builds
2424
cd_root_path
2525

26+
export GO111MODULE=on
27+
go mod download
28+
go build -o capd-manager ./cmd/capd-manager
2629
docker build --file Dockerfile -t capd-manager:pr-verify .

hack/verify-goimports.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ go build > /dev/null
4747
popd > /dev/null
4848

4949
# check for goimports diffs
50-
diff=$(git ls-files | grep "\.go" | grep -v "\/vendor" | xargs "${BIN_PATH}/goimports" -d 2>&1)
50+
diff=$(git ls-files | grep "\.go$" | xargs "${BIN_PATH}/goimports" -d 2>&1)
5151
if [[ -n "${diff}" ]]; then
5252
echo "${diff}"
5353
echo

0 commit comments

Comments
 (0)