Param. des variables OCDEPLOY_

This commit is contained in:
admju 2024-09-12 13:12:17 +00:00
parent 3481bccc22
commit 5d4de618dd
8 changed files with 41 additions and 24 deletions

View File

@ -6,10 +6,10 @@ version: 1.0
tools:
- name: kubectl
url: https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl
version: v1.30.3
version: v1.31.0
- name: helm
url: https://get.helm.sh/helm-%s-linux-amd64.tar.gz
version: v3.15.4
version: v3.16.0
# helm install my-release <repo>/<chart>
opencloud:

View File

@ -77,4 +77,9 @@ Test generate _.coverage.html_ file to view the coverage of test.
## To Publish
Cf : ../publish
Cf : ../publish
## Divers
* Latest version for _kubectl_: https://dl.k8s.io/release/stable.txt
* Release for _helm_: https://github.com/helm/helm/releases

View File

@ -24,9 +24,9 @@ func cobraInstallCmd() *cobra.Command {
Long: `deploy Charts`,
Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return InstallCmd(context, version, modules)
return InstallCmd(context, "v"+version, modules)
},
Example: "oc-deploy install --version 1.0 --context ex1",
Example: "oc-deploy install --version 0.1.0 --context ex1",
}
}
@ -51,9 +51,9 @@ func cobraGenerateCmd() *cobra.Command{
Long: "Value",
Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return GenerateCmd(context, version)
return GenerateCmd(context, "v"+version)
},
Example: "oc-deploy generate --version 1.0 --context ex1",
Example: "oc-deploy generate --version 0.1.0 --context ex1",
}
}

View File

@ -1,6 +1,18 @@
package occonst
var ONLINE_URL = "https://cloud.o-forge.io"
var ONLINE_VERSION = "core/oc-deploy"
import (
"os"
)
var OFFLINE_DIR = "../../offline"
var OCDEPLOY_ONLINE_URL = getenv("OCDEPLOY_ONLINE_URL", "https://cloud.o-forge.io")
var OCDEPLOY_ONLINE_REPO = getenv("OCDEPLOY_ONLINE_REPO", "core/oc-version")
var OCDEPLOY_OFFLINE_DIR = getenv("OCDEPLOY_OFFLINE_DIR", "../../offline")
func getenv(key string, defaut string) string {
value := os.Getenv(key)
if len(value) == 0 {
return defaut
}
return value
}

View File

@ -29,7 +29,7 @@ func GetFromOffline(version string) (string, string, error) {
}
ficversion := fmt.Sprintf("oc_%s.yml", version2)
src := filepath.Join(occonst.OFFLINE_DIR, ficversion)
src := filepath.Join(occonst.OCDEPLOY_OFFLINE_DIR, ficversion)
if _, err := os.Stat(src); err != nil {
log.Log().Debug().Msg(err.Error())
return "", "", errors.New("Version non disponible")
@ -47,7 +47,7 @@ func GetFromOffline(version string) (string, string, error) {
// readLatestFile : Lit le numéro de la version dans le fichier lastest.yml
func readLatestFromOffline() (string, error) {
src := filepath.Join(occonst.OFFLINE_DIR, "latest.yml")
src := filepath.Join(occonst.OCDEPLOY_OFFLINE_DIR, "latest.yml")
fin, err := os.Open(src)
if err != nil {

View File

@ -18,10 +18,10 @@ func TestGetOffline(t *testing.T) {
func TestGetLatest(t *testing.T) {
occonst.OFFLINE_DIR = filepath.Join(TEST_SRC_DIR, "offline")
occonst.OCDEPLOY_OFFLINE_DIR = filepath.Join(TEST_SRC_DIR, "offline")
version, _, err := GetFromOffline("latest")
assert.Nilf(t, err, "error message %s", err)
assert.Equal(t, "99.1", version, "TestGetFromFile error")
}
}

View File

@ -46,8 +46,8 @@ type ocJsonStruct struct {
func readLatestFromOnline() (string, error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/latest",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION)
occonst.OCDEPLOY_ONLINE_URL,
occonst.OCDEPLOY_ONLINE_REPO)
res, err := http.Get(url)
if err != nil {
@ -72,8 +72,8 @@ func readLatestFromOnline() (string, error) {
func getFileVersion(version string) (string, error) {
url := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION,
occonst.OCDEPLOY_ONLINE_URL,
occonst.OCDEPLOY_ONLINE_REPO,
version)
res, err := http.Get(url)

View File

@ -18,8 +18,8 @@ func TestGetOnline(t *testing.T) {
version := "99.1"
url := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION,
occonst.OCDEPLOY_ONLINE_URL,
occonst.OCDEPLOY_ONLINE_REPO,
version)
httpmock.RegisterResponder("GET", url,
@ -37,16 +37,16 @@ func TestGetOnlineLatest(t *testing.T) {
// version := "99.1"
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/latest",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION)
occonst.OCDEPLOY_ONLINE_URL,
occonst.OCDEPLOY_ONLINE_REPO)
httpmock.RegisterResponder("GET", url,
httpmock.NewStringResponder(200, `{"name": "99.0", "id": 2}`))
version := "99.0"
url2 := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION,
occonst.OCDEPLOY_ONLINE_URL,
occonst.OCDEPLOY_ONLINE_REPO,
version)
httpmock.RegisterResponder("GET", url2,