Skip to content

Commit 4d0cbe9

Browse files
authored
fixed runtime url (#20)
* upload runtime.yaml as artifact * download latest runtime.yaml artifact * replace version correctly * moved version to flag
1 parent 618c52d commit 4d0cbe9

File tree

10 files changed

+59
-35
lines changed

10 files changed

+59
-35
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
VERSION=v0.0.25
1+
VERSION=v0.0.26
22
OUT_DIR=dist
33
YEAR?=$(shell date +"%Y")
44

55
CLI_NAME?=cf
66
IMAGE_REPOSITORY?=quay.io
77
IMAGE_NAMESPACE?=codefresh
88

9-
RUNTIME_DEF_URL="https://github.com/codefresh-io/cli-v2/manifests/runtime.yaml"
9+
RUNTIME_DEF_URL="https://github.com/codefresh-io/cli-v2/releases/latest/download/runtime.yaml"
1010

1111
DEV_RUNTIME_DEF_URL="manifests/runtime.yaml"
1212

build/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ steps:
2727
- cf_export GOCACHE=/codefresh/volume/gocache # change gopath to codefresh shared volume
2828
- cf_export GOPATH=/codefresh/volume/gopath
2929
- cf_export PATH=$PATH:/codefresh/volume/gopath/bin
30-
- cf_export LATEST_VERSION=$(curl --silent -H "Authorization:Bearer ${{GITHUB_TOKEN}}" "https://api.github.com/repos/codefresh-io/cli-v2/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
30+
- cf_export LATEST_VERSION=$(curl --silent -H "Authorization:Bearer ${{GITHUB_TOKEN}}" "https://api.github.com/repos/codefresh-io/cli-v2/releases/latest" | jq -r ".tag_name")
3131
- cf_export VERSION=$(make cur-version)
3232
when:
3333
steps:

cmd/commands/runtime.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
type (
5252
RuntimeInstallOptions struct {
5353
RuntimeName string
54+
Version *semver.Version
5455
gsCloneOpts *git.CloneOptions
5556
insCloneOpts *git.CloneOptions
5657
KubeFactory kube.Factory
@@ -91,6 +92,7 @@ func NewRuntimeCommand() *cobra.Command {
9192

9293
func NewRuntimeInstallCommand() *cobra.Command {
9394
var (
95+
versionStr string
9496
f kube.Factory
9597
insCloneOpts *git.CloneOptions
9698
gsCloneOpts *git.CloneOptions
@@ -127,20 +129,33 @@ func NewRuntimeInstallCommand() *cobra.Command {
127129
gsCloneOpts.Parse()
128130
},
129131
RunE: func(cmd *cobra.Command, args []string) error {
132+
var (
133+
version *semver.Version
134+
err error
135+
)
130136
ctx := cmd.Context()
131137
if len(args) < 1 {
132138
log.G(ctx).Fatal("must enter runtime name")
133139
}
134140

141+
if versionStr != "" {
142+
version, err = semver.NewVersion(versionStr)
143+
if err != nil {
144+
return err
145+
}
146+
}
147+
135148
return RunRuntimeInstall(ctx, &RuntimeInstallOptions{
136149
RuntimeName: args[0],
150+
Version: version,
137151
gsCloneOpts: gsCloneOpts,
138152
insCloneOpts: insCloneOpts,
139153
KubeFactory: f,
140154
})
141155
},
142156
}
143157

158+
cmd.Flags().StringVar(&versionStr, "version", "", "The runtime version to install, defaults to latest")
144159
insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
145160
Prefix: "install",
146161
CreateIfNotExist: true,
@@ -158,13 +173,13 @@ func NewRuntimeInstallCommand() *cobra.Command {
158173
}
159174

160175
func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
161-
rt, err := runtime.Download(nil, opts.RuntimeName)
176+
rt, err := runtime.Download(opts.Version, opts.RuntimeName)
162177
if err != nil {
163178
return fmt.Errorf("failed to download runtime definition: %w", err)
164179
}
165180

166181
err = apcmd.RunRepoBootstrap(ctx, &apcmd.RepoBootstrapOptions{
167-
AppSpecifier: rt.Spec.BootstrapSpecifier,
182+
AppSpecifier: rt.Spec.FullSpecifier(),
168183
Namespace: opts.RuntimeName,
169184
KubeFactory: opts.KubeFactory,
170185
CloneOptions: opts.insCloneOpts,
@@ -183,7 +198,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
183198

184199
for _, component := range rt.Spec.Components {
185200
log.G(ctx).Infof("creating component '%s'", component.Name)
186-
if err = component.CreateApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName); err != nil {
201+
if err = component.CreateApp(ctx, opts.KubeFactory, opts.insCloneOpts, opts.RuntimeName, rt.Spec.Version); err != nil {
187202
return fmt.Errorf("failed to create '%s' application: %w", component.Name, err)
188203
}
189204
}
@@ -327,7 +342,8 @@ func RunRuntimeUninstall(ctx context.Context, opts *RuntimeUninstallOptions) err
327342

328343
func NewRuntimeUpgradeCommand() *cobra.Command {
329344
var (
330-
cloneOpts *git.CloneOptions
345+
versionStr string
346+
cloneOpts *git.CloneOptions
331347
)
332348

333349
cmd := &cobra.Command{
@@ -351,14 +367,20 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
351367
cloneOpts.Parse()
352368
},
353369
RunE: func(cmd *cobra.Command, args []string) error {
354-
var version *semver.Version
370+
var (
371+
version *semver.Version
372+
err error
373+
)
355374
ctx := cmd.Context()
356375
if len(args) < 1 {
357376
log.G(ctx).Fatal("must enter runtime name")
358377
}
359378

360-
if len(args) > 1 {
361-
version = semver.MustParse(args[1])
379+
if versionStr != "" {
380+
version, err = semver.NewVersion(versionStr)
381+
if err != nil {
382+
return err
383+
}
362384
}
363385

364386
return RunRuntimeUpgrade(ctx, &RuntimeUpgradeOptions{
@@ -369,6 +391,7 @@ func NewRuntimeUpgradeCommand() *cobra.Command {
369391
},
370392
}
371393

394+
cmd.Flags().StringVar(&versionStr, "version", "", "The runtime version to upgrade to, defaults to latest")
372395
cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
373396
FS: memfs.New(),
374397
})
@@ -415,7 +438,7 @@ func RunRuntimeUpgrade(ctx context.Context, opts *RuntimeUpgradeOptions) error {
415438

416439
for _, component := range newComponents {
417440
log.G(ctx).Infof("Creating app '%s'", component.Name)
418-
if err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName); err != nil {
441+
if err = component.CreateApp(ctx, nil, opts.CloneOpts, opts.RuntimeName, newRt.Spec.Version); err != nil {
419442
return fmt.Errorf("failed to create '%s' application: %w", component.Name, err)
420443
}
421444
}
@@ -455,7 +478,7 @@ func createComponentsReporter(ctx context.Context, cloneOpts *git.CloneOptions,
455478
Type: application.AppTypeDirectory,
456479
URL: cloneOpts.URL() + "/" + resPath,
457480
}
458-
if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName); err != nil {
481+
if err := appDef.CreateApp(ctx, opts.KubeFactory, cloneOpts, opts.RuntimeName, nil); err != nil {
459482
return err
460483
}
461484

@@ -835,7 +858,7 @@ func createGitSource(ctx context.Context, insCloneOpts *git.CloneOptions, gsClon
835858
Type: application.AppTypeDirectory,
836859
URL: insCloneOpts.URL() + insFs.Join(insFs.Root(), resPath),
837860
}
838-
if err = appDef.CreateApp(ctx, nil, insCloneOpts, runtimeName); err != nil {
861+
if err = appDef.CreateApp(ctx, nil, insCloneOpts, runtimeName, nil); err != nil {
839862
return fmt.Errorf("failed to create git-source: %w", err)
840863
}
841864

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cli-v2 runtime install [runtime_name] [flags]
3737
--install-repo string Repository URL [INSTALL_GIT_REPO]
3838
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
3939
-n, --namespace string If present, the namespace scope for this CLI request
40+
--version string The runtime version to install, defaults to latest
4041
```
4142

4243
### Options inherited from parent commands

docs/commands/cli-v2_runtime_upgrade.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ cli-v2 runtime upgrade [runtime_name] [flags]
3131
-t, --git-token string Your git provider api token [GIT_TOKEN]
3232
-h, --help help for upgrade
3333
--repo string Repository URL [GIT_REPO]
34+
--version string The runtime version to upgrade to, defaults to latest
3435
```
3536

3637
### Options inherited from parent commands

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
### Linux
99
```bash
1010
# download and extract the binary
11-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.24/cf-linux-amd64.tar.gz | tar zx
11+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.26/cf-linux-amd64.tar.gz | tar zx
1212

1313
# move the binary to your $PATH
1414
mv ./cf-* /usr/local/bin/cf
@@ -20,7 +20,7 @@ cf version
2020
### Mac
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.24/cf-darwin-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.26/cf-darwin-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-* /usr/local/bin/cf

hack/build.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,5 @@ go build -ldflags=" \
1313
-X 'github.com/codefresh-io/cli-v2/pkg/store.version=${VERSION}' \
1414
-X 'github.com/codefresh-io/cli-v2/pkg/store.buildDate=${BUILD_DATE}' \
1515
-X 'github.com/codefresh-io/cli-v2/pkg/store.gitCommit=${GIT_COMMIT}' \
16-
-X 'github.com/codefresh-io/cli-v2/pkg/store.ArgoCDManifestsURL=${ARGOCD_INSTALLATION_MANIFESTS_URL}' \
17-
-X 'github.com/codefresh-io/cli-v2/pkg/store.ArgoEventsManifestsURL=${EVENTS_INSTALLATION_MANIFESTS_URL}' \
18-
-X 'github.com/codefresh-io/cli-v2/pkg/store.ArgoRolloutsManifestsURL=${ROLLOUTS_INSTALLATION_MANIFESTS_URL}' \
19-
-X 'github.com/codefresh-io/cli-v2/pkg/store.ArgoWorkflowsManifestsURL=${WORKFLOWS_INSTALLATION_MANIFESTS_URL}'" \
16+
-X 'github.com/codefresh-io/cli-v2/pkg/store.RuntimeDefURL=${RUNTIME_DEF_URL}'" \
2017
-v -o ${OUT_FILE} ${MAIN}

hack/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ if [[ "$DRY_RUN" == "1" ]]; then
3838
exit 0
3939
fi
4040

41-
gh release create --repo $GIT_REPO -t $VERSION -F $FILE --prerelease=$PRERELEASE $VERSION ./dist/*.tar.gz ./dist/*.sha256
41+
gh release create --repo $GIT_REPO -t $VERSION -F $FILE --prerelease=$PRERELEASE $VERSION ./dist/*.tar.gz ./dist/*.sha256 ./manifests/runtime.yaml

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.25
8+
version: 0.0.26
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/runtime/runtime.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,12 @@ func Download(version *semver.Version, name string) (*Runtime, error) {
7070
)
7171

7272
if strings.HasPrefix(store.RuntimeDefURL, "http") {
73-
urlObj, err := url.Parse(store.RuntimeDefURL)
74-
if err != nil {
75-
return nil, fmt.Errorf("failed parsing url: %w", err)
76-
}
77-
78-
if urlObj.Query().Get("ref") == "" {
79-
urlObj.Query().Set("ref", version.String())
73+
urlString := store.RuntimeDefURL
74+
if version != nil {
75+
urlString = strings.Replace(urlString, "/releases/latest/download", "/releases/download/v"+version.String(), 1)
8076
}
8177

82-
res, err := http.Get(urlObj.String())
78+
res, err := http.Get(urlString)
8379
if err != nil {
8480
return nil, fmt.Errorf("failed to download runtime definition: %w", err)
8581
}
@@ -161,7 +157,7 @@ func (r *Runtime) Upgrade(fs fs.FS, newRt *Runtime) ([]AppDef, error) {
161157
func (r *RuntimeSpec) upgrade(fs fs.FS, newRt *RuntimeSpec) ([]AppDef, error) {
162158
log.G().Infof("Upgrading bootstrap specifier")
163159
argocdFilename := fs.Join(apstore.Default.BootsrtrapDir, apstore.Default.ArgoCDName, "kustomization.yaml")
164-
if err := updateKustomization(fs, argocdFilename, r.fullSpecifier(), newRt.fullSpecifier()); err != nil {
160+
if err := updateKustomization(fs, argocdFilename, r.FullSpecifier(), newRt.FullSpecifier()); err != nil {
165161
return nil, fmt.Errorf("failed to upgrade bootstrap specifier: %w", err)
166162
}
167163

@@ -205,11 +201,11 @@ func (a *RuntimeSpec) component(name string) *AppDef {
205201
return nil
206202
}
207203

208-
func (r *RuntimeSpec) fullSpecifier() string {
204+
func (r *RuntimeSpec) FullSpecifier() string {
209205
return buildFullURL(r.BootstrapSpecifier, r.DefVersion)
210206
}
211207

212-
func (a *AppDef) CreateApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName string) error {
208+
func (a *AppDef) CreateApp(ctx context.Context, f kube.Factory, cloneOpts *git.CloneOptions, projectName string, version *semver.Version) error {
213209
timeout := time.Duration(0)
214210
if a.Wait {
215211
timeout = store.Get().WaitTimeout
@@ -221,7 +217,7 @@ func (a *AppDef) CreateApp(ctx context.Context, f kube.Factory, cloneOpts *git.C
221217
ProjectName: projectName,
222218
AppOpts: &application.CreateOptions{
223219
AppName: a.Name,
224-
AppSpecifier: a.URL,
220+
AppSpecifier: buildFullURL(a.URL, version),
225221
AppType: a.Type,
226222
DestNamespace: projectName,
227223
},
@@ -260,9 +256,15 @@ func updateKustomization(fs fs.FS, filename, fromURL, toURL string) error {
260256
}
261257

262258
func buildFullURL(urlString string, version *semver.Version) string {
259+
if version == nil {
260+
return urlString
261+
}
262+
263263
urlObj, _ := url.Parse(urlString)
264-
if urlObj.Query().Get("ref") == "" {
265-
urlObj.Query().Add("ref", version.String())
264+
v := urlObj.Query()
265+
if v.Get("ref") == "" {
266+
v.Add("ref", version.String())
267+
urlObj.RawQuery = v.Encode()
266268
}
267269

268270
return urlObj.String()

0 commit comments

Comments
 (0)