Skip to content

Commit

Permalink
Merge pull request #312 from cybozu-go/d-kuro/krew
Browse files Browse the repository at this point in the history
Support krew release
  • Loading branch information
zoetrope authored Nov 2, 2021
2 parents d4afdf3 + cdbbe2a commit 0dc3e1c
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 37 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/docs
/e2e
/hack
/dist
/.git
17 changes: 9 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: ${{ env.go-version }}
- run: make release-build
- name: Create Release
- name: GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: v0.180.3
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tagname="${GITHUB_REF#refs/tags/}"
if echo ${{ github.ref }} | grep -q -e '-'; then prerelease=-p; fi
gh release create -t "Release $tagname" $prerelease \
-n "See [CHANGELOG.md](./CHANGELOG.md) for details." \
"$tagname" build/*
- name: Update new version in krew-index
# v0.0.40 https://github.com/rajatjindal/krew-release-bot/releases/tag/v0.0.40
uses: rajatjindal/krew-release-bot@56925b62bacc2c652114d66a8256faaf0bf89fa9
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
/bin
/build
/testbin
/dist
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
before:
hooks:
- make release-manifests-build

builds:
- id: kubectl-moco
main: ./cmd/kubectl-moco
binary: kubectl-moco
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ignore: # ref: https://goreleaser.com/deprecations/#builds-for-windowsarm64
- goos: windows
goarch: arm64

archives:
- builds:
- kubectl-moco
name_template: "kubectl-{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
wrap_in_directory: false
format: tar.gz
files:
- LICENSE

checksum:
name_template: checksums.txt

changelog:
skip: true

release:
github:
owner: cybozu-go
name: moco
prerelease: auto
name_template: "Release {{ .Tag }}"
footer: |
See [CHANGELOG.md](./CHANGELOG.md) for details.
extra_files:
- glob: build/moco.yaml
67 changes: 67 additions & 0 deletions .krew.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: moco
spec:
version: {{ .TagName }}
homepage: https://github.com/cybozu-go/moco
platforms:
- selector:
matchLabels:
os: darwin
arch: amd64
{{addURIAndSha "https://github.com/cybozu-go/moco/releases/download/{{ .TagName }}/kubectl-moco_{{ .TagName }}_darwin_amd64.tar.gz" .TagName | indent 6 }}
bin: kubectl-moco
files:
- from: kubectl-moco
to: .
- from: LICENSE
to: .
- selector:
matchLabels:
os: darwin
arch: arm64
{{addURIAndSha "https://github.com/cybozu-go/moco/releases/download/{{ .TagName }}/kubectl-moco_{{ .TagName }}_darwin_arm64.tar.gz" .TagName | indent 6 }}
bin: kubectl-moco
files:
- from: kubectl-moco
to: .
- from: LICENSE
to: .
- selector:
matchLabels:
os: linux
arch: amd64
{{addURIAndSha "https://github.com/cybozu-go/moco/releases/download/{{ .TagName }}/kubectl-moco_{{ .TagName }}_linux_amd64.tar.gz" .TagName | indent 6 }}
bin: kubectl-moco
files:
- from: kubectl-moco
to: .
- from: LICENSE
to: .
- selector:
matchLabels:
os: linux
arch: arm64
{{addURIAndSha "https://github.com/cybozu-go/moco/releases/download/{{ .TagName }}/kubectl-moco_{{ .TagName }}_linux_arm64.tar.gz" .TagName | indent 6 }}
bin: kubectl-moco
files:
- from: kubectl-moco
to: .
- from: LICENSE
to: .
- selector:
matchLabels:
os: windows
arch: amd64
{{addURIAndSha "https://github.com/cybozu-go/moco/releases/download/{{ .TagName }}/kubectl-moco_{{ .TagName }}_windows_amd64.tar.gz" .TagName | indent 6 }}
bin: kubectl-moco.exe
files:
- from: kubectl-moco.exe
to: .
- from: LICENSE
to: .
shortDescription: kubectl-moco is a plugin for kubectl to control MySQL clusters of MOCO.
description: |
kubectl-moco is a plugin for kubectl to control MySQL clusters of MOCO.
Read more documentation at: https://cybozu-go.github.io/moco/kubectl-moco.html
28 changes: 16 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ HELM_VERSION = 3.6.3
CRD_TO_MARKDOWN_VERSION = 0.0.3
MYSQLSH_VERSION = 8.0.27-1
MDBOOK_VERSION = 0.4.9
GORELEASER_VERSION = 0.180.3
OS_VERSION := $(shell . /etc/os-release; echo $$VERSION_ID)

# Test tools
Expand Down Expand Up @@ -115,21 +116,15 @@ build:
GOBIN=$(shell pwd)/bin go install ./cmd/...

.PHONY: release-build
release-build: kustomize
release-build: goreleaser
$(GORELEASER) build --snapshot --rm-dist

.PHONY: release-manifests-build
release-manifests-build: kustomize
rm -rf build
mkdir -p build
$(MAKE) kubectl-moco GOOS=windows GOARCH=amd64 SUFFIX=.exe
$(MAKE) kubectl-moco GOOS=darwin GOARCH=amd64
$(MAKE) kubectl-moco GOOS=darwin GOARCH=arm64
$(MAKE) kubectl-moco GOOS=linux GOARCH=amd64
$(MAKE) kubectl-moco GOOS=linux GOARCH=arm64
$(KUSTOMIZE) build . > build/moco.yaml

.PHONY: kubectl-moco
kubectl-moco: build/kubectl-moco-$(GOOS)-$(GOARCH)$(SUFFIX)

build/kubectl-moco-$(GOOS)-$(GOARCH)$(SUFFIX):
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ ./cmd/kubectl-moco

##@ Tools

CONTROLLER_GEN := $(shell pwd)/bin/controller-gen
Expand Down Expand Up @@ -171,6 +166,15 @@ mdbook: ## Donwload mdbook locally if necessary
mkdir -p bin
curl -fsL https://github.com/rust-lang/mdBook/releases/download/v$(MDBOOK_VERSION)/mdbook-v$(MDBOOK_VERSION)-x86_64-unknown-linux-gnu.tar.gz | tar -C bin -xzf -

GORELEASER := $(shell pwd)/bin/goreleaser
.PHONY: goreleaser
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary.

$(GORELEASER):
mkdir -p $(BIN_DIR)
curl -L -sS https://github.com/goreleaser/goreleaser/releases/download/v$(GORELEASER_VERSION)/goreleaser_Linux_x86_64.tar.gz \
| tar xz -C $(BIN_DIR) goreleaser

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
Expand Down
75 changes: 59 additions & 16 deletions docs/install-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,70 @@

Pre-built binaries are available on [GitHub releases](https://github.com/cybozu-go/moco/releases) for Windows, Linux, and MacOS.

Download one of the binaries for your OS and place it in a directory of `PATH`.
## Installing using Krew

[Krew](https://krew.sigs.k8s.io/) is the plugin manager for kubectl command-line tool.

See the [documentation](https://krew.sigs.k8s.io/docs/user-guide/setup/install/) for how to install Krew.

```console
$ curl -fsL -o /path/to/bin/kubectl-moco https://github.com/cybozu-go/moco/releases/latest/download/kubectl-moco-linux-amd64
$ chmod a+x /path/to/bin/kubectl-moco
$ kubectl krew update
$ kubectl krew install moco
```

Check the installation by running `kubectl moco -h`.
## Installing manually

```console
$ kubectl moco -h
the utility command for MOCO.
1. Set `OS` to the operating system name

Usage:
kubectl-moco [command]
OS is one of `linux`, `windows`, or `darwin` (MacOS).

Available Commands:
credential Fetch the credential of a specified user
help Help about any command
mysql Run mysql command in a specified MySQL instance
switchover Switch the primary instance
If Go is available, `OS` can be set automatically as follows:

...
```
```console
$ OS=$(go env GOOS)
```

2. Set `ARCH` to the architecture name

ARCH is one of `amd64` or `arm64`.

If Go is available, `ARCH` can be set automatically as follows:

```console
$ ARCH=$(go env GOARCH)
```

3. Set `VERSION` to the MOCO version

See the MOCO release page: https://github.com/cybozu-go/moco/releases

```console
$ VERSION=< The version you want to install >
```

4. Download the binary and put it in a directory of your `PATH`.

The following is an example to install the plugin in `/usr/local/bin`.

```console
$ curl -L -sS https://github.com/cybozu-go/moco/releases/download/$(VERSION)/kubectl-moco_$(VERSION)_$(OS)_$(ARCH).tar.gz \
| tar xz -C /usr/local/bin kubectl-moco
```

5. Check the installation by running `kubectl moco -h`.

```console
$ kubectl moco -h
the utility command for MOCO.
Usage:
kubectl-moco [command]
Available Commands:
credential Fetch the credential of a specified user
help Help about any command
mysql Run mysql command in a specified MySQL instance
switchover Switch the primary instance
...
```
2 changes: 1 addition & 1 deletion e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ endif
$(KUSTOMIZE) build . | $(KUBECTL) apply -f -
$(KUBECTL) -n moco-system wait --for=condition=available --timeout=180s --all deployments
$(KUBECTL) apply -f minio.yaml
$(KUBECTL) wait --for=condition=Ready --all pods
$(KUBECTL) wait --timeout=60s --for=condition=Ready --all pods

.PHONY: test
test:
Expand Down

0 comments on commit 0dc3e1c

Please sign in to comment.