Fixed small typo, replaced DB connection details in Makefile by .env loading
parent
b04e854fdd
commit
59707b8abd
11
Makefile
11
Makefile
|
@ -5,11 +5,6 @@ COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
||||||
BUILD_DIR = bin
|
BUILD_DIR = bin
|
||||||
|
|
||||||
DBHOST = 127.0.0.1:3306
|
|
||||||
DBNAME = docker
|
|
||||||
DBUSER = root
|
|
||||||
DBPASS = tiger
|
|
||||||
|
|
||||||
build-all:
|
build-all:
|
||||||
GOOS=linux GOARCH=amd64 make build
|
GOOS=linux GOARCH=amd64 make build
|
||||||
GOOS=linux GOARCH=arm make build
|
GOOS=linux GOARCH=arm make build
|
||||||
|
@ -19,11 +14,7 @@ build:
|
||||||
GOOS=${GOOS} GOARCH=${GOARCH} go build \
|
GOOS=${GOOS} GOARCH=${GOARCH} go build \
|
||||||
-trimpath -ldflags "-s -w -X ${PROJECT}/internal/diagnostics.Version=${RELEASE} \
|
-trimpath -ldflags "-s -w -X ${PROJECT}/internal/diagnostics.Version=${RELEASE} \
|
||||||
-X ${PROJECT}/internal/diagnostics.Commit=${COMMIT} \
|
-X ${PROJECT}/internal/diagnostics.Commit=${COMMIT} \
|
||||||
-X ${PROJECT}/internal/diagnostics.BuildDate=${BUILD_DATE} \
|
-X ${PROJECT}/internal/diagnostics.BuildDate=${BUILD_DATE}" \
|
||||||
-X ${PROJECT}/internal/tasks.Dbhost=${DBHOST} \
|
|
||||||
-X ${PROJECT}/internal/tasks.Dbname=${DBNAME} \
|
|
||||||
-X ${PROJECT}/internal/tasks.Dbuser=${DBUSER} \
|
|
||||||
-X ${PROJECT}/internal/tasks.Dbpass=${DBPASS}" \
|
|
||||||
-o bin/sysctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/sysctl
|
-o bin/sysctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/sysctl
|
||||||
cp ./bin/sysctl-${GOOS}-${GOARCH} ./bin/sysctl
|
cp ./bin/sysctl-${GOOS}-${GOARCH} ./bin/sysctl
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/edgebox-iot/sysctl/internal/diagnostics"
|
"github.com/edgebox-iot/sysctl/internal/diagnostics"
|
||||||
"github.com/edgebox-iot/sysctl/internal/tasks"
|
"github.com/edgebox-iot/sysctl/internal/tasks"
|
||||||
|
"github.com/edgebox-iot/sysctl/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultNotReadySleepTime time.Duration = time.Second * 60
|
const defaultNotReadySleepTime time.Duration = time.Second * 60
|
||||||
|
@ -85,8 +86,8 @@ func printVersion() {
|
||||||
|
|
||||||
func printDbDetails() {
|
func printDbDetails() {
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"\n\nDatabase Connection Information:\nHost: %s\nuser: %s\npassword: %s\n\n",
|
"\n\nDatabase Connection Information:\n %s\n\n",
|
||||||
tasks.Dbhost, tasks.Dbuser, tasks.Dbpass,
|
utils.GetMySQLDbConnectionDetails(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -4,5 +4,6 @@ go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
|
github.com/joho/godotenv v1.3.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,8 +31,12 @@ type EdgeAppService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const configFilename = "/edgebox-compose.yml"
|
const configFilename = "/edgebox-compose.yml"
|
||||||
const edgeAppsPath = "/home/system/components/apps/"
|
|
||||||
const wsPath = "/home/system/components/ws/"
|
// const edgeAppsPath = "/home/system/components/apps/"
|
||||||
|
const edgeAppsPath = "/home/jpt/Repositories/edgebox/apps/"
|
||||||
|
|
||||||
|
// const wsPath = "/home/system/components/ws/"
|
||||||
|
const wsPath = "/home/jpt/Repositories/edgebox/ws"
|
||||||
|
|
||||||
// GetEdgeApps : Returns a list of EdgeApp struct filled with information
|
// GetEdgeApps : Returns a list of EdgeApp struct filled with information
|
||||||
func GetEdgeApps() []EdgeApp {
|
func GetEdgeApps() []EdgeApp {
|
||||||
|
@ -53,7 +57,8 @@ func GetEdgeApps() []EdgeApp {
|
||||||
_, err := os.Stat(edgeAppsPath + f.Name() + configFilename)
|
_, err := os.Stat(edgeAppsPath + f.Name() + configFilename)
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
// File exists. Start digging!
|
// File exists. Start digging!
|
||||||
edgeApp := EdgeApp{ID: f.Name(), Status: GetEdgeAppStatus(f.Name()), Services: GetEdgeAppServices(f.Name()), NetworkURL: f.Name() + ".edgebox.local"}
|
edgeAppName := "Nextcloud"
|
||||||
|
edgeApp := EdgeApp{ID: f.Name(), Name: edgeAppName, Status: GetEdgeAppStatus(f.Name()), Services: GetEdgeAppServices(f.Name()), NetworkURL: f.Name() + ".edgebox.local"}
|
||||||
edgeApps = append(edgeApps, edgeApp)
|
edgeApps = append(edgeApps, edgeApp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,18 +13,6 @@ import (
|
||||||
_ "github.com/go-sql-driver/mysql" // Mysql Driver
|
_ "github.com/go-sql-driver/mysql" // Mysql Driver
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dbhost : Database host (can be tweaked in makefile)
|
|
||||||
var Dbhost string
|
|
||||||
|
|
||||||
// Dbname : Database name (can be tweaked in makefile)
|
|
||||||
var Dbname string
|
|
||||||
|
|
||||||
// Dbuser : Database user (can be tweaked in makefile)
|
|
||||||
var Dbuser string
|
|
||||||
|
|
||||||
// Dbpass : Database password (can be tweaked in)
|
|
||||||
var Dbpass string
|
|
||||||
|
|
||||||
// Task : Struct for Task type
|
// Task : Struct for Task type
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
|
@ -47,7 +35,7 @@ type taskSetupTunnelArgs struct {
|
||||||
func GetNextTask() Task {
|
func GetNextTask() Task {
|
||||||
|
|
||||||
// Will try to connect to API database, which should be running locally under WS.
|
// Will try to connect to API database, which should be running locally under WS.
|
||||||
db, err := sql.Open("mysql", Dbuser+":"+Dbpass+"@tcp("+Dbhost+")/"+Dbname)
|
db, err := sql.Open("mysql", utils.GetMySQLDbConnectionDetails())
|
||||||
|
|
||||||
// if there is an error opening the connection, handle it
|
// if there is an error opening the connection, handle it
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,7 +74,7 @@ func GetNextTask() Task {
|
||||||
// ExecuteTask : Performs execution of the given task, updating the task status as it goes, and publishing the task result
|
// ExecuteTask : Performs execution of the given task, updating the task status as it goes, and publishing the task result
|
||||||
func ExecuteTask(task Task) Task {
|
func ExecuteTask(task Task) Task {
|
||||||
|
|
||||||
db, err := sql.Open("mysql", Dbuser+":"+Dbpass+"@tcp("+Dbhost+")/"+Dbname)
|
db, err := sql.Open("mysql", utils.GetMySQLDbConnectionDetails())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
|
@ -193,7 +181,27 @@ func taskGetEdgeApps() string {
|
||||||
|
|
||||||
fmt.Println("Executing taskGetEdgeApps")
|
fmt.Println("Executing taskGetEdgeApps")
|
||||||
|
|
||||||
log.Println(edgeapps.GetEdgeApps())
|
edgeApps := edgeapps.GetEdgeApps()
|
||||||
|
edgeAppsJSON, _ := json.Marshal(edgeApps)
|
||||||
|
log.Println(string(edgeAppsJSON))
|
||||||
|
|
||||||
|
// db, err := sql.Open("mysql", utils.GetMySQLDbConnectionDetails())
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// panic(err.Error())
|
||||||
|
// }
|
||||||
|
|
||||||
|
// defer db.Close()
|
||||||
|
|
||||||
|
// statusUpdate, err := db.Query("UPDATE options SET value = '" + + "' WHERE name = 'EDGEAPPS_LIST'")
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// panic(err.Error())
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for statusUpdate.Next() {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
// Saving information in the "options" table.
|
// Saving information in the "options" table.
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
|
// Exec : Runs a terminal Command, catches and logs errors, returns the result.
|
||||||
|
@ -35,3 +37,25 @@ func DeleteEmptySlices(s []string) []string {
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMySQLDbConnectionDetails : Returns the necessary string as connection info for SQL.db()
|
||||||
|
func GetMySQLDbConnectionDetails() string {
|
||||||
|
|
||||||
|
// const apiEnvFileLocation = "/home/system/components/api/edgebox.env"
|
||||||
|
const apiEnvFileLocation = "/home/jpt/Repositories/edgebox/api/edgebox.env"
|
||||||
|
|
||||||
|
var apiEnv map[string]string
|
||||||
|
apiEnv, err := godotenv.Read(apiEnvFileLocation)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error loading .env file")
|
||||||
|
}
|
||||||
|
|
||||||
|
Dbhost := "127.0.0.1:" + apiEnv["HOST_MACHINE_MYSQL_PORT"]
|
||||||
|
Dbname := apiEnv["MYSQL_DATABASE"]
|
||||||
|
Dbuser := apiEnv["MYSQL_USER"]
|
||||||
|
Dbpass := apiEnv["MYSQL_PASSWORD"]
|
||||||
|
|
||||||
|
return Dbuser + ":" + Dbpass + "@tcp(" + Dbhost + ")/" + Dbname
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue