Skip to content

Commit

Permalink
Merge pull request #3 from DevopsArtFactory/prepare_deploy_production
Browse files Browse the repository at this point in the history
prepare_deploy_production
  • Loading branch information
sepiro2000 authored Jan 13, 2021
2 parents 093eed8 + ee11fe9 commit d790c08
Show file tree
Hide file tree
Showing 27 changed files with 478 additions and 240 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ GCP_PROJECT ?= escli
SUPPORTED_PLATFORMS = linux-amd64 darwin-amd64 windows-amd64.exe linux-arm64
BUILD_PACKAGE = $(REPOPATH)/$(COMMAND_PKG)

escli_TEST_PACKAGES = ./pkg/... ./cmd/... ./hack/...
escli_TEST_PACKAGES = ./cmd/...
GO_FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/diag/*")

VERSION_PACKAGE = $(REPOPATH)/pkg/version
VERSION_PACKAGE = $(REPOPATH)/internal/version
COMMIT = $(shell git rev-parse HEAD)
TEST_PACKAGES = ./pkg/... ./hack/...

ifeq "$(strip $(VERSION))" ""
override VERSION = $(shell git describe --always --tags --dirty)
Expand Down Expand Up @@ -99,7 +98,7 @@ $(BUILD_DIR):
mkdir -p $(BUILD_DIR)

.PHONY: release
release: clean format linters test permission cross $(BUILD_DIR)/VERSION upload-only
release: clean format linters cross $(BUILD_DIR)/VERSION upload-only

.PHONY: build
build: format cross $(BUILD_DIR)/VERSION
Expand Down
127 changes: 116 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# escli
`escli` is a command-line tool for managing elasticsearch cluster.
`escli` is a command-line tool for managing elasticsearch cluster. If you want to set number_of_replicas of index, you should do with curl like below example.
```bash
$ curl -X PUT "localhost:9200/my-index-000001/_settings?pretty" -H 'Content-Type: application/json' -d'
{
"index" : {
"number_of_replicas" : 2
}
}
'
```
But with escli, you type below command.
```bash
$ escli index setting my-index-000001 number_of_replicas 2
```
`escli` should be make your elasticsearch experience more powerful.

## Installation
### Required
Expand Down Expand Up @@ -81,30 +95,121 @@ application-log-2021.01.06 green open 100 1
| snapshot list | shows information of repositories and snapshots. it calls `_cat/snapshot` API. |
| snapshot archive | change storage class of snapshots to S3 glacier. it works on AWS only. |
| snapshot restore | change storage class of snapshots to S3 standard and restore snapshot. |
| snapshot take | take snapshot of indices. |
| snapshot create | create snapshot of indices. |

#### available options
| option | description |
| ------------- | ---------------------------------------------------------------- |
| force | do not ask continue. it will be used for automated batch job. |
| force | do not ask continue. it will be used for automated batch job. (only `archive`, `restore` command) |
| with-repo | shows snapshots of specified repo (only `list` command) |
| repo-only | shows only information of repos (only `list` command) |

#### examples

```bash
$ escli snapshot list
$ escli snapshot list --repo-only
Repository ID : log-archive
Repository ID : log-archive-standard-ia
Repository ID : log-archive-standard
```

```bash
$ escli snapshot create prod-snapshot snapshots-2021-01-01 result-prod-2021-01-01
snapshots-2021-01-01 is created
```

```bash
$ escli snapshot archive send-mail-result-prod-snapshot snapshots-2020-12-31 --region us-east-1
bucket name : result-prod
base path : elasticsearch-snapshot-standard
Downloaded /tmp/index-456 81207 bytes
index name : result-prod-2020-12-31
elasticsearch-snapshot-standard/indices/z8bqmUmAQxy8tuwSsmFEKg/0/__-urzTmmuR8K6s6kpLryZ5g
? Change Storage Class to GLACIER
```

- If you use `--force` option to `snapshot arvhice` command, escli doesn't ask you to continue. It makes all archiving job.

### `index` command

#### command list
| command | description |
| ----------- | --------------------------------------------------------- |
| index settings | get or set settings of index. |
| command | description |
| index settings | get or set index settings |

#### available options
| option | description |
| ------------- | ---------------------------------------------------------------- |
| force | do not ask continue. it will be used for automated batch job. |
#### examples

```bash
$ escli index settings prod-2021-01-01
{
"prod-2021-01-01" : {
"settings" : {
"index" : {
"creation_date" : "1609906432373",
"number_of_shards" : "5",
"number_of_replicas" : "2",
"uuid" : "ha6Y6uiCSfOV_syHJwFCqA",
"version" : {
"created" : "6080099"
},
"provided_name" : "send-mail-result-prod-2021-01-01"
}
}
}
}
```

```bash
$ escli index settings prod-2021-01-12 number_of_replicas ok 3s
{
"prod-2021-01-12" : {
"settings" : {
"index" : {
"number_of_replicas" : "1"
}
}
}
}
```

```bash
$ escli index settings send-mail-result-prod-2021-01-12 number_of_replicas 2 ok
{
"acknowledged" : true
}
```

### `cluster` command

#### command list
| command | description |
| cluster settings | get or set index settings |

#### examples

```bash
$ escli cluster settings
{
"persistent" : {
"cluster" : {
"routing" : {
"allocation" : {
......
}
```
```bash
$ escli cluster settings persistent indices.recovery.max_bytes_per_sec 50mb
```
### `diag` command
#### examples
```bash
$ escli diag
check cluster status...........................[green] 😎
check yellow status indices....................[0] 😎
check red status indices.......................[0] 😎
check number of master nodes...................[3]
check maximum disk used percent of nodes.......[36]
```
6 changes: 3 additions & 3 deletions cmd/cmd/builder/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ limitations under the license.
package builder

import (
"github.com/DevopsArtFactory/escli/internal/constants"
"reflect"

"github.com/aws/aws-sdk-go/aws"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/DevopsArtFactory/escli/internal/constants"
"github.com/DevopsArtFactory/escli/internal/util"
)

Expand All @@ -49,7 +49,7 @@ var FlagRegistry = []Flag{
Value: aws.Bool(false),
DefValue: false,
FlagAddMethod: "BoolVar",
DefinedOn: []string{
DefinedOn: []string{
"snapshot restore [repositoryID] [snapshotID] [indexName]",
"snapshot create",
"snapshot delete",
Expand Down Expand Up @@ -94,7 +94,7 @@ var FlagRegistry = []Flag{
Value: aws.String(constants.EmptyString),
DefValue: constants.EmptyString,
FlagAddMethod: "StringVar",
DefinedOn: []string{
DefinedOn: []string{
"snapshot restore [repositoryID] [snapshotID] [indexName]",
"snapshot archive [repositoryID] [snapshotID]"},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the license.
package cmd

import (
"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/DevopsArtFactory/escli/cmd/cmd/cat"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/cat/indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package cat

import (
"context"
"github.com/DevopsArtFactory/escli/internal/executor"
"io"

"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/DevopsArtFactory/escli/internal/executor"
)

func NewCatIndicesCommand() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/cat/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package cat

import (
"context"
"github.com/DevopsArtFactory/escli/internal/executor"
"io"

"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/DevopsArtFactory/escli/internal/executor"
)

func NewCatNodesCommand() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/cat/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package cat

import (
"context"
"github.com/DevopsArtFactory/escli/internal/executor"
"io"

"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/DevopsArtFactory/escli/internal/executor"
)

func NewCatShardsCommand() *cobra.Command {
Expand Down
3 changes: 2 additions & 1 deletion cmd/cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the license.
package cmd

import (
"github.com/DevopsArtFactory/escli/cmd/cmd/cluster"
"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/cluster"
)

func NewClusterCommand() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/cluster/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ func NewClusterSettingsCommand() *cobra.Command {

func funcClusterSettings(ctx context.Context, out io.Writer, args []string) error {
return executor.RunExecutor(ctx, func(executor executor.Executor) error {
return executor.Runner.IndexSettings(out, args)
return executor.Runner.ClusterSettings(out, args)
})
}
2 changes: 1 addition & 1 deletion cmd/cmd/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package cmd

import (
"context"
"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"io"

"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/DevopsArtFactory/escli/internal/executor"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the license.
package cmd

import (
"github.com/DevopsArtFactory/escli/cmd/cmd/index"
"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/index"
)

func NewIndexCommand() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the license.
package cmd

import (
"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/spf13/cobra"

"github.com/DevopsArtFactory/escli/cmd/cmd/builder"
"github.com/DevopsArtFactory/escli/cmd/cmd/snapshot"
)

Expand Down
34 changes: 34 additions & 0 deletions deploy/cross/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2020 The escli Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM dockercore/golang-cross:1.13.10 as base

# The base image is not yet available for go 1.14.
# Let's just replace the Go that's installed with a newer one.
RUN rm -Rf /usr/local/go && mkdir /usr/local/go
RUN curl --fail --show-error --silent --location https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz \
| tar xz --directory=/usr/local/go --strip-components=1

# Cross compile escli for Linux, Windows and MacOS
ARG GOOS
ARG GOARCH
ARG TAGS
ARG LDFLAGS

WORKDIR /escli
COPY . ./

RUN if [ "$GOOS" = "darwin" ]; then export CC=o64-clang CXX=o64-clang++; fi; \
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=1 \
go build -tags "${TAGS}" -ldflags "${LDFLAGS}" -o /build/escli cmd/main.go
4 changes: 2 additions & 2 deletions internal/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
)

type Flags struct {
Region string `json:"region"`
Force bool `json:"force"`
TroubledOnly bool `json:"troubled-only"`
SortBy string `json:"sort-by"`
RepoOnly bool `json:"repo-only"`
WithRepo string `json:"with-repo"`
Region string `json:"region"`
SortBy string `json:"sort-by"`
}

func ParseFlags() (*Flags, error) {
Expand Down
Loading

0 comments on commit d790c08

Please sign in to comment.