Skip to content

Commit

Permalink
Merge pull request #132 from SelfhostedPro/updating
Browse files Browse the repository at this point in the history
Error Handling
  • Loading branch information
SelfhostedPro authored Oct 1, 2020
2 parents aec8e48 + fae1da2 commit bce3091
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
41 changes: 31 additions & 10 deletions backend/api/actions/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,28 @@ def app_action(app_name, action):

def app_update(app_name):
dclient = docker.from_env()
old = dclient.containers.get(app_name)
try:
old = dclient.containers.get(app_name)
except Exception as exc:
print(exc)
if exc.response.status_code == 404:
raise HTTPException(status_code=exc.response.status_code, detail="Unable to get container ID")
else:
raise HTTPException(status_code=exc.response.status_code, detail=exc.explanation)

volumes ={'/var/run/docker.sock': {'bind':'/var/run/docker.sock', 'mode': 'rw'}}
updater = dclient.containers.run(
image='containrrr/watchtower:latest',
command='--run-once '+old.name,
remove=True,
detach=True,
volumes=volumes
)
try:
updater = dclient.containers.run(
image='containrrr/watchtower:latest',
command='--run-once '+old.name,
remove=True,
detach=True,
volumes=volumes
)
except Exception as exc:
print(exc)
raise HTTPException(status_code=exc.response.status_code, detail=exc.explanation)

print('**** Updating '+old.name+'****')
result = updater.wait(timeout=120)
print(result)
Expand All @@ -171,7 +184,15 @@ def update_self():
dclient = docker.from_env()
bash_command = "head -1 /proc/self/cgroup|cut -d/ -f3"
yacht_id = subprocess.check_output(['bash','-c', bash_command]).decode('UTF-8').strip()
yacht = dclient.containers.get(yacht_id)
try:
yacht = dclient.containers.get(yacht_id)
except Exception as exc:
print(exc)
if exc.response.status_code == 404:
raise HTTPException(status_code=exc.response.status_code, detail="Unable to get Yacht container ID")
else:
raise HTTPException(status_code=exc.response.status_code, detail=exc.explanation)

volumes ={'/var/run/docker.sock': {'bind':'/var/run/docker.sock', 'mode': 'rw'}}
print('**** Updating '+yacht.name+'****')
updater = dclient.containers.run(
Expand All @@ -184,7 +205,7 @@ def update_self():
result = updater.wait(timeout=120)
print(result)
time.sleep(1)
return get_apps()
return result

def prune_images():
dclient = docker.from_env()
Expand Down
22 changes: 17 additions & 5 deletions frontend/src/components/serverSettings/Prune.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<template>
<v-card>
<v-fade-transition>
<v-progress-linear
indeterminate
v-if="isLoading"
color="primary"
bottom
/>
</v-fade-transition>
<v-card-title class="subheading warning font-weight-bold"
>Prune</v-card-title
>
Expand Down Expand Up @@ -65,6 +73,7 @@ export default {
data() {
return {
containerDialog: false,
isLoading: false,
};
},
methods: {
Expand All @@ -84,20 +93,21 @@ export default {
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
},
prune(resource) {
this.isLoading = true;
axios({
url: "/api/settings/prune/" + resource,
method: "GET",
responseType: "text/json",
})
.then((response) => {
console.log(response.data);
let action = Object.keys(response.data)[0]
console.log(action)
let action = Object.keys(response.data)[0];
console.log(action);
if (response.data[action] != null) {
console.log(response.data[action].length)
var deletedNumber = response.data[action].length
console.log(response.data[action].length);
var deletedNumber = response.data[action].length;
} else {
deletedNumber = '0'
deletedNumber = "0";
}
this.setMessage(
deletedNumber +
Expand All @@ -106,9 +116,11 @@ export default {
". Space Reclaimed: " +
this.formatBytes(response.data.SpaceReclaimed)
);
this.isLoading = false;
})
.catch((err) => {
this.setErr(err);
this.isLoading = false;
});
},
},
Expand Down
23 changes: 12 additions & 11 deletions frontend/src/components/serverSettings/ServerUpdate.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<template>
<v-card>
<v-fade-transition>
<v-progress-linear
indeterminate
v-if="isLoading"
color="primary"
bottom
/>
</v-fade-transition>
<v-card-title class="subheading primary font-weight-bold"
>Update</v-card-title
>
Expand All @@ -23,37 +31,30 @@ export default {
data() {
return {
containerDialog: false,
isLoading: false,
};
},
methods: {
...mapMutations({
setMessage: "snackbar/setMessage",
setErr: "snackbar/setErr",
}),
formatBytes(bytes) {
if (bytes === 0) return "0 Bytes";
const decimals = 2;
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
},
update() {
this.isLoading = true
axios({
url: "/api/settings/update",
method: "GET",
responseType: "text/json",
})
.then((response) => {
this.isLoading = false
console.log(response.data);
this.setMessage(
"Yacht is updating now"
);
})
.catch((err) => {
this.isLoading = false
this.setErr(err);
});
},
Expand Down

0 comments on commit bce3091

Please sign in to comment.