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

App list #89

Merged
merged 7 commits into from
Sep 22, 2020
Merged
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
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: SelfhostedPro
open_collective: selfhostedpros
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![logo](https://raw.githubusercontent.com/SelfhostedPro/Yacht/vue/readme_media/Yacht_logo_1_dark.png "templates")
![logo](https://raw.githubusercontent.com/SelfhostedPro/Yacht/master/readme_media/Yacht_logo_1_dark.png "templates")

[![Docker Hub Pulls](https://img.shields.io/docker/pulls/selfhostedpro/yacht?color=%234518f5&label=Docker%20Pulls&logo=docker&logoColor=%23403d3d&style=for-the-badge)](https://hub.docker.com/r/selfhostedpro/yacht)
[![Docker Image Size](https://img.shields.io/docker/image-size/selfhostedpro/yacht/vue?color=%234518f5&label=Image%20Size&logo=docker&logoColor=%23403d3d&style=for-the-badge)](https://hub.docker.com/r/selfhostedpro/yacht)
Expand All @@ -7,7 +7,7 @@
Yacht is a container management UI with a focus on templates and 1-click deployments.

## Demo:
![Tempaltes](https://raw.githubusercontent.com/SelfhostedPro/Yacht/vue/readme_media/Yacht-Demo.gif "templates")
![Tempaltes](https://raw.githubusercontent.com/SelfhostedPro/Yacht/master/readme_media/Yacht-Demo.gif "templates")

## Installation:
Currently only linux has been verified as working but we are open to the idea of supporting windows eventually as well.
Expand Down
64 changes: 36 additions & 28 deletions backend/api/routers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ async def logs(websocket: WebSocket, app_name: str):
await websocket.accept()
async with aiodocker.Docker() as docker:
container: DockerContainer = await docker.containers.get(app_name)
logs = container.log(stdout=True, stderr=True, follow=True)
async for line in logs:
try:
await websocket.send_text(line)
except Exception as e:
return e
if container._container['State']['Status'] == 'running':
stats = container.stats(stream=True)
logs = container.log(stdout=True, stderr=True, follow=True)
async for line in logs:
try:
await websocket.send_text(line)
except Exception as e:
return e
else:
await websocket.close(code=status.WS_1011_INTERNAL_ERROR)
else:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)

Expand All @@ -92,28 +96,32 @@ async def stats(websocket: WebSocket, app_name: str):
cpu_percent = 0.0

container: DockerContainer = await docker.containers.get(app_name)
stats = container.stats(stream=True)
async for line in stats:
mem_current = line["memory_stats"]["usage"]
mem_total = line["memory_stats"]["limit"]

try:
cpu_percent, cpu_system, cpu_total = await calculate_cpu_percent2(line, cpu_total, cpu_system)
except KeyError as e:
print("error while getting new CPU stats: %r, falling back")
cpu_percent = await calculate_cpu_percent(line)

full_stats = {
"time": line['read'],
"cpu_percent": cpu_percent,
"mem_current": mem_current,
"mem_total": line["memory_stats"]["limit"],
"mem_percent": (mem_current / mem_total) * 100.0,
}
try:
await websocket.send_text(json.dumps(full_stats))
except Exception as e:
return e
if container._container['State']['Status'] == 'running':
stats = container.stats(stream=True)

async for line in stats:
mem_current = line["memory_stats"]["usage"]
mem_total = line["memory_stats"]["limit"]

try:
cpu_percent, cpu_system, cpu_total = await calculate_cpu_percent2(line, cpu_total, cpu_system)
except KeyError as e:
print("error while getting new CPU stats: %r, falling back")
cpu_percent = await calculate_cpu_percent(line)

full_stats = {
"time": line['read'],
"cpu_percent": cpu_percent,
"mem_current": mem_current,
"mem_total": line["memory_stats"]["limit"],
"mem_percent": (mem_current / mem_total) * 100.0,
}
try:
await websocket.send_text(json.dumps(full_stats))
except Exception as e:
return e
else:
await websocket.close(code=status.WS_1011_INTERNAL_ERROR)
else:
await websocket.close(code=status.WS_1008_POLICY_VIOLATION)

Expand Down
2 changes: 2 additions & 0 deletions backend/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Settings(BaseSettings):
ADMIN_EMAIL = os.environ.get('ADMIN_EMAIL', '[email protected]')
ACCESS_TOKEN_EXPIRES = os.environ.get('ACCESS_TOKEN_EXPIRES', 15)
REFRESH_TOKEN_EXPIRES = os.environ.get('REFRESH_TOKEN_EXPIRES', 1)
SAME_SITE_COOKIES = os.environ.get('SAME_SITE_COOKIES', True)

BASE_TEMPLATE_VARIABLES = [
{"variable": "!config", "replacement": "/yacht/AppData/Config"},
{"variable": "!data", "replacement": "/yacht/AppData/Data"},
Expand Down
17 changes: 4 additions & 13 deletions frontend/src/components/applications/ApplicationDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default {
this.readAppStats(appName);
},
readAppLogs(appName) {
console.log("Starting connection to Websocket");
console.log("Starting connection to Logs");
this.connection = new WebSocket(
`ws://${location.hostname}:${location.port}/api/apps/${appName}/livelogs`
);
Expand All @@ -104,18 +104,10 @@ export default {
// this.connection.close("Leaving page or refreshing", 1001);
},
readAppStats(appName) {
console.log("Starting connection to Websocket");
let proto = "";
console.log(location.protocol);
if (location.protocol == "http:") {
console.log("if working");
proto = "ws://";
} else if (location.protocol == "https:") {
proto = "wss://";
}
console.log(proto);
console.log("Starting connection to Stats");

this.statConnection = new WebSocket(
`${proto}${location.hostname}:${location.port}/api/apps/${appName}/stats`
`ws://${location.hostname}:${location.port}/api/apps/${appName}/stats`
);
this.statConnection.onopen = () => {
this.statConnection.send(
Expand All @@ -129,7 +121,6 @@ export default {
this.stats.mem_percent.push(Math.round(statsGroup.mem_percent));
this.stats.mem_current.push(statsGroup.mem_current);
this.stats.mem_total.push(statsGroup.mem_total);
console.log(this.stats.blk_read);
for (let key in this.stats) {
if (this.stats[key].length > 300) {
this.stats[key].shift();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,42 @@
>
Start the app to view stats
</v-card-text>
<v-card flat>
<v-card-title>
CPU Usage {{ stats.cpu_percent[stats.cpu_percent.length - 1] }}%
</v-card-title>
<v-card-subtitle>
(0-100%) <br />
Max: {{ Math.max.apply(Math, stats.cpu_percent) }}%
</v-card-subtitle>
<PercentLineChart :chartData="fillCPU(stats.cpu_percent, stats.time)" />
</v-card>
<v-card flat>
<v-card-title>
Memory Usage {{ stats.mem_percent[stats.mem_percent.length - 1] }}%,
{{ formatBytes(stats.mem_current[stats.mem_current.length - 1]) }}/{{
formatBytes(stats.mem_total[stats.mem_total.length - 1])
}}
</v-card-title>
<v-card-subtitle>
(0-100%) <br />
Max: {{ Math.max.apply(Math, stats.mem_percent) }}%,
{{ formatBytes(Math.max.apply(Math, stats.mem_current)) }}/{{
formatBytes(stats.mem_total[stats.mem_total.length - 1])
}}
</v-card-subtitle>
<PercentLineChart :chartData="fillMem(stats.mem_percent, stats.time)" />
</v-card>
<div v-else>
<v-card flat>
<v-card-title>
CPU Usage {{ stats.cpu_percent[stats.cpu_percent.length - 1] }}%
</v-card-title>
<v-card-subtitle>
(0-100%) <br />
Max: {{ Math.max.apply(Math, stats.cpu_percent) }}%
</v-card-subtitle>
<PercentLineChart :chartData="fillCPU(stats.cpu_percent, stats.time)" />
</v-card>
<v-card flat>
<v-card-title>
Memory Usage {{ stats.mem_percent[stats.mem_percent.length - 1] }}%,
{{ formatBytes(stats.mem_current[stats.mem_current.length - 1]) }}/{{
formatBytes(stats.mem_total[stats.mem_total.length - 1])
}}
</v-card-title>
<v-card-subtitle>
(0-100%) <br />
Max: {{ Math.max.apply(Math, stats.mem_percent) }}%,
{{ formatBytes(Math.max.apply(Math, stats.mem_current)) }}/{{
formatBytes(stats.mem_total[stats.mem_total.length - 1])
}}
</v-card-subtitle>
<PercentLineChart :chartData="fillMem(stats.mem_percent, stats.time)" />
</v-card>
</div>
</v-card>
</template>

<script>
import PercentLineChart from "../../charts/PercentLineChart";
export default {
components: {
PercentLineChart
PercentLineChart,
},
props: ["app", "stats"],
data() {
Expand Down Expand Up @@ -70,9 +72,9 @@ export default {
pointRadius: 0,
data: time.map((t, i) => {
return { x: t, y: stat[i] };
})
}
]
}),
},
],
};
return datacollection;
},
Expand All @@ -86,13 +88,13 @@ export default {
pointRadius: 0,
data: time.map((t, i) => {
return { x: t, y: stat[i] };
})
}
]
}),
},
],
};
return datacollection;
}
}
},
},
};
</script>

Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/applications/ApplicationsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ export default {
const payload = { ...this.form };
this.isLoading = true;
const url = `/api/apps/deploy`;
console.log(payload);
axios
.post(url, payload)
.then(() => {
Expand Down
Loading