Skip to content

Commit

Permalink
fixed db migration; changed how apps are displayed; linted
Browse files Browse the repository at this point in the history
  • Loading branch information
SelfhostedPro committed Mar 5, 2021
1 parent 2a22e80 commit bfd7071
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 79 deletions.
10 changes: 3 additions & 7 deletions backend/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from api.settings import Settings
from api.db import models
from os.path import abspath, dirname
import sys
import os
Expand All @@ -23,10 +21,9 @@
# target_metadata = mymodel.Base.metadata

sys.path.insert(0, dirname(dirname(abspath(__file__))))

from api.db import models

print("--- MODELS ---")
print(models)
# Combine metadata from auth and containers/templates
combined_meta_data = MetaData()
for declarative_base in [models.Base]:
Expand Down Expand Up @@ -62,13 +59,12 @@ def run_migrations_offline():
url=url,
target_metadata=target_metadata,
literal_binds=True,
starting_rev=None,
dialect_opts={"paramstyle": "named"},
)

with context.begin_transaction():
context.execute("DROP TABLE IF EXISTS alembic_version;")
context.run_migrations()
context.execute("DROP TABLE IF EXISTS alembic_version")


def run_migrations_online():
Expand All @@ -89,8 +85,8 @@ def run_migrations_online():
target_metadata=target_metadata)

with context.begin_transaction():
context.execute("DROP TABLE IF EXISTS alembic_version;")
context.run_migrations()
context.execute("DROP TABLE IF EXISTS alembic_version")


if context.is_offline_mode():
Expand Down
4 changes: 3 additions & 1 deletion backend/api/actions/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def write_compose(compose):
f.close()
except TypeError as exc:
if exc.args[0] == "write() argument must be str, not None":
raise HTTPException(status_code=422, detail="Compose file cannot be empty.")
raise HTTPException(
status_code=422, detail="Compose file cannot be empty."
)
except Exception as exc:
raise HTTPException(exc.status_code, exc.detail)

Expand Down
2 changes: 2 additions & 0 deletions backend/api/actions/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from fastapi import HTTPException

### IMAGES ###


def get_images():
dclient = docker.from_env()
containers = dclient.containers.list(all=True)
Expand Down
1 change: 1 addition & 0 deletions backend/api/db/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .models import *
8 changes: 4 additions & 4 deletions backend/api/db/crud/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def add_template(db: Session, template: models.Template):
sysctls=sysctls,
cap_add=entry.get("cap_add", []),
cpus=entry.get("cpus"),
mem_limit=entry.get("mem_limit")
mem_limit=entry.get("mem_limit"),
)
except Exception as exc:
raise HTTPException(
Expand Down Expand Up @@ -124,7 +124,7 @@ def add_template(db: Session, template: models.Template):
sysctls=sysctls,
cap_add=entry.get("cap_add", []),
cpus=entry.get("cpus"),
mem_limit=entry.get("mem_limit")
mem_limit=entry.get("mem_limit"),
)
_template.items.append(template_content)
except (OSError, TypeError, ValueError) as err:
Expand Down Expand Up @@ -190,7 +190,7 @@ def refresh_template(db: Session, template_id: id):
sysctls=sysctls,
cap_add=entry.get("cap_add", []),
cpus=entry.get("cpus"),
mem_limit=entry.get("mem_limit")
mem_limit=entry.get("mem_limit"),
)
items.append(item)
elif type(loaded_file) == dict:
Expand Down Expand Up @@ -221,7 +221,7 @@ def refresh_template(db: Session, template_id: id):
sysctls=sysctls,
cap_add=entry.get("cap_add", []),
cpus=entry.get("cpus"),
mem_limit=entry.get("mem_limit")
mem_limit=entry.get("mem_limit"),
)
items.append(template_content)
except Exception as exc:
Expand Down
10 changes: 7 additions & 3 deletions backend/api/db/crud/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def get_user(db: Session, user_id: int):


def get_user_by_name(db: Session, username: str):
return db.query(models.User).filter(models.User.username == username.casefold()).first()
return (
db.query(models.User)
.filter(models.User.username == username.casefold())
.first()
)


def get_users(db: Session, skip: int = 0, limit: int = 100):
Expand All @@ -33,8 +37,8 @@ def update_user(db: Session, user: schemas.UserCreate, current_user):
_user = get_user_by_name(db=db, username=current_user)
if _user and _user.is_active:
if _user.username.casefold() != user.username.casefold():
print('Old Username: {name}'.format(name=_user.username))
print('New Username: {name}'.format(name=user.username))
print("Old Username: {name}".format(name=_user.username))
print("New Username: {name}".format(name=user.username))
_user.username = user.username.casefold()
if user.password != "":
_user.hashed_password = _hashed_password
Expand Down
2 changes: 2 additions & 0 deletions backend/api/routers/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

router = APIRouter()
### Images ###


@router.get(
"/images/",
)
Expand Down
6 changes: 5 additions & 1 deletion backend/api/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def login(
db: Session = Depends(get_db),
Authorize: AuthJWT = Depends(),
):
_user = db.query(models.User).filter(models.User.username == user.username.casefold()).first()
_user = (
db.query(models.User)
.filter(models.User.username == user.username.casefold())
.first()
)
if _user is not None and crud.verify_password(user.password, _user.hashed_password):
# Create Tokens
access_token = Authorize.create_access_token(subject=user.username)
Expand Down
14 changes: 10 additions & 4 deletions backend/api/utils/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# {
# '53/tcp': ('0.0.0.0', 53),
# }


def conv_ports2data(data, network, network_mode):
ports = {}
for d in data:
Expand Down Expand Up @@ -129,6 +131,8 @@ def conv_devices2data(data):
else:
devices = None
return devices


# def conv_labels2data(data):
# # Set is depracated. Name is the actual value. Label is the name of the field.
# # Label is the label of the label field.
Expand Down Expand Up @@ -333,11 +337,12 @@ def _check_updates(tag):
return False
else:
raise HTTPException(
status_code=err.response.status_code, detail=err.explanation
status_code=err.response.status_code,
detail=err.explanation
)
try:
new = dclient.images.get_registry_data(tag)
except APIError as err:
except APIError:
return False
if any(
new.attrs["Descriptor"]["digest"] in i for i in current.attrs["RepoDigests"]
Expand All @@ -359,8 +364,9 @@ def format_bytes(size):
n += 1
return str(round(size)) + " " + str(power_labels[n])


def conv_cpus2data(cpus):
if cpus:
return cpus*10**9
return cpus * 10 ** 9
else:
return None
return None
65 changes: 56 additions & 9 deletions frontend/src/components/applications/ApplicationDetails.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
<template lang="html">
<v-card color="foreground" class="d-flex mx-auto page">
<v-container fluid class="component">
<Nav class="mb-3" :isLoading="isLoading" />
<div>
<v-tabs
v-model="AppTab"
class="mb-3"
background-color="tabs"
mobile-breakpoint="sm"
>
<v-tab class="text-left" @click="$router.go(-1)">
<v-icon left class="mr-1">mdi-arrow-left-bold-outline</v-icon> Back
</v-tab>
<v-tab class="text-left">
<v-icon left class="mr-1">mdi-information-outline</v-icon>Info
</v-tab>
<v-tab class="text-left">
<v-icon left class="mr-1">mdi-view-list-outline</v-icon>Processes
</v-tab>
<v-tab class="text-left">
<v-icon left class="mr-1">mdi-book-open-outline</v-icon>Logs
</v-tab>
<v-tab class="text-left">
<v-icon left class="mr-1">mdi-gauge</v-icon>Stats
</v-tab>
</v-tabs>
<v-fade-transition>
<v-progress-linear
indeterminate
v-if="isLoading"
color="primary"
bottom
/>
</v-fade-transition>
</div>
<v-card color="foreground" class="pb-3" tile>
<v-row>
<v-col xs="12" sm="12" md="6" class="flex-grow-1 flex-shrink-0">
Expand Down Expand Up @@ -239,27 +270,43 @@
leave-active-class="animated slideOutRight"
mode="out-in"
>
<router-view
:app="app"
:processes="processes"
:logs="logs"
:stats="stats"
/>
<v-tabs-items v-model="AppTab" class="mt-3">
<v-tab-item> </v-tab-item>
<v-tab-item>
<Content :app="app" />
</v-tab-item>
<v-tab-item>
<Processes :app="app" :processes="processes" />
</v-tab-item>
<v-tab-item>
<Logs :app="app" :logs="logs" />
</v-tab-item>
<v-tab-item>
<Stats :app="app" :stats="stats" />
</v-tab-item>
</v-tabs-items>
</transition>
</v-card>
</v-container>
</v-card>
</template>

<script>
import ApplicationDetailsNav from "./ApplicationDetailsComponents/ApplicationDetailsNav";
import AppStats from "./ApplicationDetailsComponents/AppStats";
import AppProcesses from "./ApplicationDetailsComponents/AppProcesses";
import AppContent from "./ApplicationDetailsComponents/AppContent";
import AppLogs from "./ApplicationDetailsComponents/AppLogs";
import { mapActions, mapGetters, mapState } from "vuex";
export default {
components: {
Nav: ApplicationDetailsNav
Content: AppContent,
Processes: AppProcesses,
Logs: AppLogs,
Stats: AppStats
},
data() {
return {
AppTab: 1,
removeDialog: false,
logs: [],
stats: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@
<td>
<v-chip
v-if="port.hip == '0.0.0.0'"
color="indigo darken-2"
color="primary"
label
:href="'http://' + host_ip + ':' + port.hport"
target="_blank"
><v-icon small class="mr-1">mdi-link-variant</v-icon
>{{ port.hport }}</v-chip
><v-chip
v-else
color="indigo darken-2"
color="primary"
label
:href="'http://' + port.hip + ':' + port.hport"
target="_blank"
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/components/applications/ApplicationsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
v-bind="attrs"
class="ma-1"
v-else
color="indigo darken-2"
color="primary"
label
small
:href="'http://' + port.hip + ':' + port.hport"
Expand Down Expand Up @@ -342,7 +342,7 @@ export default {
checkUpdate: "apps/checkAppUpdate"
}),
handleRowClick(appName) {
this.$router.push({ path: `/apps${appName.Name}/info` });
this.$router.push({ path: `/apps${appName.Name}` });
},
editClick(appName) {
this.$router.push({ path: `/apps/edit/${appName.Name}` });
Expand Down
4 changes: 2 additions & 2 deletions root/etc/cont-init.d/31-migrate
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/with-contenv bash
cd /
#Stage a db migration
s6-setuidgid abc \
sqlite3 /config/data.sqlite "DROP TABLE IF EXISTS alembic_version;"
# s6-setuidgid abc \
# sqlite3 /config/data.sqlite "DROP TABLE IF EXISTS alembic_version;"
# Make sure versions folder exists
s6-setuidgid abc \
mkdir -p /alembic/versions
Expand Down

0 comments on commit bfd7071

Please sign in to comment.