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

Feat(arango): add arango api and bff to archi #135

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d6956c9
feat(arango): add arango api to Core
vbeaucha Aug 3, 2023
adc8c33
feat(arango): add arango api to docker compose
vbeaucha Aug 3, 2023
c7e7f47
fix(port): arango_api_port has a variable
vbeaucha Aug 4, 2023
c0c506a
fix(package): rename go-api to arango-api
vbeaucha Aug 4, 2023
743ee44
feat(Auth): add Authorization Bearer to arango api
vbeaucha Aug 4, 2023
9cfa436
fix(health): add healthcheck on /api/v1/health
vbeaucha Aug 4, 2023
fb7c017
feat(device): get device connected to another
vbeaucha Aug 4, 2023
4426b95
fix(router): rename route getDevicesConnecteTo
vbeaucha Aug 7, 2023
1039333
feat(bff): init bff
vbeaucha Aug 7, 2023
8ef5fdc
feat(bff): add route Organization and Objects
vbeaucha Aug 8, 2023
980c6f9
feat(bff): add flutterApp and about route to bff
vbeaucha Aug 8, 2023
2dc98d3
feat(bff): add bff to docker-compose
vbeaucha Aug 8, 2023
d1777df
fix(swagger): remove ussless swagger.yaml
vbeaucha Aug 8, 2023
4f32bf1
fix(bff): fix arango url in docker-compose
vbeaucha Aug 8, 2023
b3c1966
fix(bff): many fix in bff
vbeaucha Aug 8, 2023
b720dc5
fix(bff): return text message if response body is not json
vbeaucha Aug 9, 2023
bf2bf3d
feat(bff): modify commandline get into CLI to use arango
vbeaucha Aug 9, 2023
d348645
fix(cli): add error message if device not found
vbeaucha Aug 9, 2023
f9fb016
feat(cli): binding info from object and devices
vbeaucha Aug 9, 2023
a6aaded
fix(bff): rename database and changing route for binding
vbeaucha Aug 9, 2023
cc9493a
feat(bff): update devices routes
vbeaucha Aug 10, 2023
ac831f6
readme(ARANGO): add readme for arango api
vbeaucha Aug 10, 2023
911be5a
fix(bff): api info for bff has json file
vbeaucha Aug 10, 2023
aebc1a4
fix(bff): stop exposing api into docker compose
vbeaucha Aug 10, 2023
02732a8
fix(doc): add BFF readme.md
vbeaucha Aug 10, 2023
27598e1
fix(cli): correct function that never return error
vbeaucha Aug 10, 2023
f910a93
fix(doc): add info for config file of bff
vbeaucha Aug 10, 2023
6b19902
fix(bff): remove useless code
vbeaucha Aug 11, 2023
d4f392c
Add arango profile, expose API
helderbetiol Aug 11, 2023
e21e3ed
fix(bff): change routes /api/devices by /api/deviceComp/ to avoid con…
vbeaucha Aug 11, 2023
2bc9b7c
fix(bff): add allowAllCrossOrigin
vbeaucha Aug 11, 2023
a10c04d
fix(bff): add options to cors
vbeaucha Aug 11, 2023
1554356
Add Arango+BFF to SuperAdmin APP
helderbetiol Aug 11, 2023
ef5c2be
Fix superadmin deploy without Arango
helderbetiol Aug 11, 2023
c7a713b
fix(deploy): change dockerfile to match other
vbeaucha Aug 17, 2023
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
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ unitylog.txt

# APP Ignore
deploy/docker/*.env
deploy/docker/app-deploy
deploy/docker/app-deploy

#ARANGO_API Ignore
ARANGO_API/arango-api
ARANGO_API/*env

#BFF Ignore
BFF/*env
BFF/ogree-bff

27 changes: 16 additions & 11 deletions APP/ogree_app/lib/models/tenant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Tenant {
String docUrl;
String docPort;
String imageTag;
bool hasBff;
TenantStatus? status;

Tenant(
Expand All @@ -29,6 +30,7 @@ class Tenant {
this.docUrl,
this.docPort,
this.imageTag,
this.hasBff,
{this.status});

Map<String, dynamic> toMap() {
Expand All @@ -44,22 +46,25 @@ class Tenant {
'docUrl': docUrl,
'docPort': docPort,
'imageTag': imageTag,
'hasBff': hasBff,
};
}

factory Tenant.fromMap(Map<String, dynamic> map) {
return Tenant(
map['name'].toString(),
map['customerPassword'].toString(),
map['apiUrl'].toString(),
map['webUrl'].toString(),
map['apiPort'].toString(),
map['webPort'].toString(),
map['hasWeb'],
map['hasDoc'],
map['docUrl'].toString(),
map['docPort'].toString(),
map['imageTag'].toString());
map['name'].toString(),
map['customerPassword'].toString(),
map['apiUrl'].toString(),
map['webUrl'].toString(),
map['apiPort'].toString(),
map['webPort'].toString(),
map['hasWeb'],
map['hasDoc'],
map['docUrl'].toString(),
map['docPort'].toString(),
map['imageTag'].toString(),
map['hasBff'],
);
}

String toJson() => json.encode(toMap());
Expand Down
16 changes: 12 additions & 4 deletions APP/ogree_app/lib/widgets/tenants/popups/create_tenant_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _CreateTenantPopupState extends State<CreateTenantPopup> {
String _docPort = "";
bool _hasWeb = true;
bool _hasDoc = false;
bool _hasBff = false;
bool _isLoading = false;
PlatformFile? _loadedImage;
String _imageTag = "main";
Expand Down Expand Up @@ -78,8 +79,8 @@ class _CreateTenantPopupState extends State<CreateTenantPopup> {
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
getCheckBox("API", true, (_) {},
enabled: false),
// getCheckBox("API", true, (_) {},
// enabled: false),
getCheckBox(
"WEB",
_hasWeb,
Expand All @@ -92,6 +93,12 @@ class _CreateTenantPopupState extends State<CreateTenantPopup> {
(value) => setState(() {
_hasDoc = value!;
})),
getCheckBox(
"Arango",
_hasBff,
(value) => setState(() {
_hasBff = value!;
})),
],
),
const SizedBox(height: 10),
Expand Down Expand Up @@ -259,7 +266,8 @@ class _CreateTenantPopupState extends State<CreateTenantPopup> {
_hasDoc,
_docUrl,
_docPort,
_imageTag));
_imageTag,
_hasBff));
switch (result) {
case Success(value: final value):
widget.parentCallback();
Expand All @@ -278,7 +286,7 @@ class _CreateTenantPopupState extends State<CreateTenantPopup> {
getCheckBox(String title, bool value, Function(bool?) onChange,
{bool enabled = true}) {
return SizedBox(
width: 95,
width: 110,
child: CheckboxListTile(
activeColor: Colors.blue.shade600,
contentPadding: EdgeInsets.zero,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _UpdateTenantPopupState extends State<UpdateTenantPopup> {
alignment: WrapAlignment.start,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
getCheckBox("API", true, (_) {}, enabled: false),
// getCheckBox("API", true, (_) {}, enabled: false),
getCheckBox(
"WEB",
widget.tenant.hasWeb,
Expand All @@ -67,6 +67,8 @@ class _UpdateTenantPopupState extends State<UpdateTenantPopup> {
(value) => setState(() {
widget.tenant.hasDoc = value!;
})),
getCheckBox("Arango", widget.tenant.hasBff, (_) {},
enabled: false),
],
),
getFormField(
Expand Down Expand Up @@ -182,7 +184,7 @@ class _UpdateTenantPopupState extends State<UpdateTenantPopup> {
getCheckBox(String title, bool value, Function(bool?) onChange,
{bool enabled = true}) {
return SizedBox(
width: 95,
width: 105,
child: CheckboxListTile(
activeColor: Colors.blue.shade600,
contentPadding: EdgeInsets.zero,
Expand Down
2 changes: 2 additions & 0 deletions APP/ogree_app_backend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

var tmplt *template.Template
var bfftmplt *template.Template
var apptmplt *template.Template
var servertmplt *template.Template
var netboxtmplt *template.Template
Expand All @@ -35,6 +36,7 @@ func init() {
// []byte("password"), bcrypt.DefaultCost)
// println(string(hashedPassword))
tmplt = template.Must(template.ParseFiles("backend-assets/docker-env-template.txt"))
bfftmplt = template.Must(template.ParseFiles("backend-assets/bff-api-list-template.txt"))
apptmplt = template.Must(template.ParseFiles("flutter-assets/flutter-env-template.txt"))
servertmplt = template.Must(template.ParseFiles("backend-assets/template.service"))
netboxtmplt = template.Must(template.ParseFiles("tools-assets/netbox-docker-template.txt"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{"name":"server", "url": "http://{{.Name}}_arango_api:8080"},
{"name":"objects", "url": "http://{{.Name}}_api:{{.ApiPort}}"}
]
12 changes: 12 additions & 0 deletions APP/ogree_app_backend/backend-assets/docker-env-template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ API_EXTERNALURL={{.ApiUrl}}
COMPOSE_PROJECT_NAME={{.Name}}
APP_ASSETS_DIR={{.AssetsDir}}
IMAGE_TAG={{.ImageTag}}

ARANGO_API_BUILD_DIR=ARANGO_API
ARANGO_API_PORT=8080
ARANGO_PASS=ogree
ARANGO_USER=root
ARANGO_DB=_system

BFF_BUILD_DIR=BFF
BFF_PORT={{.BffPort}}
BFF_API_LIST={{.BffApiListFile}}

AUTH_SECRET=myAwesomeApiSecret
46 changes: 40 additions & 6 deletions APP/ogree_app_backend/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"time"

Expand All @@ -27,10 +28,13 @@ type tenant struct {
WebPort string `json:"webPort"`
DocUrl string `json:"docUrl"`
DocPort string `json:"docPort"`
BffPort string `json:"bffPort"`
HasWeb bool `json:"hasWeb"`
HasDoc bool `json:"hasDoc"`
HasBff bool `json:"hasBff"`
AssetsDir string `json:"assetsDir"`
ImageTag string `json:"imageTag"`
BffApiListFile string
}

type container struct {
Expand Down Expand Up @@ -182,6 +186,12 @@ func addTenant(c *gin.Context) {

func dockerCreateTenant(newTenant tenant) string {
tenantLower := strings.ToLower(newTenant.Name)
appDeployDir := DOCKER_DIR + "app-deploy/" + tenantLower + "/"
err := os.MkdirAll(appDeployDir, 0755)
if err != nil && !strings.Contains(err.Error(), "already") {
println(err.Error())
}

// Image tagging
if newTenant.ImageTag == "" {
newTenant.ImageTag = "main"
Expand All @@ -193,29 +203,53 @@ func dockerCreateTenant(newTenant tenant) string {
args = append(args, "--profile")
args = append(args, "web")
// Create flutter assets folder
newTenant.AssetsDir = DOCKER_DIR + "app-deploy/" + tenantLower
newTenant.AssetsDir = appDeployDir + "flutter"
addAppAssets(newTenant)
} else {
// docker does not accept it empty, even if it wont be created
newTenant.AssetsDir = DOCKER_DIR
}

if newTenant.HasDoc {
args = append(args, "--profile")
args = append(args, "doc")
}

// Default values, empty vars not accepted on docker compose
newTenant.BffApiListFile = "./bff_api_list.json"
newTenant.BffPort = newTenant.ApiPort
if newTenant.HasBff {
args = append(args, "--profile")
args = append(args, "arango")
if newTenant.BffPort == "" {
// Set API Port to BFF Port + 1
port, _ := strconv.Atoi(newTenant.ApiPort)
newTenant.ApiPort = strconv.Itoa(port + 1)
}
// Create bff api list json file
file, _ := os.Create(appDeployDir + tenantLower + "-bff-api-list.json")
err := bfftmplt.Execute(file, newTenant)
if err != nil {
fmt.Println("Error creating bff api list file: " + err.Error())
} else {
newTenant.BffApiListFile = "./app-deploy/" + tenantLower + "/" + tenantLower + "-bff-api-list.json"
}
file.Close()
}

args = append(args, "up")
args = append(args, "--build")
args = append(args, "-d")

// Create .env file
file, _ := os.Create(DOCKER_DIR + ".env")
err := tmplt.Execute(file, newTenant)
err = tmplt.Execute(file, newTenant)
if err != nil {
panic(err)
}
file.Close()
// Create tenantName.env as a copy
file, _ = os.Create(DOCKER_DIR + tenantLower + ".env")
file, _ = os.Create(appDeployDir + tenantLower + ".env")
err = tmplt.Execute(file, newTenant)
if err != nil {
fmt.Println("Error creating .env copy: " + err.Error())
Expand Down Expand Up @@ -285,7 +319,7 @@ func addTenantLogo(c *gin.Context) {
c.String(http.StatusInternalServerError, err.Error())
}
// Make sure destination dir is created
assetsDir := DOCKER_DIR + "app-deploy/" + tenantName
assetsDir := DOCKER_DIR + "app-deploy/" + tenantName + "/flutter"
err = os.MkdirAll(assetsDir, 0755)
if err != nil && !strings.Contains(err.Error(), "already") {
c.String(http.StatusInternalServerError, err.Error())
Expand All @@ -302,7 +336,7 @@ func removeTenant(c *gin.Context) {
tenantName := strings.ToLower(c.Param("name"))

// Stop and remove containers
for _, str := range []string{"_webapp", "_api", "_db", "_doc"} {
for _, str := range []string{"_webapp", "_api", "_db", "_doc", "_bff", "_arango_api", "_arango_db"} {
cmd := exec.Command("docker", "rm", "--force", strings.ToLower(tenantName)+str)
cmd.Dir = DOCKER_DIR
var stderr bytes.Buffer
Expand All @@ -315,7 +349,7 @@ func removeTenant(c *gin.Context) {
}

// Remove assets
os.RemoveAll(DOCKER_DIR + "app-deploy/" + tenantName)
os.RemoveAll(DOCKER_DIR + "app-deploy/" + tenantName + "/flutter")
os.Remove(DOCKER_DIR + tenantName + ".env")

// Update local file
Expand Down
Loading