Skip to content

Commit

Permalink
reorganize in subcommands and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tashima42 committed Nov 30, 2023
1 parent bfdb977 commit 87de17c
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 57 deletions.
69 changes: 69 additions & 0 deletions cmd/rke2_release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,75 @@ rke2_release components -l image-build-k8s-metrics-server
image-build-k8s-metrics-server|v0.6.3-build20231009
```

### image-build

#### list-repos
List all repos supported by this command

```sh
rke2_release image-build list-repos

> INFO[0000] Supported repos:
image-build-sriov-network-resources-injector
image-build-containerd
image-build-multus
image-build-ib-sriov-cni
image-build-sriov-network-device-plugin
image-build-cni-plugins
image-build-rke2-cloud-provider
image-build-dns-nodecache
image-build-k8s-metrics-server
image-build-calico
image-build-flannel
image-build-sriov-cni
image-build-whereabouts
image-build-etcd
image-build-runc
```

#### update
Updates references to the `hardened-build-base` docker image in the `rancher/image-build-*` repos.

| **Flag** | **Description** | **Required** |
| ----------------------------------- | --------------- | ------------ |
| `github-token`, `g`, `GITHUB_TOKEN` | Github Token | TRUE |
| `repo`, `r` | What image-build repo to update, use `rke2_release image-build list-repos` for a full list | TRUE |
| `owner`, `o` | Owner of the repo, default is 'rancher' only used for testing purposes | FALSE |
| `repo-path`, `p` | Local copy of the image-build repo that is being updated | TRUE |
| `working-dir`, `w` | Directory in which the temporary scripts will be created, default is /tmp | FALSE |
| `build-base-tag`, `t` | hardened-build-base Docker image tag to update the references in the repo to | TRUE |
| `dry-run`, `d` | Don't push changes to remote and don't create the PR, just log the information | FALSE |
| `create-pr`, `p` | If not set, the images will be pushed to a new branch, but a PR won't be created | FALSE |

**Examples**

```sh
export GITHUB_TOKEN={YOUR_GITHUB_TOKEN}

rke2_release image-build update --repo image-build-calico --repo-path /tmp/image-build-calico --build-base-tag v1.21.3b1 --create-pr --dry-run
```

```sh
export GITHUB_TOKEN={YOUR_GITHUB_TOKEN}

rke2_release image-build update -r image-build-calico -p /tmp/image-build-calico -t v1.21.3b1 -p -d
```

### Components

```sh
rke2_release components -l all
image-build-base |v1.21.3b1
image-build-calico |v3.26.1-build20231009
image-build-cni-plugins |v1.2.0-build20231009
...
```

```sh
rke2_release components -l image-build-k8s-metrics-server
image-build-k8s-metrics-server|v0.6.3-build20231009
```

## Contributions

- File Issue with details of the problem, feature request, etc.
Expand Down
2 changes: 1 addition & 1 deletion cmd/rke2_release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
app.Commands = []*cli.Command{
imageBuildBaseReleaseCommand(),
componentsCommand(),
updateImageBuildCommand(),
imageBuildCommand(),
}
app.Flags = rootFlags

Expand Down
126 changes: 73 additions & 53 deletions cmd/rke2_release/update_image_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,77 @@ import (

"github.com/rancher/ecm-distro-tools/release/rke2"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

func updateImageBuildCommand() *cli.Command {
func imageBuildCommand() *cli.Command {
return &cli.Command{
Name: "update-image-build",
Usage: "checks if a new release is available at rancher/image-build-base and updates the references at the rancher/image-build repos",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "github-token",
Aliases: []string{"g"},
EnvVars: []string{"GITHUB_TOKEN"},
Required: true,
Name: "image-build",
Subcommands: []*cli.Command{
{
Name: "list-repos",
Usage: "List all repos supported by this command",
Action: listRepos,
},
&cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Usage: "what image-build repo to update, use `rke2_release update-image-build list-repos` for a full list",
Required: true,
},
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Usage: "Owner of the repo, default is 'rancher' only used for testing purposes",
Value: "rancher",
Required: false,
},
&cli.StringFlag{
Name: "repo-path",
Aliases: []string{"c"},
Usage: "Local copy of the image-build repo that is being updated",
Required: true,
},
&cli.StringFlag{
Name: "working-dir",
Aliases: []string{"w"},
Usage: "Directory in which the temporary scripts will be created, default is /tmp",
Value: "/tmp",
Required: false,
},
&cli.StringFlag{
Name: "build-base-tag",
Aliases: []string{"t"},
Usage: "hardened-build-base Docker image tag to update the references in the repo to",
Required: true,
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"d"},
Usage: "don't push changes to remote and don't create the PR, just log the information",
Required: false,
},
&cli.BoolFlag{
Name: "create-pr",
Aliases: []string{"p"},
Usage: "If not set, the images will be pushed to a new branch, but a PR won't be created",
Required: false,
{
Name: "update",
Usage: "updates hardened-build-base references in the rancher/image-build-* repos",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "github-token",
Aliases: []string{"g"},
EnvVars: []string{"GITHUB_TOKEN"},
Required: true,
},
&cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Usage: "What image-build repo to update, use `rke2_release image-build list-repos` for a full list",
Required: true,
},
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Usage: "Owner of the repo, default is 'rancher' only used for testing purposes",
Value: "rancher",
Required: false,
},
&cli.StringFlag{
Name: "repo-path",
Aliases: []string{"c"},
Usage: "Local copy of the image-build repo that is being updated",
Required: true,
},
&cli.StringFlag{
Name: "working-dir",
Aliases: []string{"w"},
Usage: "Directory in which the temporary scripts will be created, default is /tmp",
Value: "/tmp",
Required: false,
},
&cli.StringFlag{
Name: "build-base-tag",
Aliases: []string{"t"},
Usage: "hardened-build-base Docker image tag to update the references in the repo to",
Required: true,
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"d"},
Usage: "Don't push changes to remote and don't create the PR, just log the information",
Required: false,
},
&cli.BoolFlag{
Name: "create-pr",
Aliases: []string{"p"},
Usage: "If not set, the images will be pushed to a new branch, but a PR won't be created",
Required: false,
},
},
Action: updateImageBuild,
},
},
Action: updateImageBuild,
}
}

Expand All @@ -81,3 +92,12 @@ func updateImageBuild(c *cli.Context) error {
ghClient := repository.NewGithub(ctx, token)
return rke2.UpdateImageBuild(ctx, ghClient, repo, owner, repoPath, workingDir, buildBaseTag, dryRun, createPR)
}

func listRepos(c *cli.Context) error {
repos := ""
for k := range rke2.ImageBuildRepos {
repos += " " + k + "\n"
}
logrus.Info("Supported repos: \n" + repos)
return nil
}
6 changes: 3 additions & 3 deletions release/rke2/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type UpdateImageBuildArgs struct {
CurrentTag string
}

var imageBuildRepos map[string]bool = map[string]bool{
var ImageBuildRepos map[string]bool = map[string]bool{
"image-build-dns-nodecache": true,
"image-build-k8s-metrics-server": true,
"image-build-sriov-cni": true,
Expand Down Expand Up @@ -170,8 +170,8 @@ func goVersions(goDevURL string) ([]goVersionRecord, error) {
}

func UpdateImageBuild(ctx context.Context, ghClient *github.Client, repo, owner, repoPath, workingDir, newTag string, dryRun, createPR bool) error {
if _, ok := imageBuildRepos[repo]; !ok {
return errors.New("invalid repo, please review the `imageBuildRepos` map")
if _, ok := ImageBuildRepos[repo]; !ok {
return errors.New("invalid repo, please review the supported repos list")
}
branchName := "update-to-" + newTag
data := UpdateImageBuildArgs{
Expand Down

0 comments on commit 87de17c

Please sign in to comment.