Skip to content

Commit

Permalink
Merge branch 'implement-update' into 'master'
Browse files Browse the repository at this point in the history
implement update

See merge request arvan/arvan-cli!1
  • Loading branch information
pjfa committed Dec 29, 2020
2 parents d3b9d3e + de579e4 commit 002b07d
Show file tree
Hide file tree
Showing 26 changed files with 2,890 additions and 276 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release Go project

on:
push:
tags:
- "*" # triggers only if push new tag version, like `0.8.4` or else

jobs:
build:
name: GoReleaser build
runs-on: ubuntu-latest

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up Go 1.14
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go

- name: Install Prerequisites
run: sudo apt install -y libgpgme-dev

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
*.dll
*.so
*.dylib

bin
# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
.vscode/
14 changes: 0 additions & 14 deletions .gitlab-ci.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .gitmodules

This file was deleted.

29 changes: 29 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
builds:
- id: arvan
main: ./cmd/arvan/arvan.go
binary: arvan
goos:
- linux
- darwin
- windows
goarch:
- amd64
- "386"
ldflags:
- -s -w
- -X 'k8s.io/client-go/pkg/version.gitVersion=v{{.Version}}'
- -X 'k8s.io/client-go/pkg/version.gitCommit={{.Commit}}'
- -X 'github.com/openshift/oc/pkg/version.versionFromGit=v{{.Version}}'
- -X 'github.com/openshift/oc/pkg/version.commitFromGit={{.Commit}}'
hooks:
post:
- upx -7 "{{ .Path }}"
archives:
-
format_overrides:
- goos: windows
format: zip
files:
- none*
name_template: 'arvan_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm
}}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#@IgnoreInspection BashAddShebang
export ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))
export CGO_ENABLED=0
export GO111MODULE=on
export GOPROXY=https://proxy.golang.org,direct

export ENV=development

LDFLAGS+=-X k8s.io/client-go/pkg/version.gitVersion=v0.1.0
LDFLAGS+=-X k8s.io/client-go/pkg/version.gitCommit=4f75300
LDFLAGS+=-X github.com/openshift/oc/pkg/version.versionFromGit=v0.1.0
LDFLAGS+=-X github.com/openshift/oc/pkg/version.commitFromGit=4f75300
build:
go build -v -o $(ROOT)/bin/arvan -ldflags="$(LDFLAGS)" $(ROOT)/cmd/arvan/*.go
109 changes: 4 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,115 +1,14 @@
# Arvan CLI

Command line for managing Arvan Services developed using [cobra](https://github.com/spf13/cobra) library.
Command line for managing Arvan Services.

## Usage

Login to arvan using `arvan login` command.

Type `arvan --help` to get list of all commands.

## Development

### Build

Building of project can be done using `build.sh` script:

```bash
./scripts/build/build.sh ~/go/bin/arvan
```
Where `~/go/bin/arvan` would be output of the project.

#### Environment Variables

`GOEXEC`: path to `go` executable. Change it if you don't want to use `go` executable defined in your PATH.

Example:

```bash
GOEXEC=/usr/lib/go-1.10/bin/go ./scripts/build/build.sh ~/go/bin/arvan
```

`BUILD_TAGS`: add build tags to `go build` process using `-tags` option.

Example:

```bash
BUILD_TAGS="include_gcs include_oss" ./scripts/build/build.sh ~/go/bin/arvan
```

`LDFLAGS`: add build tags to `go build`.

Example: disable debug information with `-s -w`:

```bash
GOEXEC=/usr/lib/go-1.10/bin/go LDFLAGS="-s -w" ./scripts/build/build.sh ~/go/bin/arvan
```

#### Shrink go binary size

Make sure you disabled debug informations using `-s -w` flags.

Use UPX to compress your binary:
## Update

```bash
upx -7 /home/vahid/go/bin/arvan
```
Update to the latest version using `arvan update` command.

### Subcommand Development:

You can add any subcommand to arvan by developing a [cobra](https://github.com/spf13/cobra) command and add to to arvan as subcommand.

#### Example Subcommand

Develope your subcommand and it's functionalities in separated git repository using [cobra](https://github.com/spf13/cobra). Assume your repository is `github.com/example/examplecli` and it have a `InitiatedCommand` function that returns your base command with type of `github.com/spf13/cobra`.`Command`. Add your project to to this repository vendor using `git submodule`:

```bash
git submodule add -b master https://github.com/example/examplecli vendor/github.com/example/examplecli
```

Create an `example` package in pkg and prepare what you need to for initializing you module in `pkg/example/example.go`:

```go
package example

import (
example "github.com/example/examplecli"
)

// NewCmdPaas return new cobra cli for paas
func NewCmdExample(in io.Reader, out, errout io.Writer) *cobra.Command {

exampleCommand := example.InitiatedCommand(in, out, errout)

// Do whatever you need to prepare your command. e.g. login preparation.

return exampleCommand
}
```

You can access all authentication information and general configurations of `arvan cli` by getting arvan config object using `config.GetConfigInfo()` from `git.arvan.me/arvan/cli/pkg/config`.

After you initialized and prepared your command add it to `arvan cli` as subcommand in `pkg/cli/cli.go`:

```go
package cli

import (
.
.
.
"git.arvan.me/arvan/cli/pkg/example"
)

func NewCommandCLI() *cobra.Command {
.
.
.

exampleCommand := example.NewCmdExample(in, out, errout)
cmd.AddCommand(exampleCommand)

return cmd
}
```
Type `arvan --help` to get list of all commands.

83 changes: 82 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
module git.arvan.me/arvan/cli

go 1.10
go 1.15

require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/alexbrainman/sspi v0.0.0-20200928142253-2a432fede40d // indirect
github.com/apcera/gssapi v0.0.0-20161010215902-5fb4217df13b // indirect
github.com/aws/aws-sdk-go v1.36.7 // indirect
github.com/containerd/continuity v0.0.0-20201208142359-180525291bb7 // indirect
github.com/containers/image v3.0.2+incompatible // indirect
github.com/containers/storage v1.18.2 // indirect
github.com/docker/docker v20.10.0+incompatible // indirect
github.com/fsouza/go-dockerclient v1.6.6 // indirect
github.com/gonum/graph v0.0.0-20190426092945-678096d81a4b // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/buildkit v0.8.0 // indirect
github.com/moby/term v0.0.0-20201110203204-bea5bbe245bf // indirect
github.com/openshift/api v3.9.0+incompatible
github.com/openshift/client-go v3.9.0+incompatible // indirect
github.com/openshift/library-go v0.0.0-20201211095848-8399bf6288d6
github.com/openshift/oc v0.0.0-alpha.0.0.20201210232229-4ebfe9cad4c3
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.20.0-beta.2
k8s.io/apimachinery v0.20.0-beta.2
k8s.io/cli-runtime v0.20.0-beta.2
k8s.io/client-go v0.20.0-beta.2
k8s.io/kubectl v0.20.0-beta.2
)

replace (
github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.8.7
github.com/apcera/gssapi => github.com/openshift/gssapi v0.0.0-20161010215902-5fb4217df13b
github.com/containerd/containerd => github.com/containerd/containerd v1.3.6
github.com/containers/image => github.com/openshift/containers-image v0.0.0-20190130162819-76de87591e9d
// Taking changes from https://github.com/moby/moby/pull/40021 to accomodate new version of golang.org/x/sys.
// Although the PR lists c3a0a3744636069f43197eb18245aaae89f568e5 as the commit with the fixes,
// d1d5f6476656c6aad457e2a91d3436e66b6f2251 is more suitable since it does not break fsouza/go-clientdocker,
// yet provides the same fix.
github.com/docker/docker => github.com/docker/docker v1.4.2-0.20191121165722-d1d5f6476656

// Temporary prebase beta.2 pins
github.com/openshift/api => github.com/openshift/api v0.0.0-20201119144013-9f0856e7c657
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20201119144744-148025d790a9
github.com/openshift/library-go => github.com/openshift/library-go v0.0.0-20201119162840-a8387fdfa05b
github.com/openshift/oc => github.com/arvancloud/oc v0.0.0-alpha.0.0.20201229052306-dff55bd9edf0

golang.org/x/crypto => golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975

k8s.io/api => k8s.io/api v0.20.0-beta.2
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.20.0-beta.2
k8s.io/apimachinery => github.com/openshift/kubernetes-apimachinery v0.0.0-20201119164651-a0d1e1af7af8
k8s.io/apiserver => k8s.io/apiserver v0.20.0-beta.2
k8s.io/cli-runtime => github.com/openshift/kubernetes-cli-runtime v0.0.0-20201120205941-cafce159b165
k8s.io/client-go => github.com/openshift/kubernetes-client-go v0.0.0-20201119165025-c1570ba06fef
k8s.io/cloud-provider => k8s.io/cloud-provider v0.20.0-beta.2
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.20.0-beta.2
k8s.io/code-generator => k8s.io/code-generator v0.20.0-beta.2
k8s.io/component-base => k8s.io/component-base v0.20.0-beta.2
k8s.io/component-helpers => k8s.io/component-helpers v0.20.0-beta.2
k8s.io/controller-manager => k8s.io/controller-manager v0.20.0-beta.2
k8s.io/cri-api => k8s.io/cri-api v0.20.0-beta.2
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.20.0-beta.2
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.20.0-beta.2
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.20.0-beta.2
k8s.io/kube-proxy => k8s.io/kube-proxy v0.20.0-beta.2
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.20.0-beta.2
k8s.io/kubectl => github.com/openshift/kubernetes-kubectl v0.0.0-20201120182004-53f855031220
k8s.io/kubelet => k8s.io/kubelet v0.20.0-beta.2
k8s.io/kubernetes => github.com/openshift/kubernetes v1.20.0-beta.2.0.20201120184952-99ac8bcc32c6
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.20.0-beta.2
k8s.io/metrics => k8s.io/metrics v0.20.0-beta.2
k8s.io/mount-utils => k8s.io/mount-utils v0.20.0-beta.2
k8s.io/node-api => k8s.io/node-api v0.20.0-beta.2
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.20.0-beta.2
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.20.0-beta.2
k8s.io/sample-controller => k8s.io/sample-controller v0.20.0-beta.2

)
Loading

0 comments on commit 002b07d

Please sign in to comment.