Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new vars to builder.yaml and metadata #74

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ Please note that all keys must be lowercase
- `auto`: specify whether to automatically push build metadata and logs on build completion. Eliminates need of running `builder push` command
- `appicon`: specify url to app icon image
- ("http://domain.co/path/to/app_icon.png")
- `containerport`: specify container port
- (8080, 1234)
- `serviceport`: specify service port
- (1234, 2233)
- `application_dependencies`: specify list of application dependencies
- (Specify as yaml array)
- `application_envs`: specify list of environment variable key value pairs
- (specify as yaml array of objects with `key` for key and `value` for value)

## Builder ENV Vars

Expand Down
8 changes: 8 additions & 0 deletions utils/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func Help() {
- auto: (true/false) whether to automate pushing process for future builds
* appicon: specify url to app icon image
- ("http://domain.co/path/to/app_icon.png")
* containerport: specify container port
- (8080, 3000, etc)
* serviceport: specify service port
- (1233, 4433, etc)
* application_dependencies: specify list of application dependencies
- (specify as yaml array)
* application_envs: specify list of environment variable key value pairs
- (specify as yaml array of objects with 'key' for key and 'value' for value)
`)
os.Exit(0)
}
Expand Down
117 changes: 78 additions & 39 deletions utils/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"fmt"
"runtime"
"strconv"
"sync"

"encoding/json"
Expand All @@ -20,6 +21,40 @@ import (
"gopkg.in/yaml.v2"
)

type Artifacts struct {
name string
checksum string
}

// EnvData holds the struct of envs argument
type EnvData struct {
Key string
Value string
}

// AllMetaData holds the stuct of all the arguments
type AllMetaData struct {
ProjectName string
ProjectType string
ArtifactName string
ArtifactChecksums string
ArtifactLocation string
LogsLocation string
UserName string
HomeDir string
IP string
StartTime string
EndTime string
GitURL string
MasterGitHash string
BranchName string
AppIcon string
ContainerPort int
ServicePort int
ApplicationDependencies []string
ApplicationEnvs []EnvData
}

func Metadata(path string) {
//Metedata
projectName := GetName()
Expand Down Expand Up @@ -102,48 +137,57 @@ func Metadata(path string) {

appIcon := os.Getenv("BUILD_APP_ICON")

containerPort, _ := strconv.Atoi(os.Getenv("APP_CONTAINER_PORT"))
servicePort, _ := strconv.Atoi(os.Getenv("APP_SERVICE_PORT"))

var appDependencies []string
if os.Getenv("APP_DEPENDENCIES") == "" {
appDependencies = nil
} else {
appDependencies = strings.Split(os.Getenv("APP_DEPENDENCIES"), ",")
}

var appEnvs []EnvData
var pairData EnvData
if os.Getenv("APP_ENVS") != "" {
envPairs := strings.Split(os.Getenv("APP_ENVS"), ";")
for _, pair := range envPairs {
pairArray := strings.Split(pair, ",")
pairData.Key = pairArray[0]
pairData.Value = pairArray[1]
appEnvs = append(appEnvs, pairData)
}
} else {
appEnvs = nil
}

//Contains a collection of files with user's metadata
userMetaData := AllMetaData{
ProjectName: projectName,
ProjectType: projectType,
ArtifactName: artifactName,
ArtifactChecksums: artifactChecksums,
ArtifactLocation: artifactLocation,
LogsLocation: logsLocation,
UserName: userName,
HomeDir: homeDir,
IP: ip,
StartTime: startTime,
EndTime: endTime,
GitURL: gitURL,
MasterGitHash: masterGitHash,
BranchName: branchName,
AppIcon: appIcon,
ProjectName: projectName,
ProjectType: projectType,
ArtifactName: artifactName,
ArtifactChecksums: artifactChecksums,
ArtifactLocation: artifactLocation,
LogsLocation: logsLocation,
UserName: userName,
HomeDir: homeDir,
IP: ip,
StartTime: startTime,
EndTime: endTime,
GitURL: gitURL,
MasterGitHash: masterGitHash,
BranchName: branchName,
AppIcon: appIcon,
ContainerPort: containerPort,
ServicePort: servicePort,
ApplicationDependencies: appDependencies,
ApplicationEnvs: appEnvs,
}

OutputMetadata(path, &userMetaData)

}

// AllMetaData holds the stuct of all the arguments
type AllMetaData struct {
ProjectName string
ProjectType string
ArtifactName string
ArtifactChecksums string
ArtifactLocation string
LogsLocation string
UserName string
HomeDir string
IP string
StartTime string
EndTime string
GitURL string
MasterGitHash string
BranchName string
AppIcon string
}

// GetUserData return username and userdir
func GetUserData() *user.User {
user, err := user.Current()
Expand Down Expand Up @@ -224,11 +268,6 @@ func GitMasterNameAndHash() (string, string) {
return masterBranchName, masterBranchHash
}

type Artifacts struct {
name string
checksum string
}

func GetArtifactChecksum() string {
artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR")

Expand Down
154 changes: 109 additions & 45 deletions yaml/createBuilderYaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ package yaml
import (
"Builder/spinner"
"os"
"strconv"
"strings"

"gopkg.in/yaml.v2"
)

type BuilderYaml struct {
ProjectName string
ProjectPath string
ProjectType string
BuildsDir string
BuildTool string
BuildFile string
PreBuildCmd string
ConfigCmd string
BuildCmd string
ArtifactList string
OutputPath string
RepoBranch string
Docker map[string]interface{}
Push map[string]interface{}
AppIcon string
ProjectName string
ProjectPath string
ProjectType string
BuildsDir string
BuildTool string
BuildFile string
PreBuildCmd string
ConfigCmd string
BuildCmd string
ArtifactList string
OutputPath string
RepoBranch string
Docker map[string]interface{}
Push map[string]interface{}
AppIcon string
ContainerPort int
ServicePort int
Application_Dependencies []string
Application_Envs []EnvData
}

func CreateBuilderYaml(fullPath string) {
Expand Down Expand Up @@ -89,22 +95,51 @@ func CreateBuilderYaml(fullPath string) {
}
appIcon := os.Getenv("BUILD_APP_ICON")

containerPort, _ := strconv.Atoi(os.Getenv("APP_CONTAINER_PORT"))
servicePort, _ := strconv.Atoi(os.Getenv("APP_SERVICE_PORT"))

var appDependencies []string
if os.Getenv("APP_DEPENDENCIES") == "" {
appDependencies = nil
} else {
appDependencies = strings.Split(os.Getenv("APP_DEPENDENCIES"), ",")
}

var appEnvs []EnvData
if os.Getenv("APP_ENVS") != "" {
envPairs := strings.Split(os.Getenv("APP_ENVS"), ";")
for _, pair := range envPairs {
pairArray := strings.Split(pair, ",")
pairData := EnvData{
Key: pairArray[0],
Value: pairArray[1],
}
appEnvs = append(appEnvs, pairData)
}
} else {
appEnvs = nil
}

builderData := BuilderYaml{
ProjectName: projectName,
ProjectPath: projectPath,
ProjectType: projectType,
BuildsDir: buildsDir,
BuildTool: buildTool,
BuildFile: buildFile,
PreBuildCmd: preBuildCmd,
ConfigCmd: configCmd,
BuildCmd: buildCmd,
ArtifactList: artifactList,
OutputPath: outputPath,
RepoBranch: repoBranch,
Docker: docker,
Push: push,
AppIcon: appIcon,
ProjectName: projectName,
ProjectPath: projectPath,
ProjectType: projectType,
BuildsDir: buildsDir,
BuildTool: buildTool,
BuildFile: buildFile,
PreBuildCmd: preBuildCmd,
ConfigCmd: configCmd,
BuildCmd: buildCmd,
ArtifactList: artifactList,
OutputPath: outputPath,
RepoBranch: repoBranch,
Docker: docker,
Push: push,
AppIcon: appIcon,
ContainerPort: containerPort,
ServicePort: servicePort,
Application_Dependencies: appDependencies,
Application_Envs: appEnvs,
}

OutputData(fullPath, &builderData)
Expand Down Expand Up @@ -144,22 +179,51 @@ func UpdateBuilderYaml(fullPath string) {
}
appIcon := os.Getenv("BUILD_APP_ICON")

containerPort, _ := strconv.Atoi(os.Getenv("APP_CONTAINER_PORT"))
servicePort, _ := strconv.Atoi(os.Getenv("APP_SERVICE_PORT"))

var appDependencies []string
if os.Getenv("APP_DEPENDENCIES") == "" {
appDependencies = nil
} else {
appDependencies = strings.Split(os.Getenv("APP_DEPENDENCIES"), ",")
}

var appEnvs []EnvData
if os.Getenv("APP_ENVS") != "" {
envPairs := strings.Split(os.Getenv("APP_ENVS"), ";")
for _, pair := range envPairs {
pairArray := strings.Split(pair, ",")
pairData := EnvData{
Key: pairArray[0],
Value: pairArray[1],
}
appEnvs = append(appEnvs, pairData)
}
} else {
appEnvs = nil
}

builderData := BuilderYaml{
ProjectName: projectName,
ProjectPath: projectPath,
ProjectType: projectType,
BuildsDir: buildsDir,
BuildTool: buildTool,
BuildFile: buildFile,
PreBuildCmd: preBuildCmd,
ConfigCmd: configCmd,
BuildCmd: buildCmd,
ArtifactList: artifactList,
OutputPath: outputPath,
RepoBranch: repoBranch,
Docker: docker,
Push: push,
AppIcon: appIcon,
ProjectName: projectName,
ProjectPath: projectPath,
ProjectType: projectType,
BuildsDir: buildsDir,
BuildTool: buildTool,
BuildFile: buildFile,
PreBuildCmd: preBuildCmd,
ConfigCmd: configCmd,
BuildCmd: buildCmd,
ArtifactList: artifactList,
OutputPath: outputPath,
RepoBranch: repoBranch,
Docker: docker,
Push: push,
AppIcon: appIcon,
ContainerPort: containerPort,
ServicePort: servicePort,
Application_Dependencies: appDependencies,
Application_Envs: appEnvs,
}

_, err := os.Stat(fullPath + "/builder.yaml")
Expand Down
Loading