-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add image-build-base-release command
- Loading branch information
Showing
9 changed files
with
222 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
name: ECM Distro Tools Release | ||
on: | ||
push: | ||
tags: | ||
- "v*" | ||
push: | ||
tags: | ||
- "v*" | ||
jobs: | ||
release: | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Build ECM Distro Tools | ||
run: | | ||
|
@@ -19,7 +19,7 @@ jobs: | |
uses: SierraSoftworks/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
overwrite: 'true' | ||
overwrite: "true" | ||
files: | | ||
${{ github.workspace }}/bin/bootstrap_hash | ||
${{ github.workspace }}/bin/check_for_k8s_release | ||
|
@@ -38,6 +38,7 @@ jobs: | |
${{ github.workspace }}/cmd/gen_release_notes/bin/* | ||
${{ github.workspace }}/cmd/k3s_release/bin/* | ||
${{ github.workspace }}/cmd/rancher_release/bin/* | ||
${{ github.workspace }}/cmd/rke2_release/bin/* | ||
${{ github.workspace }}/cmd/standup/bin/* | ||
${{ github.workspace }}/cmd/test_coverage/bin/* | ||
${{ github.workspace }}/cmd/upstream_go_version/bin/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
include ../Makefile | ||
|
||
GO = go | ||
|
||
BINDIR := bin | ||
BINARY := rke2_release | ||
|
||
VERSION = v0.1.0 | ||
GIT_SHA = $(shell git rev-parse HEAD) | ||
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings' | ||
TAGS = "netgo osusergo no_stage static_build" | ||
|
||
$(BINDIR)/$(BINARY): clean | ||
for arch in $(ARCHS); do \ | ||
for os in $(OSs); do \ | ||
$(GO_COMPILE) ; \ | ||
done; \ | ||
done | ||
|
||
.PHONY: clean | ||
clean: | ||
$(GO) clean | ||
rm -f $(BINDIR)/$(BINARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# rke2_release | ||
|
||
rke2_release is a utility that performs the bulk of the actions to complete a rke2 release. | ||
|
||
Please reference the help menu from the binary. | ||
|
||
## Commands | ||
|
||
### image-build-base-release | ||
|
||
Checks if new Golang versions are available and creates new releases in `rancher/image-build-base` | ||
|
||
| **Flag** | **Description** | **Required** | | ||
| ----------------------------------- | --------------- | ------------ | | ||
| `github-token`, `g`, `GITHUB_TOKEN` | Github Token | TRUE | | ||
|
||
**Examples** | ||
|
||
``` | ||
export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} | ||
rke2_release image-build-base-release | ||
``` | ||
|
||
## Contributions | ||
|
||
- File Issue with details of the problem, feature request, etc. | ||
- Submit a pull request and include details of what problem or feature the code is solving or implementing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var rootFlags = []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "config", | ||
Aliases: []string{"c"}, | ||
Usage: "Specify release config file", | ||
EnvVars: []string{"RELEASE_CONFIG"}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "debug", | ||
Aliases: []string{"d"}, | ||
Usage: "Debug mode", | ||
}, | ||
} | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "rke2-release" | ||
app.Usage = "Perform a rke2 release" | ||
app.UseShortOptionHandling = true | ||
app.Commands = []*cli.Command{ | ||
imageBuildBaseReleaseCommand(), | ||
} | ||
app.Flags = rootFlags | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
logrus.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/rancher/ecm-distro-tools/release/rke2" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func imageBuildBaseReleaseCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "image-build-base-release", | ||
Usage: "checks if new golang versions are available and creates new releases for rancher/image-build-base", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "github-token", | ||
Aliases: []string{"g"}, | ||
EnvVars: []string{"GITHUB_TOKEN"}, | ||
Required: true, | ||
}, | ||
}, | ||
Action: imageBuildBaseRelease, | ||
} | ||
} | ||
|
||
func imageBuildBaseRelease(c *cli.Context) error { | ||
token := c.String("github-token") | ||
if token == "" { | ||
return errors.New("env var GITHUB_TOKEN is required") | ||
} | ||
return rke2.ImageBuildBaseRelease(context.Background(), token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package rke2 | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/google/go-github/v39/github" | ||
ecmHTTP "github.com/rancher/ecm-distro-tools/http" | ||
"github.com/rancher/ecm-distro-tools/repository" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
goDevURL = "https://go.dev/dl/?mode=json" | ||
githubApiURL = "https://api.github.com/" | ||
imageBuildBaseRepo = "image-build-base" | ||
) | ||
|
||
type goVersionRecord struct { | ||
Version string `json:"version"` | ||
Stable bool `json:"stable"` | ||
} | ||
|
||
type GithubRelease struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
func ImageBuildBaseRelease(ctx context.Context, githubToken string) error { | ||
versions, err := goVersions(goDevURL) | ||
if err != nil { | ||
return err | ||
} | ||
ghClient := repository.NewGithub(ctx, githubToken) | ||
imageBuildBaseOrg, err := repository.OrgFromRepo(imageBuildBaseRepo) | ||
if err != nil { | ||
return err | ||
} | ||
for _, version := range versions { | ||
logrus.Info("version: " + version.Version) | ||
if !version.Stable { | ||
logrus.Info("version " + version.Version + " is not stable") | ||
continue | ||
} | ||
v := "v" + strings.Split(version.Version, "go")[1] + "b1" | ||
logrus.Info("stripped version: " + v) | ||
_, _, err := ghClient.Repositories.GetReleaseByTag(ctx, imageBuildBaseOrg, imageBuildBaseRepo, v) | ||
if err == nil { | ||
logrus.Info("release " + v + " already exists") | ||
continue | ||
} | ||
logrus.Info("release " + v + " doesn't exists, creating release") | ||
_, _, err = ghClient.Repositories.CreateRelease(ctx, imageBuildBaseOrg, imageBuildBaseRepo, &github.RepositoryRelease{ | ||
TagName: github.String(v), | ||
Name: github.String(v), | ||
Prerelease: github.Bool(false), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
logrus.Info("created release for version: " + v) | ||
} | ||
return nil | ||
} | ||
|
||
func goVersions(goDevURL string) ([]goVersionRecord, error) { | ||
httpClient := ecmHTTP.NewClient(time.Second * 15) | ||
res, err := httpClient.Get(goDevURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return nil, errors.New("failed to get stable go versions") | ||
} | ||
|
||
var versions []goVersionRecord | ||
if err := json.NewDecoder(res.Body).Decode(&versions); err != nil { | ||
return nil, err | ||
} | ||
return versions, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters