Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The CLI Client #198

Merged
merged 59 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
59c33ce
feat(cli-client): initial commit
zhijie-yang Jun 4, 2024
54f610e
ci: automatically update oci/mock-rock/_releases.json, from https://g…
Jun 4, 2024
b11fac4
feat(cli-client): full upload trigger generation
zhijie-yang Jun 5, 2024
3ac8eeb
ci: automatically update oci/mock-rock/_releases.json, from https://g…
Jun 5, 2024
012d346
feat(cli-client): get run id from workflow ext ref id
zhijie-yang Jun 5, 2024
50e962b
feat(cli-client): finalize workflow dispatcher
zhijie-yang Jun 5, 2024
bcb69f6
ci: automatically update oci/mock-rock/_releases.json, from https://g…
Jun 5, 2024
58128a1
feat(cli-client) add poller for workflow run status
zhijie-yang Jun 6, 2024
bbfd44d
feat(cli-client): optimize token management
zhijie-yang Jun 6, 2024
cb41fca
ci: automatically update oci/mock-rock/_releases.json, from https://g…
Jun 6, 2024
6742f5d
feat(cli-client): display current job for poller
zhijie-yang Jun 7, 2024
e7ea085
ci: automatically update oci/mock-rock/_releases.json, from https://g…
Jun 7, 2024
3698b74
chore(ci): disable mock-rock CI for cli-client
zhijie-yang Jun 7, 2024
083e7df
ci: automatically update oci/mock-rock/_releases.json, from https://g…
Jun 7, 2024
4d381f5
fix(cli-client): workflow dispatch returns 204
zhijie-yang Jun 10, 2024
c105f6e
fix(cli-client): fix poller not updating runs list
zhijie-yang Jun 10, 2024
be365dc
feat(cli-client): get image name by rockcraft.yaml
zhijie-yang Jun 10, 2024
34d1827
fix(cli-client): add missing version field
zhijie-yang Jun 10, 2024
ac07b65
feat(cli-client): add basic cli parser
zhijie-yang Jun 10, 2024
d7b29e5
feat(cli-client): full go-flags parser for upload
zhijie-yang Jun 11, 2024
6232b6e
test(cli-client): add test for trigger and dispatcher
zhijie-yang Jun 11, 2024
dcedd24
refactor(cli-client): refactor client for testability
zhijie-yang Jun 13, 2024
edf6f07
test(cli-client): add tests for client, validator and tokens
zhijie-yang Jun 13, 2024
a06df9d
doc(cli-client): add readme
zhijie-yang Jun 13, 2024
d842db5
chore(cli-client): change panic to println
zhijie-yang Jun 14, 2024
242ac2c
docs(cli-client): updated README
zhijie-yang Jun 24, 2024
3b72ff2
Merge branch 'main' into ROCKS-1216-cli-client
zhijie-yang Jun 24, 2024
f697e50
fix(cli-client): fix the code styling accord. to review
zhijie-yang Jun 24, 2024
cbfdc97
fix(cli-client): update test and function visibility acc. to review
zhijie-yang Jun 24, 2024
54b8ca6
feat(cli-client): use regex to find release args and add test
zhijie-yang Jun 24, 2024
d444410
fix(cli-client): multiple adjustments according to code review
zhijie-yang Jun 25, 2024
9490c9d
refactor(cli-client): change tacks to track for cmd
zhijie-yang Jun 25, 2024
2a4791a
test(cli-client): reformed tests with go check
zhijie-yang Jun 25, 2024
14f64e6
refactor(cli-client): use defer to restore injected variable
zhijie-yang Jun 27, 2024
0c81222
feat(cli-client): use kv pair to parse upload cmd
zhijie-yang Jun 28, 2024
7c7d675
doc(cli-client): update readme accord. code review
zhijie-yang Jul 2, 2024
18061b4
fix(cli-client): fix accord. to code review
zhijie-yang Jul 2, 2024
e0a2336
feat(cli-client): add 503 retry for SendRequest
zhijie-yang Jul 2, 2024
f5c68dc
chore(cli-client): comment out not impl.'ed release cmd
zhijie-yang Jul 3, 2024
f43d41d
chore(cli-client): add description help msg
zhijie-yang Jul 3, 2024
3dcd613
chore(cli-client): update go module
zhijie-yang Jul 4, 2024
cc2b88a
fix(cli-client): resolve golint err
zhijie-yang Jul 4, 2024
c0fe424
build(cli-client): add test workflow
zhijie-yang Jul 4, 2024
f1c56e4
doc(cli-client): add cli client in root README
zhijie-yang Jul 4, 2024
b12ffe5
doc(cli-client): fix hyperlink in root README
zhijie-yang Jul 5, 2024
ecd99fb
build(cli-client): ROCKS-1274 add snap pack
zhijie-yang Jul 12, 2024
0aae871
feat(cli-client): make unauthorized error more friendly
zhijie-yang Jul 12, 2024
f4359f4
refactor(cli-client): rename cli workflow as internal
zhijie-yang Jul 12, 2024
b0d144f
chore(ci): use working-directory in workflow
zhijie-yang Jul 12, 2024
49ac137
doc(cli-client): update from code reivew
zhijie-yang Jul 12, 2024
ef30468
build(cli-client): use . as build source
zhijie-yang Jul 12, 2024
b7d61f5
docs(cli): move install client outside of deps
zhijie-yang Jul 12, 2024
e48824f
chore(cli): go mod tidy
zhijie-yang Jul 15, 2024
d25d8ef
feat(cli): enhance err handling in cli_main
zhijie-yang Jul 15, 2024
a2479a1
feat(cli): handle 'help' command
zhijie-yang Jul 15, 2024
db12a9a
feat(cli): enhance error handling
zhijie-yang Jul 15, 2024
b819f16
chore(cli): update the long desc of upload cmd
zhijie-yang Jul 15, 2024
7a6e701
ci(cli): add snap build for cli client
zhijie-yang Jul 16, 2024
c541687
feat(cli): use AddCommand directly from parser
zhijie-yang Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/_CLI-Client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CLI-Client
on:
push:
paths:
- "src/cli-client/**"
pull_request:
paths:
- "src/cli-client/**"

jobs:
test:
runs-on: ubuntu-latest
name: Test
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.22
- name: Test
working-directory: src/cli-client
run: |
go test ./...
2 changes: 2 additions & 0 deletions .github/workflows/_Test-OCI-Factory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ on:
- "!.github/workflows/PR-Validator.yaml"
- "!.github/workflows/_Auto-updates.yaml"
- "!.github/workflows/Continuous-Testing.yaml"
- "!.github/workflows/CLI-Client.yaml"
- "examples/**"
- "oci/mock*"
- "src/**"
- "!src/workflow-engine/**"
- "!src/cli-client/**"
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved

jobs:
test-workflows:
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ Pull Requests 🚀.

### As a **Maintainer** ⛏ 🪨

Maintainers shall use Pull Requests (PRs) as an interface for asking the OCI
Maintainers can request new image builds and releases by either creating
Pull Requests (PRs) or via the OCI Factory CLI Client.

#### 1. With Pull Requests

Maintainers can use Pull Requests (PRs) as an interface for asking the OCI
Factory to build their images. Here's what you should do and know before you
make your first PR as a Maintainer:

Expand All @@ -84,6 +89,25 @@ multiple images;
- that means one PR can only propose changes to
[Maintainer files](#maintainer-files) within a single `oci` folder.

#### 2. With the CLI Client

Maintainers can use the OCI Factory's CLI Client to interact with the OCI
Factory. The CLI Client is a Go module at [src/cli-client](src/cli-client).

Here's what you should do and know before you use the CLI Client:

1. you **must** already be an onboarded Maintainer and have had significant
interactions with the OCI Factory (via PRs). Why is that? To use this client
you'll be granted write permissions to the repository, and thus you'll have
escalated rights when compared to a regular Maintainer - with great power
comes great maintainability,
2. each use of the CLI Client **must** only target one version of an OCI image,
i.e. you can ask the OCI Factory to build one version of the image, upload and
release it to GHCR, Docker Hub, and ECR with different tracks, risks and EOL with
a single command, but **not** multiple versions of the same image.

Further documentation regarding the CLI Client can be found [here](src/cli-client/README.md).

Refer to the diagram below to understand the oci-factory workflow:
![OCI Factory Workflow](assets/img/oci-factory-workflow.png)

Expand Down
Binary file modified assets/img/oci-factory-workflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/cli-client/README.md
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

# The OCI Factory CLI Client

A CLI client that triggers GitHub workflows for building, uploading and releasing images in
[OCI Factory](https://github.com/canonical/oci-factory).

## How to use

### New User

See ["How to Contribute as a Maintainer"](https://github.com/canonical/oci-factory?tab=readme-ov-file#as-a-maintainer--).

Upon finishing the onboarding, the user should receive a GitHub Personal Access Token. This token grants you proper
permissions to trigger the build, upload and release of your rocks. This token should never be shared with
third-parties, nor put anywhere that is publicly available.

The user will be asked to input the GitHub Personal Access Token upon triggering a workflow. For a non-interactive
terminal, it is possible to assign the token to the environmental variable `export GITHUB_TOKEN=<your token>`, and pass
`-y` to confirm the triggering by default.

### Install using Snap

```bash
sudo snap install oci-factory
```

### Install using Go

#### Dependencies
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved

```bash
# install git
sudo apt update && sudo apt install -y git
```

Golang-go can be installed either with APT or Snap:

```bash
# install golang-go with apt
sudo apt update && sudo apt install -y golang-go
```

```bash
# install golang-go with snap
sudo snap install go --classic
```

#### Install the CLI client
```bash
go install github.com/canonical/oci-factory/src/cli-client/cmd/oci-factory
```

# Triggering workflows
Note: The workflow can only be triggered for the rocks owned by Canonical, i.e., whose repository
belong to the organization Canonical in GitHub.
```bash
cd <directory containing rockcraft.yaml>
# Run `oci-factory upload --help` for more help
oci-factory upload --release track=<release track>,risks=<risk1>[,<risk2>...],eol=yyyy-mm-dd
```

## How to debug the CLI client

The debug log can be enabled with the following command

```bash
export LOGGER_DEBUG=1
```
14 changes: 14 additions & 0 deletions src/cli-client/cmd/oci-factory/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"os"

"github.com/canonical/oci-factory/src/cli-client/internals/cli"
"github.com/canonical/oci-factory/src/cli-client/internals/logger"
)

func main() {
logger.SetLogger(logger.New(os.Stderr, fmt.Sprintf("[%s] ", "oci-factory")))
cli.CliMain()
}
44 changes: 44 additions & 0 deletions src/cli-client/go.mod
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module github.com/canonical/oci-factory/src/cli-client

go 1.22.3
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/canonical/go-flags v0.0.0-20230403090104-105d09a091b8 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/src-d/gcfg v1.4.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading