Compare commits
No commits in common. "95884e14d64a21cecf9fc5735d4c2258f84dad58" and "9f0218a4da5ae4a63aaf6e4941921774ac87b791" have entirely different histories.
95884e14d6
...
9f0218a4da
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1 @@
|
||||
bin
|
||||
*.base64
|
||||
env
|
||||
|
31
Makefile
31
Makefile
@ -1,27 +1,6 @@
|
||||
#!make
|
||||
|
||||
include env
|
||||
export
|
||||
|
||||
ifndef OC_VERSION
|
||||
$(error OC_VERSION is not set)
|
||||
endif
|
||||
|
||||
ifndef PUBLISH_TOKEN
|
||||
$(error PUBLISH_TOKEN is not set)
|
||||
endif
|
||||
|
||||
PUBLISH_REPO := "core/oc-deploy"
|
||||
PUBLISH_BRANCH := main
|
||||
|
||||
.PHONY: publish
|
||||
publish:
|
||||
@echo Publication de : ${OC_VERSION}
|
||||
@(cd publish && \
|
||||
PUBLISH_REPO=${PUBLISH_REPO} \
|
||||
PUBLISH_TOKEN=${PUBLISH_TOKEN} \
|
||||
PUBLISH_BRANCH=${PUBLISH_BRANCH} \
|
||||
go run main.go ${OC_VERSION})
|
||||
|
||||
clean:
|
||||
@rm *.base64
|
||||
curl -X 'POST' \
|
||||
'https://cloud.o-forge.io/api/v1/repos/core/oc-deploy/releases/2/assets?name=oc.json&token=92ad0a4b3d75ec7c5964913b7085d7ddf379247c' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: multipart/form-data' \
|
||||
-F 'attachment=@oc.json;type=application/json'
|
93
README.md
93
README.md
@ -17,101 +17,20 @@ It thus contains a first optional installation layer which deploys the Kubernete
|
||||
|
||||
This documentation will be updated with the needed command and/or requirements to properly execute the installation.
|
||||
|
||||
|
||||
# oc-deploy tools
|
||||
|
||||
## Usage
|
||||
|
||||
| Command | Description |
|
||||
| ----------------------------------------------------------------------------- | --------------------------- |
|
||||
| ```oc-deploy``` | Display help |
|
||||
| ```oc-deploy version``` | Display the version of tool |
|
||||
| ```oc-deploy install [-c\|--context <context>] [-v\|--version <OcVersion>]``` | Deploy an OpenCloud |
|
||||
| ```oc-deploy uninstall [-c\|--context <context>]``` | Undeploy an OpenCloud |
|
||||
|
||||
| Arguments | Description | Default |
|
||||
| ---------------- | --------------------------- | ------------ |
|
||||
| ```context``` | Context Kubernetes | _opencloud_ |
|
||||
| ```OcVersion``` | Specific version or latest | _latest_ |
|
||||
|
||||
## Principe
|
||||
|
||||
* Download an "OpenCloud file version" : oc_<version>.yml from relase on GitEa (core/oc-version).
|
||||
* Initialise an workspace direcotry : ./workspace_<contextK8S>
|
||||
* Install tools as describe, if not found on the path :
|
||||
* Helm
|
||||
* Kubectl
|
||||
* Check if the Cluster (context) is available
|
||||
* Install all charts as describe :
|
||||
* Charts : from Harbor or local
|
||||
* Images : from Harbor or local
|
||||
* Check if componants are available
|
||||
|
||||
## Pre-requis
|
||||
|
||||
**oc-deploy** need to access to an Kubernetes Cluster, c'est-à-dire : kubeconfig.
|
||||
|
||||
**oc-deploy** need to access to Internet :
|
||||
|
||||
* to download the _oc.json_ file (contient _oc.yml_) :
|
||||
* Url : https://cloud.o-forge.io/core/oc-deploy/releases
|
||||
* to download _kubectl_ and _helm_ tools if
|
||||
* Url : Urls are specified into _oc.yml_
|
||||
|
||||
## Dev
|
||||
|
||||
Cf. src/README.md
|
||||
|
||||
## Publish
|
||||
|
||||
Publish in the relase GitEa the binary (the binary is base64 coding).
|
||||
|
||||
Set **env** file to overwrite varibable as :
|
||||
|
||||
#!make
|
||||
PUBLISH_TOKEN = <gitea_token>
|
||||
|
||||
To publish :
|
||||
|
||||
OC_VERSION = <x.y.z> make publish
|
||||
|
||||
# Installation on Kubernetes
|
||||
|
||||
## Minikube
|
||||
|
||||
TO DO
|
||||
|
||||
## Kubernetes
|
||||
|
||||
TO DO
|
||||
|
||||
## RKE2
|
||||
|
||||
TO DO
|
||||
|
||||
## OpenShift
|
||||
|
||||
TO DO
|
||||
|
||||
# Installation on Docker
|
||||
|
||||
Without Kubernetes, for dev in Docker
|
||||
|
||||
## Install brew
|
||||
# Deploy cluster
|
||||
## For dev in Docker
|
||||
Install brew
|
||||
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
|
||||
## Install Talos
|
||||
Install Talos
|
||||
|
||||
brew install siderolabs/tap/talosctl
|
||||
talosctl cluster create
|
||||
## Install helm
|
||||
# Install helm
|
||||
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
||||
chmod 700 get_helm.sh
|
||||
./get_helm.sh
|
||||
|
||||
## Create OpenCloud Chart
|
||||
|
||||
Obsolete : use oc-deploy tool
|
||||
|
||||
# Create OpenCloud Chart
|
||||
helm create occhart
|
||||
|
@ -1,83 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"encoding/base64"
|
||||
"oc-publish/releases"
|
||||
"oc-publish/occonst"
|
||||
"fmt"
|
||||
"os"
|
||||
"oc-publish/releases"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
version := os.Args[1]
|
||||
fmt.Println(" >> oc-publish :")
|
||||
|
||||
fmt.Printf(" >> oc-publish :\n")
|
||||
version := os.Args[1]
|
||||
fmt.Println(fmt.Sprintf(" << version : %s", version))
|
||||
|
||||
fmt.Printf(" << Url : %s/%s\n", occonst.PUBLISH_URL, occonst.PUBLISH_REPO)
|
||||
existe, _ := releases.CheckRelease(version)
|
||||
fmt.Println(fmt.Sprintf(" << existe : %t ", existe))
|
||||
|
||||
fmt.Printf(" << version : %s %s\n", version, occonst.PUBLISH_BRANCH)
|
||||
idRelease, _ := releases.GetReleaseId(version)
|
||||
fmt.Println(fmt.Sprintf(" << id : %d ", idRelease))
|
||||
|
||||
vversion := fmt.Sprintf("v%s", version)
|
||||
existe, _ := releases.CheckRelease(vversion)
|
||||
idAsset, _ := releases.GetAssetId(idRelease, "oc.json")
|
||||
fmt.Println(fmt.Sprintf(" << idAsset : %d ", idAsset))
|
||||
|
||||
if existe == false {
|
||||
err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
idRelease, _ := releases.GetReleaseId(vversion)
|
||||
if existe == true {
|
||||
fmt.Println(fmt.Sprintf(" << Release existante : %d ", idRelease))
|
||||
} else {
|
||||
fmt.Println(fmt.Sprintf(" << Release crée : %d ", idRelease))
|
||||
}
|
||||
|
||||
assetname := "oc-deploy.base64"
|
||||
binary := fmt.Sprintf("../bin/oc-deploy")
|
||||
binary64 := fmt.Sprintf("../%s", assetname)
|
||||
err := createBinaryFile(binary, binary64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
idAsset, _ := releases.GetAssetId(idRelease, assetname)
|
||||
if idAsset == 0 {
|
||||
fmt.Println(fmt.Sprintf(" << Ajout Asset : %s", assetname))
|
||||
err := releases.CreateAsset(idRelease, binary64, assetname)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(fmt.Sprintf(" << Mise à jour : %s (idAsset=%d) ", assetname, idAsset))
|
||||
err := releases.UpdateAsset(idRelease, idAsset, binary64, assetname)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Println(releases.CreateAsset(idRelease, "../bin/oc-deploy"))
|
||||
|
||||
}
|
||||
|
||||
|
||||
func createBinaryFile(source string, dest string) error {
|
||||
fout, _ := os.Create(dest)
|
||||
defer fout.Close()
|
||||
|
||||
byteValue, err := ioutil.ReadFile(source)
|
||||
if err != nil {
|
||||
fmt.Println("64e", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
data64 := base64.StdEncoding.EncodeToString(byteValue)
|
||||
fout.Write([]byte(data64))
|
||||
return nil
|
||||
}
|
||||
|
@ -1,18 +1,6 @@
|
||||
package occonst
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
var PUBLISH_URL = "https://cloud.o-forge.io"
|
||||
var PUBLISH_VERSION = "core/oc-deploy"
|
||||
|
||||
var PUBLISH_URL = getenv("PUBLISH_URL", "https://cloud.o-forge.io")
|
||||
var PUBLISH_REPO = getenv("PUBLISH_REPO", "core/oc-deploy")
|
||||
var PUBLISH_TOKEN = getenv("PUBLISH_TOKEN", "")
|
||||
var PUBLISH_BRANCH = getenv("PUBLISH_BRANCH", "main")
|
||||
|
||||
func getenv(key string, defaut string) string {
|
||||
value := os.Getenv(key)
|
||||
if len(value) == 0 {
|
||||
return defaut
|
||||
}
|
||||
return value
|
||||
}
|
||||
var PUBLISH_TOKEN = ""
|
||||
|
@ -1,6 +0,0 @@
|
||||
Version %s d'OpenCloud
|
||||
|
||||
```
|
||||
wget %s/%s/releases/download/%s/oc-deploy.base64 -O - | base64 -d > oc-deploy
|
||||
chmod u+x ./oc-deploy
|
||||
```
|
@ -6,7 +6,6 @@ import (
|
||||
"path/filepath"
|
||||
"mime/multipart"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"bytes"
|
||||
@ -22,7 +21,7 @@ type assetStruct struct {
|
||||
func GetAssetId(idRelease int, name string) (int, error) {
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets",
|
||||
occonst.PUBLISH_URL,
|
||||
occonst.PUBLISH_REPO,
|
||||
occonst.PUBLISH_VERSION,
|
||||
idRelease)
|
||||
|
||||
res, err := http.Get(url)
|
||||
@ -37,6 +36,7 @@ func GetAssetId(idRelease int, name string) (int, error) {
|
||||
var data []assetStruct
|
||||
|
||||
err = json.Unmarshal(body, &data)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
return -3, err
|
||||
}
|
||||
@ -54,52 +54,48 @@ func GetAssetId(idRelease int, name string) (int, error) {
|
||||
// -H 'accept: application/json' \
|
||||
// -H 'Content-Type: multipart/form-data' \
|
||||
// -F 'attachment=oc-deploy'
|
||||
func CreateAsset(idRelease int, filename string, name string) (error) {
|
||||
func CreateAsset(idRelease int, filename string) (int, error) {
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s",
|
||||
occonst.PUBLISH_URL,
|
||||
occonst.PUBLISH_REPO,
|
||||
occonst.PUBLISH_VERSION,
|
||||
idRelease,
|
||||
name,
|
||||
"name",
|
||||
occonst.PUBLISH_TOKEN)
|
||||
|
||||
// request, err := newfileUploadRequest(url, extraParams, "file", "/tmp/doc.pdf")
|
||||
|
||||
err := uploadFile(url, "attachment", filename)
|
||||
fmt.Println(url, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateAsset(idRelease int, idAsset int, filename string, name string) (error) {
|
||||
// fmt.Println(url)
|
||||
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets/%d?token=%s",
|
||||
occonst.PUBLISH_URL,
|
||||
occonst.PUBLISH_REPO,
|
||||
idRelease,
|
||||
idAsset,
|
||||
occonst.PUBLISH_TOKEN)
|
||||
// body := []byte("CONTENU")
|
||||
// req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
|
||||
// if err != nil {
|
||||
// return -1, err
|
||||
// }
|
||||
// req.Header.Add("accept", "application/json")
|
||||
// req.Header.Add("Content-Type", "multipart/form-data")
|
||||
|
||||
// Create client
|
||||
client := &http.Client{}
|
||||
// client := &http.Client{}
|
||||
// res, err := client.Do(req)
|
||||
// fmt.Println(res, err)
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("DELETE", url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// cnt, err := io.ReadAll(res.Body)
|
||||
// fmt.Println(string(cnt), err)
|
||||
|
||||
// Fetch Request
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
// if err != nil {
|
||||
// return -1, err
|
||||
// }
|
||||
|
||||
// Read Response Body
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(respBody))
|
||||
// if err != nil {
|
||||
// return -2, err
|
||||
// }
|
||||
|
||||
return CreateAsset(idRelease, filename, name)
|
||||
// defer res.Body.Close()
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func uploadFile(url string, paramName string, filePath string) error {
|
||||
@ -108,7 +104,7 @@ func uploadFile(url string, paramName string, filePath string) error {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
part, err := writer.CreateFormFile(paramName, filepath.Base(filePath))
|
||||
@ -127,19 +123,44 @@ func uploadFile(url string, paramName string, filePath string) error {
|
||||
request.Header.Add("accept", "application/json")
|
||||
client := &http.Client{}
|
||||
response, err := client.Do(request)
|
||||
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(109, err)
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode > 400 {
|
||||
return fmt.Errorf(response.Status)
|
||||
}
|
||||
|
||||
_, err1 := io.ReadAll(response.Body)
|
||||
cnt, err := io.ReadAll(response.Body)
|
||||
fmt.Println(string(cnt), err, writer.FormDataContentType())
|
||||
|
||||
// Handle the server response...
|
||||
return err1
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
|
||||
// file, err := os.Open(path)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// body := &bytes.Buffer{}
|
||||
// writer := multipart.NewWriter(body)
|
||||
// part, err := writer.CreateFormFile(paramName, filepath.Base(path))
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// _, err = io.Copy(part, file)
|
||||
|
||||
// // for key, val := range params {
|
||||
// // _ = writer.WriteField(key, val)
|
||||
// // }
|
||||
// // err = writer.Close()
|
||||
// // if err != nil {
|
||||
// // return nil, err
|
||||
// // }
|
||||
|
||||
// req, err := http.NewRequest("POST", uri, body)
|
||||
// req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||
// return req, err
|
||||
// }
|
@ -3,8 +3,6 @@ package releases
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
@ -17,9 +15,10 @@ type checkStruct struct {
|
||||
}
|
||||
|
||||
func CheckRelease(version string) (bool, error) {
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases",
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
|
||||
occonst.PUBLISH_URL,
|
||||
occonst.PUBLISH_REPO)
|
||||
occonst.PUBLISH_VERSION,
|
||||
version)
|
||||
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
@ -30,25 +29,19 @@ func CheckRelease(version string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var data []checkStruct
|
||||
var data checkStruct
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, ele := range data {
|
||||
if ele.Name == version {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
// return data.Name != "", nil
|
||||
return false, nil
|
||||
return data.Name != "", nil
|
||||
}
|
||||
|
||||
func GetReleaseId(version string) (int, error) {
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
|
||||
occonst.PUBLISH_URL,
|
||||
occonst.PUBLISH_REPO,
|
||||
occonst.PUBLISH_VERSION,
|
||||
version)
|
||||
|
||||
res, err := http.Get(url)
|
||||
@ -67,60 +60,4 @@ func GetReleaseId(version string) (int, error) {
|
||||
}
|
||||
|
||||
return data.Id, nil
|
||||
}
|
||||
|
||||
// curl -X 'POST' \
|
||||
// 'https://cloud.o-forge.io/api/v1/repos/na/oc-version/releases?token=sss' \
|
||||
// -H 'accept: application/json' \
|
||||
// -H 'Content-Type: application/json' \
|
||||
// -d '{
|
||||
// "body": "string",
|
||||
// "draft": true,
|
||||
// "name": "string",
|
||||
// "prerelease": true,
|
||||
// "tag_name": "string",
|
||||
// "target_commitish": "string"
|
||||
// }'
|
||||
func CreateRelease(version string, branch string) (error) {
|
||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases?token=%s",
|
||||
occonst.PUBLISH_URL,
|
||||
occonst.PUBLISH_REPO,
|
||||
occonst.PUBLISH_TOKEN)
|
||||
|
||||
releasebytes, err := ioutil.ReadFile("release.txt")
|
||||
releasetxt := string(releasebytes)
|
||||
releasetxt = strings.Replace(releasetxt, "\n", "\\n", -1)
|
||||
releasetxt = fmt.Sprintf(releasetxt, version, occonst.PUBLISH_URL, occonst.PUBLISH_REPO, version)
|
||||
|
||||
body := fmt.Sprintf(`{
|
||||
"body": "%s",
|
||||
"draft": false,
|
||||
"name": "%s",
|
||||
"prerelease": false,
|
||||
"tag_name": "%s",
|
||||
"target_commitish": "%s"
|
||||
}`, releasetxt, version, version, branch)
|
||||
|
||||
request, err := http.NewRequest("POST", url, strings.NewReader(body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.Header.Add("accept", "application/json")
|
||||
request.Header.Add("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
_, err1 := io.ReadAll(response.Body)
|
||||
// cnt, err1 := io.ReadAll(response.Body)
|
||||
// fmt.Println(string(cnt))
|
||||
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
@ -2,6 +2,33 @@
|
||||
|
||||
**oc-deploy** is a tool to deploy (with **helm**) all component of **OpenCloud**.
|
||||
|
||||
# Usage
|
||||
|
||||
| Command | Description |
|
||||
| ----------------------------------------------------------------------------- | --------------------------- |
|
||||
| ```oc-deploy``` | Display help |
|
||||
| ```oc-deploy version``` | Display the version of tool |
|
||||
| ```oc-deploy install [-c\|--context <context>] [-v\|--version <OcVersion>]``` | Deploy an OpenCloud |
|
||||
| ```oc-deploy uninstall [-c\|--context <context>]``` | Undeploy an OpenCloud |
|
||||
|
||||
| Arguments | Description | Default |
|
||||
| ---------------- | --------------------------- | ------------ |
|
||||
| ```context``` | Context Kubernetes | _opencloud_ |
|
||||
| ```OcVersion``` | Specific version or latest | _latest_ |
|
||||
|
||||
# Principe
|
||||
|
||||
# Pre-requis
|
||||
|
||||
**oc-deploy** need to access to an Kubernetes Cluster, c'est-à-dire : kubeconfig.
|
||||
|
||||
**oc-deploy** need to access to Internet :
|
||||
|
||||
* to download the _oc.json_ file (contient _oc.yml_) :
|
||||
* Url : https://cloud.o-forge.io/core/oc-deploy/releases
|
||||
* to download _kubectl_ and _helm_ tools if
|
||||
* Url : Urls are specified into _oc.yml_
|
||||
|
||||
# Development
|
||||
|
||||
To init:
|
||||
|
Loading…
Reference in New Issue
Block a user