diff --git a/.dockerignore b/.dockerignore index dd0e93dc6..ac40a38d9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,5 @@ /docs /e2e /hack +/dist /.git diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4276748f1..a78f1798b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 7594e05d8..f4b90a419 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ /bin /build /testbin +/dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 000000000..6b4b6256f --- /dev/null +++ b/.goreleaser.yaml @@ -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 diff --git a/.krew.yaml b/.krew.yaml new file mode 100644 index 000000000..2035e3c0d --- /dev/null +++ b/.krew.yaml @@ -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 diff --git a/Makefile b/Makefile index 318404a8e..e7102f608 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 diff --git a/docs/install-plugin.md b/docs/install-plugin.md index e585ac56c..b8f6da55d 100644 --- a/docs/install-plugin.md +++ b/docs/install-plugin.md @@ -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 + + ... + ``` diff --git a/e2e/Makefile b/e2e/Makefile index c1c4f0857..248277c32 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -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: