Skip to content

Commit

Permalink
Cli rename (#29)
Browse files Browse the repository at this point in the history
* successfully renamed
* adding dockerfile for deployment options
* adding github package
* added install scripts
  • Loading branch information
Ryan SVIHLA authored Nov 15, 2021
1 parent 12a4732 commit b64572c
Show file tree
Hide file tree
Showing 19 changed files with 599 additions and 207 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Astra Cli docker image

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- main
- seed

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:

env:
IMAGE_NAME: astra-cli

jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- revive
- gomnd
- goprintffuncname
- gosimple
Expand All @@ -27,7 +27,7 @@ linters:
- nakedret
- nolintlint
- rowserrcheck
- scopelint
- exportloopref
- staticcheck
- structcheck
- typecheck
Expand Down
10 changes: 5 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ before:
# You may remove this if you don't use go modules.
- go mod tidy
builds:
- id: astra-cli
- id: astra
goos:
- windows
- linux
goarch:
- amd64
- arm64
- id: astra-cli-osx-amd
binary: astra-cli
- id: astra-osx-amd
binary: astra
goos:
- darwin
goarch:
- amd64
hooks:
post: gon gon_osx_darwin_amd64.hcl
- id: astra-cli-osx-arm
binary: astra-cli
- id: astra-osx-arm
binary: astra
goos:
- darwin
goarch:
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.17.3-alpine as BUILD

COPY / /astra
WORKDIR /astra

RUN ./script/build

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /astra/bin/astra /astra
89 changes: 38 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ Apache 2.0 licensed Astra Cloud Management CLI

Ready for production

## How to install - install script

* /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/rsds143/astra-cli/main/script/install-astra.sh)"
* astra login

## How to install - docker

Instead of downloading the binary this trusts that you have docker installed

* make sure docker is installed
* /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/rsds143/astra-cli/main/script/install-astra-docker.sh)"
* astra.sh login

## How to install - Homebrew for Mac and Linux

* [install homebrew](https://brew.sh/) if you have not
Expand All @@ -22,13 +35,13 @@ Ready for production
* download a [release](https://github.com/rsds143/astra-cli/releases)
* tar zxvf <download>
* cd <extracted folder>
* ./astra-cli
* ./astra

## How to install - From Source

* Install [Go 1.16](https://golang.org/dl/)
* Install [Go 1.17](https://golang.org/dl/)
* run `git clone [email protected]:rsds143/astra-cli.git`
* run `./scripts/build` or `go build -o ./bin/astra-cli .`
* run `./scripts/build` or `go build -o ./bin/astra .`

## How to use

Expand All @@ -40,58 +53,51 @@ Ready for production
After creating a token with rights to use the devops api

```
./bin/astra-cli login --token "changed"
astra login --token "changed"
Login information saved
```
### login service account

After creating a service account on the Astra page

```
./bin/astra-cli login --id "changed" --name "changed" --secret "changed"
astra login --id "changed" --name "changed" --secret "changed"
Login information saved
```

## login service account with json

```
./bin/astra-cli login --json '{"clientId":"changed","clientName":"[email protected]","clientSecret":"changed"}'
astra login --json '{"clientId":"changed","clientName":"[email protected]","clientSecret":"changed"}'
Login information saved
```

### creating database

```
./bin/astra-cli db create -v --keyspace myks --name mydb
2021/02/24 18:23:24 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 19 more times
2021/02/24 18:23:29 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 18 more times
2021/02/24 18:23:35 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 17 more times
2021/02/24 18:23:40 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 16 more times
2021/02/24 18:23:45 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 15 more times
2021/02/24 18:23:50 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 14 more times
2021/02/24 18:23:55 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 13 more times
2021/02/24 18:24:00 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PENDING but expected ACTIVE trying again 12 more times
astra db create -v --keyspace myks --name mydb
............
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b created
```

### get secure connection bundle

```
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d external -l external.zip
astra db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d external -l external.zip
file external.zip saved 12072 bytes written
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d internal -l internal.zip
astra db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d internal -l internal.zip
file internal.zip saved 12066 bytes written
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d proxy-internal -l proxy-internal.zip
astra db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d proxy-internal -l proxy-internal.zip
file proxy-internal.zip saved 348 bytes written
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d proxy-external -l proxy-external.zip
astra db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -d proxy-external -l proxy-external.zip
file proxy-external.zip saved 339 bytes written
```

### get secure connection bundle URLs

```
./bin/astra-cli db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -o list
astra db secBundle 3c577e51-4ff5-4551-86a4-41d475c61822 -o list
external bundle: changed
internal bundle: changed
external proxy: changed
Expand All @@ -101,15 +107,15 @@ file proxy-external.zip saved 339 bytes written
### listing databases

```
./bin/astra-cli db list
astra db list
name id status
mydb 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b ACTIVE
```

### listing databases in json

```
./bin/astra-cli db list -o json
astra db list -o json
[
{
"id": "2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b",
Expand Down Expand Up @@ -157,15 +163,15 @@ mydb 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b ACTIVE
### getting database by id

```
./bin/astra-cli db get 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
astra db get 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
name id status
mydb 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b ACTIVE
```

### getting database by id in json

```
./bin/astra-cli db get 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b -o json
astra db get 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b -o json
{
"id": "2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b",
"orgId": "changed",
Expand Down Expand Up @@ -212,49 +218,30 @@ mydb 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b ACTIVE

### parking database

Does not work on serverless
NOTE: Does not work on serverless

```
./bin/astra-cli db park -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
astra db park -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
starting to park database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
2021/02/24 18:31:26 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 29 more times
2021/02/24 18:31:56 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 28 more times
2021/02/24 18:32:26 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 27 more times
2021/02/24 18:32:57 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 26 more times
2021/02/24 18:33:27 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state PARKING but expected PARKED trying again 25 more times
...........
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b parked
```

### unparking database

Does not work on serverless
NOTE: Does not work on serverless

```
./bin/astra-cli db unpark -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
astra db unpark -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
starting to unpark database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
2021/02/25 08:41:02 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 59 more times
2021/02/25 08:41:32 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 58 more times
2021/02/25 08:42:02 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 57 more times
2021/02/25 08:42:32 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 56 more times
2021/02/25 08:43:02 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 55 more times
2021/02/25 08:43:32 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 54 more times
2021/02/25 08:44:02 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 53 more times
2021/02/25 08:44:32 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 52 more times
2021/02/25 08:45:03 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 51 more times
2021/02/25 08:45:33 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 50 more times
2021/02/25 08:46:03 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 49 more times
2021/02/25 08:46:33 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 48 more times
2021/02/25 08:47:03 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 47 more times
2021/02/25 08:47:33 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 46 more times
2021/02/25 08:48:03 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 45 more times
2021/02/25 08:48:33 db 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b in state UNPARKING but expected ACTIVE trying again 44 more times
...........
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b unparked
```

### deleting database

```
./bin/astra-cli db delete -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
astra db delete -v 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
starting to delete database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b
database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b deleted
```
Expand All @@ -264,7 +251,7 @@ database 2c3bc0d6-5e3e-4d77-81c8-d95a35bdc58b deleted
I did not have a paid account to verify this works, but you can see it succesfully starts the process

```
./bin/astra-cli db resize -v 72c4d35b-1875-495a-b5f1-97329d90b6c5 2
astra db resize -v 72c4d35b-1875-495a-b5f1-97329d90b6c5 2
unable to unpark '72c4d35b-1875-495a-b5f1-97329d90b6c5' with error expected status code 2xx but had: 400 error was [map[ID:2.000009e+06 message:resizing is not supported for this database tier]]
```

Expand Down
3 changes: 2 additions & 1 deletion cmd/db/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var startingAfter string
var listFmt string

func init() {
ListCmd.Flags().IntVarP(&limit, "limit", "l", 10, "limit of databases retrieved")
defaultLimit := 10
ListCmd.Flags().IntVarP(&limit, "limit", "l", defaultLimit, "limit of databases retrieved")
ListCmd.Flags().StringVarP(&include, "include", "i", "", "the type of filter to apply")
ListCmd.Flags().StringVarP(&provider, "provider", "p", "", "provider to filter by")
ListCmd.Flags().StringVarP(&startingAfter, "startingAfter", "a", "", "timestamp filter, ie only show databases created after this timestamp")
Expand Down
4 changes: 3 additions & 1 deletion cmd/db/resize.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func executeResize(args []string, makeClient func() (pkg.Client, error)) error {
}
id := args[0]
capacityUnitRaw := args[1]
capacityUnit, err := strconv.ParseInt(capacityUnitRaw, 10, 32)
defaultCapacity := 10
bits := 32
capacityUnit, err := strconv.ParseInt(capacityUnitRaw, defaultCapacity, bits)
if err != nil {
return &pkg.ParseError{
Args: args,
Expand Down
Loading

0 comments on commit b64572c

Please sign in to comment.