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

Release #95

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .github/main.workflow

This file was deleted.

21 changes: 21 additions & 0 deletions .github/release.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
workflow "Release" {
on = "push"
resolves = ["Setup Google Cloud"]
}

action "Setup Google Cloud" {
uses = "actions/gcloud/auth@master"
secrets = ["GCLOUD_AUTH"]
}

action "is-tag" {
uses = "actions/bin/filter@master"
args = "tag"
}

action "goreleaser" {
uses = "docker://goreleaser/goreleaser"
secrets = []
args = "release"
needs = ["is-tag", "Setup Google Cloud"]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ kind-test

# vscode
.vscode

# goland
.idea

# ignore build output
dist
48 changes: 48 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
before:
hooks:
- go mod download
builds:
-
id: capdctl
env:
- CGO_ENABLED=0
main: ./cmd/capdctl/main.go
binary: capdctl
ldflags:
- -s
- -w
- -X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.version={{.Version}}
- -X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.shortHash={{.ShortCommit}}
goos:
- linux
- darwin
goarch:
- amd64
-
id: capd-manager
env:
- CGO_ENABLED=0
main: ./cmd/capd-manager/main.go
binary: capd-manager
goos:
- linux
goarch:
- amd64
archives:
- replacements:
darwin: Darwin
linux: Linux
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
dockers:
- goos: linux
goarch: amd64
binaries:
- capd-manager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this just use the top level Dockerfile?

image_templates:
- "gcr.io/kubernetes1-226021/capd-manager:{{.Version}}"
- "gcr.io/kubernetes1-226021/capd-manager:{{.Major}}.{{.Minor}}"
- "gcr.io/kubernetes1-226021/capd-manager:latest"
21 changes: 5 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.12.6
WORKDIR /cluster-api-provider-docker
ADD go.mod .
ADD go.sum .
RUN go mod download
RUN curl -L https://dl.k8s.io/v1.14.3/kubernetes-client-linux-amd64.tar.gz | tar xvz
ADD cmd cmd
ADD actuators actuators
ADD kind kind
ADD third_party third_party

RUN go install -v ./cmd/capd-manager
FROM golang:1.12.7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this isn't building anything, any reason not to use distroless here?

WORKDIR /tmp
RUN curl -L https://dl.k8s.io/v1.14.4/kubernetes-client-linux-amd64.tar.gz | tar xvz
RUN mv /tmp/kubernetes/client/bin/kubectl /usr/local/bin
RUN curl https://get.docker.com | sh
COPY capd-manager /usr/local/bin
chuckha marked this conversation as resolved.
Show resolved Hide resolved

FROM golang:1.12.5
COPY --from=0 /cluster-api-provider-docker/kubernetes/client/bin/kubectl /usr/local/bin
COPY --from=0 /go/bin/capd-manager /usr/local/bin
COPY --from=0 /usr/bin/docker /usr/local/bin
ENTRYPOINT ["capd-manager"]
5 changes: 2 additions & 3 deletions cmd/capd-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ func main() {
os.Exit(1)
}

clusterLogger := log.WithName("cluster-actuator")
clusterLogger := klogr.New().WithName("cluster-actuator")
clusterActuator := actuators.Cluster{
Log: clusterLogger,
}

machineLogger := log.WithName("machine-actuator")

machineLogger := klogr.New().WithName("machine-actuator")
machineActuator := actuators.Machine{
Core: k8sclientset.CoreV1(),
ClusterAPI: cs.ClusterV1alpha1(),
Expand Down
39 changes: 16 additions & 23 deletions cmd/versioninfo/versioninfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,27 @@ package versioninfo

import (
"fmt"
"strings"
)

const (
defaultVersion = "v0.0.0"
defaultShortHash = "0000000"
)

var (
// GitBranch is the branch from which this binary was built
GitBranch string
// GitReleaseTag is the git tag from which this binary is released
GitReleaseTag string
// GitReleaseCommit is the commit corresponding to the GitReleaseTag
GitReleaseCommit string
// GitTreeState indicates if the git tree, from which this binary was built, was clean or dirty
GitTreeState string
// GitCommit is the git commit at which this binary binary was built
GitCommit string
// GitMajor is the major version of the release
GitMajor string
// GitMinor is the minor version of the release
GitMinor string
// version is the version being released
version string
// ShortHash is the short form of the git hash of the commit being built
shortHash string
)

// VersionInfo returns version information for the supplied binary
func VersionInfo(binName string) string {
var vi strings.Builder
vi.WriteString(fmt.Sprintf("%s version info:\n", binName))
vi.WriteString(fmt.Sprintf("GitReleaseTag: %q, Major: %q, Minor: %q, GitRelaseCommit: %q\n", GitReleaseTag, GitMajor, GitMinor, GitReleaseCommit))
vi.WriteString(fmt.Sprintf("Git Branch: %q\n", GitBranch))
vi.WriteString(fmt.Sprintf("Git commit: %q\n", GitCommit))
vi.WriteString(fmt.Sprintf("Git tree state: %q\n", GitTreeState))

return vi.String()
if version == "" {
version = defaultVersion
}
if shortHash == "" {
shortHash = defaultShortHash
}
return fmt.Sprintf("%s %s+%s\n", binName, version, shortHash)
}
64 changes: 4 additions & 60 deletions hack/set-workspace-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,8 @@ set -o errexit
set -o nounset
set -o pipefail

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

if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then
GIT_TREE_STATE="clean"
else
GIT_TREE_STATE="dirty"
fi

# mostly stolen from k8s.io/hack/lib/version.sh
# Use git describe to find the version based on tags.
if GIT_VERSION=$(git describe --tags --abbrev=14 2>/dev/null); then
# This translates the "git describe" to an actual semver.org
# compatible semantic version that looks something like this:
# v1.1.0-alpha.0.6+84c76d1142ea4d
#
# TODO: We continue calling this "git version" because so many
# downstream consumers are expecting it there.
DASHES_IN_VERSION=$(echo "${GIT_VERSION}" | sed "s/[^-]//g")
if [[ "${DASHES_IN_VERSION}" == "---" ]] ; then
# We have distance to subversion (v1.1.0-subversion-1-gCommitHash)
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\-\2/")
elif [[ "${DASHES_IN_VERSION}" == "--" ]] ; then
# We have distance to base tag (v1.1.0-1-gCommitHash)
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-g\([0-9a-f]\{14\}\)$/-\1/")
fi
if [[ "${GIT_TREE_STATE}" == "dirty" ]]; then
# git describe --dirty only considers changes to existing files, but
# that is problematic since new untracked .go files affect the build,
# so use our idea of "dirty" from git status instead.
GIT_VERSION+="-dirty"
fi


# Try to match the "git describe" output to a regex to try to extract
# the "major" and "minor" versions and whether this is the exact tagged
# version or whether the tree is between two tagged versions.
if [[ "${GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?([-].*)?([+].*)?$ ]]; then
GIT_MAJOR=${BASH_REMATCH[1]}
GIT_MINOR=${BASH_REMATCH[2]}
fi

# If GIT_VERSION is not a valid Semantic Version, then refuse to build.
if ! [[ "${GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
GIT_VERSION=v0.0.0+${GIT_VERSION}
GIT_MAJOR=0
GIT_MINOR=0
fi
else
GIT_VERSION="UNKNOWN_GIT_VERSION"
GIT_MAJOR="UNKNOWN_GIT_MAJOR_VERSION"
GIT_MINOR="UNKNOWN_GIT_MINOR_VERSION"
fi

if GIT_RELEASE_TAG=$(git describe --abbrev=0 --tags 2> /dev/null); then
GIT_RELEASE_COMMIT=$(git rev-list -n 1 ${GIT_RELEASE_TAG} | head -c 14)
else
GIT_RELEASE_TAG="UNKNOWN_RELEASE"
GIT_RELEASE_COMMIT="UNKNOWN_RELEAE_COMMIT"
fi

GIT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2)
# Override by passing in SHORT
SHORT=${SHORT:-$(git rev-parse --short "${VERSION}")}
3 changes: 3 additions & 0 deletions hack/verify-docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ source "$(dirname "$0")/utils.sh"
# check if manager docker image builds
cd_root_path

export GO111MODULE=on
go mod download
go build -o capd-manager ./cmd/capd-manager
docker build --file Dockerfile -t capd-manager:pr-verify .
2 changes: 1 addition & 1 deletion hack/verify-goimports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ go build > /dev/null
popd > /dev/null

# check for goimports diffs
diff=$(git ls-files | grep "\.go" | grep -v "\/vendor" | xargs "${BIN_PATH}/goimports" -d 2>&1)
diff=$(git ls-files | grep "\.go$" | xargs "${BIN_PATH}/goimports" -d 2>&1)
if [[ -n "${diff}" ]]; then
echo "${diff}"
echo
Expand Down
14 changes: 7 additions & 7 deletions scripts/build-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
set -o errexit
set -o xtrace

VERSION=${VERSION:-}
SHORT=${SHORT:-}

# shellcheck source=/dev/null
source "$(dirname "$0")/../hack/utils.sh"
readonly REPO_PATH=$(get_root_path)
Expand All @@ -28,15 +31,12 @@ readonly CAPDMGR_SRC=${REPO_PATH}/cmd/capd-manager
readonly KIND_TEST_BIN=${REPO_PATH}/bin/kind-test
readonly KIND_TEST_SRC=${REPO_PATH}/cmd/kind-test

# this sets VERSION and SHORT if they are not already set
source "${REPO_PATH}/hack/set-workspace-status.sh"

LDFLAGS="-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitBranch=${GIT_BRANCH} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitReleaseTag=${GIT_RELEASE_TAG} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitReleaseCommit=${GIT_RELEASE_COMMIT} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitTreeState=${GIT_TREE_STATE} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitCommit=${GIT_COMMIT} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitMajor=${GIT_MAJOR} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitMinor=${GIT_MINOR}"
LDFLAGS="-s -w \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.version=${VERSION} \
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.shortHash=${SHORT}"

# build capdctl
go build -ldflags "${LDFLAGS}" -o ${CAPDCTL_BIN} ${CAPDCTL_SRC}
Expand Down