Skip to content

Commit 035f249

Browse files
authored
Merge pull request #2 from cloudwm/server_options_schema_travis
commands schema, server options subcommand, travis-ci
2 parents d4e2711 + 0bb7d7a commit 035f249

20 files changed

Lines changed: 1141 additions & 281 deletions

.dockerignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
*.md
22
Dockerfile*
3-
main
4-
main-*
3+
cloudcli
4+
cloudcli-*
55
.*

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
main
2-
main-*
1+
cloudcli
2+
cloudcli-*
33
.idea

.travis.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export GOOS="${GOOS:-linux}"
2+
export GOARCH="${GOARCH:-amd64}"
3+
4+
if [ "${1}" == "script" ]; then
5+
( docker rm -f cloudwm-cli-build || true ) &&\
6+
docker build --build-arg GOOS=$GOOS --build-arg GOARCH=$GOARCH -t cloudwm-cli-build -f Dockerfile.build . &&\
7+
docker run -d --rm --name cloudwm-cli-build -v `pwd`:/go/src/github.com/cloudwm/cli cloudwm-cli-build tail -f /dev/null &&\
8+
sleep 1 &&\
9+
docker exec -it cloudwm-cli-build go build -o cloudcli main.go && sudo chown $USER ./cloudcli && sudo chmod +x ./cloudcli
10+
export PATH="`pwd`:${PATH}"
11+
[ "$?" != "0" ] && echo Failed build && exit 1
12+
if [ "${GOOS}" == "linux" ] && [ "${GOARCH}" == "amd64" ]; then
13+
echo "Running tests for linux/amd64"
14+
# Debug output may contain sensitive details
15+
export DEBUG_OUTPUT_FILE=/dev/null
16+
bash tests/test_all.sh
17+
RES="$?"
18+
exit "${RES}"
19+
else
20+
echo Skipping tests for $GOOS/$GOARCH
21+
exit 0
22+
fi
23+
fi

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
language: bash
2+
sudo: required
3+
env:
4+
matrix:
5+
- GOOS=darwin GOARCH=386
6+
- GOOS=darwin GOARCH=amd64
7+
- GOOS=linux GOARCH=386
8+
- GOOS=linux GOARCH=amd64
9+
- GOOS=windows GOARCH=386
10+
- GOOS=windows GOARCH=amd64
11+
global:
12+
- TRAVIS_CI_OPERATOR=1
13+
- secure: "2lb908fqRlPZ48NcEP5/steszQMUfNBMVaeq7czlKXWh5n0afxVPwAYsrppeDfeJy4LdVwZ+uxtYrEnRqpmfYQLaGKdUh+rDzcZf0SHpZIIoFQP8aETVS134Mpn0bndc/HezqJ/idAHR1LKmL+eYYGcHD2So9l3oASdTy4n3PK5M+vcfSzMLGR3OdgUSENp5QEhqiPmhHf5guTRwkZ3DCT7u76AXlmlZ8T9Ds7V28MHjYolMrZeG3GMi0nA6+rzlCZNk4kqoz1iE78PbiqKP6qly6IfG+kd3T1SibadkDiIH2IVEPRnrRfleYNTZdCCEr9/zXjtLLcyb8jk461pOtZUjlOwAQnxFZbcPy2ptlGSJ6JsKDOT9xHh8hfNuAd9G0nCWHz8yvcSCW2eTpGwHfAECp3N70arEHlOmEicQg2rib0A5ybV9oif4pzY59Vg0Yoy5KiikFkIPqKO6ZcBWncjBVvYNS2OLQhD38Jl3TOMdF/sHyG2SjLXkigM/iWlXJbh6i7+hy4u18IESMsKLMiG6WpHdM3+HZqXV8ONWJfkK8nvu0iYlEbPgYwe+lWGaK++aJUO6lctzv5cJecygZZbxUlk4ChHpdojpte9R7LaNNKpLs2L+h2xSMlmXH4mGpCn2/xyzObWOqBmSrXUTFYIl43JcVT5QpB2/F5hkvtE="
14+
- secure: "yBOPkxOL3baqbLv5SAc4q5nM4N6r51vqfxlH9L4vYiD/QTHc86GzWGbJzby4pCYoTLsrMrijqOYo3oc11mvROhtwyTnU/mfbtQIHyFWlGJFyq2wXYo2G8zPFKswiyYLGHNLK6P3q/ALD2vBXB5LbMCg81bOZrCMJ4/QiNYWefSuuSXZKVHL7Ca7+ZysCiTxWs/mEloYN1slX9sPs52ey12nU8z2O9pcAXnpAR2gH+vfpuqcqG4MXpqKUX7IL9NSBtV0nkUpt6s04BFDWqkAo3qOvjEtzMBEZDUIIj9OJvbF49N8JK0c2mgHsdlf6cbtn0Qz9U+hqqeQzqSWr6Uq65PFKhUquf3wrHaGY36pPVkmhH3XTx6xVVP9Hr4XMjeg4R+sB2EETsfn+yxhJYOBeb2suTnGqw14cVwdcSw0UMvW1SlndHLlwdfBXoZOkM6nUgQvQT59kkOaVdjrbjF0dGer8DD0VxEYxI0P6xBbcZ86vh8bHAS64PDNp3+e+BZW1Epc1ytO4zLSvR/2xj41qEqcSoQ5uamXuxXCfM8QrrqCAG6jxEWgUj5YALPayW6vMCQ+aYQRL5dyFbs8cDLh7TIFCvsYOSPWELkiqeaak8QopUyPxbXaZwLYXKcgZr4OIEMMX4H3OxLPq/ONEjS7A6r3Cja9Z2KXGOwW2EuKXfF4="
15+
services:
16+
- docker
17+
install:
18+
- sudo apt-get install -y python3-yaml
19+
- curl -L https://raw.githubusercontent.com/OriHoch/travis-ci-operator/master/travis_ci_operator.sh > $HOME/bin/travis_ci_operator.sh
20+
- bash $HOME/bin/travis_ci_operator.sh init
21+
- travis_ci_operator.sh docker-login
22+
script:
23+
- bash .travis.sh script
24+
- mkdir builds && mv cloudcli builds/cloudcli-$GOOS-$GOARCH
25+
deploy:
26+
# See https://docs.travis-ci.com/user/deployment/releases/
27+
provider: releases
28+
api_key:
29+
secure: "IismjCG8HUUIghVhjEHHRPyiSKbLiz80Dfn+4X7000icnxcJMWjYj2dNMeVXv1bAFcQON4GZTaXDJxcsnWXg5GDx837JkXocpOIMEMt1YjbRIIOY3xT9JR9gOUIPRgZu3Ck4rEhgLZZOY8LX8qoqglzw7IDSmqvx0hJXt0FX3Jl8nN39yM3py2F8vl9qPF7sTOHDla9P8nUjPvD0WzsXYvCYgrJsTFyMP1SLcwdzeUK1xUk1egQbEPUWqovgP8e94P6M7x84/GO0CnI1iXUjkvlKSh9wwMuzrCJoEvDcQSOCkWRbXc5sLAbV72Z42RugbIHf7KhXoQCv+csPsrkL/XQhWMfTGKA3NAWnu1bYvNFki1sV8TeyofMpUUPNs9uUj4hRQheSYwedxslNaQD4GKI9Jv9WanKQXUD+0PKhknPlVTtP5nmkdORHj327jrblmLaulIT8ULnrp0aSlNOqPDuJ2Y61UhCAJuAJcdJ+Y1dHFzTyNZP3uHuSIxvJ4DuSSR8DhytoyQ3uq0dhPWKIkrwcszoQxRW3VuJifUH+R/xWCYLF/qqT8zjNsBm8vWyqAurzwHBAlV+eWUao3LIag/268T3ltMPlBzoQUaNFnJnviQnvwsiKg0zrBtDF2BNeskdH/eRmZtzCk2VLtzH1iFh+k8SyJL28tf+SAhX2O1E="
30+
file_glob: true # enables wildcards in file names
31+
file: "builds/cloudcli-*"
32+
skip_cleanup: true
33+
on:
34+
tags: true

CONTRIBUTING.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88

99
We use Docker for consistent build environment. You are welcome to inspect `Dockerfile.build` and replicate on a local host.
1010

11+
Set env vars for desired OS (doesn't have to match your own OS)
12+
13+
```
14+
export GOOS=linux
15+
export GOARCH=amd64
16+
```
17+
1118
Build and run the Docker image which contains the build environment:
1219

1320
```
1421
( docker rm -f cloudwm-cli-build || true ) &&\
15-
docker build -t cloudwm-cli-build -f Dockerfile.build . &&\
22+
docker build --build-arg GOOS=$GOOS --build-arg GOARCH=$GOARCH -t cloudwm-cli-build -f Dockerfile.build . &&\
1623
docker run -d --rm --name cloudwm-cli-build -v `pwd`:/go/src/github.com/cloudwm/cli cloudwm-cli-build tail -f /dev/null
1724
```
1825

@@ -22,30 +29,23 @@ Compile and run the CLI:
2229
docker exec -it cloudwm-cli-build go run main.go
2330
```
2431

25-
Use [cobra](https://github.com/spf13/cobra/blob/master/cobra/README.md) to add commands:
26-
27-
```
28-
docker exec -it cloudwm-cli-build cobra add --help
29-
```
30-
31-
Build a Linux binary and set executable:
32+
Build a binary and set executable:
3233

3334
```
34-
docker exec -it cloudwm-cli-build go build main.go && sudo chown $USER ./main && sudo chmod +x ./main
35+
docker exec -it cloudwm-cli-build go build -o cloudcli main.go && sudo chown $USER ./cloudcli && sudo chmod +x ./cloudcli
3536
```
3637

3738
Run the executable (From Linux):
3839

3940
```
40-
./main
41+
./cloudcli
4142
```
4243

4344
(Optional) For fast development iterations, define bash aliases:
4445

4546
```
4647
alias cloudcli="docker exec -it cloudwm-cli-build go run main.go"
47-
alias cloudcli-cobra="docker exec -it cloudwm-cli-build cobra add --help"
48-
alias cloudcli-build="docker exec -it cloudwm-cli-build go build main.go && sudo chown $USER ./main && sudo chmod +x ./main"
48+
alias cloudcli-build="docker exec -it cloudwm-cli-build go build -o cloudcli main.go && sudo chown $USER ./cloudcli && sudo chmod +x ./cloudcli"
4949
```
5050

5151
## Troubleshooting
@@ -56,6 +56,8 @@ If you encounter permission problems, try running the following from project pat
5656
sudo chown -R $USER .
5757
```
5858

59+
Environment variables are not passed to the container by default. To test environment variables - you will have to modify the aliases or modify the exec script.
60+
5961

6062
## Cross Platform Building
6163

@@ -68,7 +70,28 @@ for GOOS in darwin linux windows; do
6870
export GOOS=$GOOS
6971
export GOARCH=$GOARCH
7072
docker build --build-arg GOOS=$GOOS --build-arg GOARCH=amd64 -t cloudwm-cli-build-$GOOS-$GOARCH -f Dockerfile.build . &&\
71-
docker run -it -v `pwd`:/go/src/github.com/cloudwm/cli cloudwm-cli-build-$GOOS-$GOARCH go build -o main-$GOOS-$GOARCH main.go
73+
docker run -it -v `pwd`:/go/src/github.com/cloudwm/cli cloudwm-cli-build-$GOOS-$GOARCH go build -o cloudcli-$GOOS-$GOARCH main.go
7274
done
7375
done
7476
```
77+
78+
79+
## Running the tests suite
80+
81+
Compile the cloudcli binary and place in PATH
82+
83+
Make sure environment is "clean" - e.g. no default cloudcli config files / env vars.
84+
85+
Set environment variables for the API server and account to use for testing:
86+
87+
```
88+
TEST_API_SERVER=""
89+
TEST_API_CLIENTID=""
90+
TEST_API_SECRET=""
91+
```
92+
93+
Run the tests suite:
94+
95+
```
96+
tests/test_all.sh
97+
```

README.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,85 @@
1-
# cloudcli-server
1+
# cloudcli
2+
3+
Terminal-based CLI interface for server and infrastructure management using supported APIs
4+
5+
## Install
6+
7+
Download binary for your OS/architecture from the [Releases](https://github.com/cloudwm/cloudcli/releases) page
8+
9+
```
10+
sudo wget -O /usr/local/bin/cloudcli https://github.com/cloudwm/cloudcli/releases/download/v0.0.1/cloudcli-linux-amd64 &&\
11+
sudo chmod +x /usr/local/bin/cloudcli
12+
```
13+
14+
## Usage
15+
16+
Set server API host and credentials using one of the following options:
17+
18+
* **yaml configuration file**:
19+
* A configuration file can set CLI flags
20+
* By default, a file is searched for at `$HOME/.cloudcli.yaml`
21+
* A different location can be specified using env var `CLOUDCLI_CONFIG=""` or `--config` flag
22+
* See [example-cloudcli.yaml](/example-cloudcli.yaml)
23+
24+
* **environment variables**:
25+
* Environment variables prefixed with `CLOUDCLI_` can set CLI flags
26+
* See [example-cloudcli.env](/example-cloudcli.env)
27+
28+
* **CLI flags**:
29+
* Server host and credentials can also be set using flags:
30+
* `cloudcli --api-server "" --api-clientid "" --api-secret ""`
31+
32+
**Important** Please keep your server and API credentials secure,
33+
it's recommended to use a configuration file with appropriate permissions and location.
34+
35+
36+
## Commands
37+
38+
Following is an overview of main supported commands.
39+
40+
See the cloudcli command help messages for full reference.
41+
42+
```
43+
cloudcli --help
44+
```
45+
46+
47+
### Server commands
48+
49+
50+
#### `cloudcli server list`
51+
52+
List all the servers in the account
53+
54+
55+
#### `cloudcli server options`
56+
57+
Download and show the available server options for your account.
58+
59+
One of the following flags must be provided:
60+
61+
```
62+
--billing show billing resources
63+
--cpu show cpu resources
64+
--datacenter show datacenter resources
65+
--disk show disk resources
66+
--image show image resources
67+
--network show network resources
68+
--ram show ram resources
69+
--traffic show traffic resources
70+
```
71+
72+
If optional flag `--cache` is provided, the options will be downloaded to local file `cloudcli-server-options.json` and loaded from that file if it exists.
73+
74+
75+
### Work in progress / Experiemental / Unstable commands
76+
77+
Following commands are work in progress / experiemental / unstable
78+
79+
To enable them set environment variable `CLOUDCLI_ENABLE_ALPHA=1`
80+
81+
##### `cloudcli server create`
82+
83+
Create server
84+
85+
**Work In Progress**

0 commit comments

Comments
 (0)