Skip to content

Commit

Permalink
Merge pull request #129 from SelfhostedPro/updating
Browse files Browse the repository at this point in the history
wait until watchtower exits to move on
  • Loading branch information
SelfhostedPro authored Sep 30, 2020
2 parents d2de7d5 + 6761a5b commit aec8e48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
47 changes: 22 additions & 25 deletions backend/api/actions/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ..utils import *

from datetime import datetime
import time
import subprocess
import docker

Expand Down Expand Up @@ -152,41 +153,37 @@ def app_action(app_name, action):
def app_update(app_name):
dclient = docker.from_env()
old = dclient.containers.get(app_name)
properties = {
'name': old.name,
'hostname': old.attrs['Config']['Hostname'],
'user': old.attrs['Config']['User'],
'detach': True,
'domainname': old.attrs['Config']['Domainname'],
'tty': old.attrs['Config']['Tty'],
'ports': get_update_ports(old.ports),
'volumes': None if not old.attrs['Config'].get('Volumes') else [
v for v in old.attrs['Config']['Volumes'].keys()
],
'working_dir': old.attrs['Config']['WorkingDir'],
'labels': old.attrs['Config']['Labels'],
'entrypoint': old.attrs['Config']['Entrypoint'],
'environment': old.attrs['Config']['Env'],
'healthcheck': old.attrs['Config'].get('Healthcheck', None)
}
dclient.images.pull(old.image.tags[0])
old.stop()
old.remove()
dclient.containers.run(old.image.tags[0], old.attrs['Config']['Cmd'], **properties)
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
)
print('**** Updating '+old.name+'****')
result = updater.wait(timeout=120)
print(result)
time.sleep(1)
return get_apps()

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')
print(yacht_id)
yacht_id = subprocess.check_output(['bash','-c', bash_command]).decode('UTF-8').strip()
yacht = dclient.containers.get(yacht_id)
volumes ={'/var/run/docker.sock': {'bind':'/var/run/docker.sock', 'mode': 'rw'}}
dclient.containers.run(
print('**** Updating '+yacht.name+'****')
updater = dclient.containers.run(
image='containrrr/watchtower:latest',
command='--run-once '+yacht_id,
command='--run-once '+yacht.name,
remove=True,
detach=True,
volumes=volumes
)
result = updater.wait(timeout=120)
print(result)
time.sleep(1)
return get_apps()

def prune_images():
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/serverSettings/ServerUpdate.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<v-card>
<v-card-title class="subheading primary font-weight-bold"
>Prune</v-card-title
>Update</v-card-title
>
<v-card-text class="mt-2"
>Update Yacht to the latest version. <br/> Note: This will kill the running version of Yacht, Pull the latest version of the current tag, and run that with the same settings that are currently set.</v-card-text
>Update Yacht to the latest version. <br/> Note: This will spin up a run-once watchtower instance and update Yacht. In the process Yacht will be restarted.</v-card-text
>
<v-btn
class="mx-5 mb-5"
Expand Down

0 comments on commit aec8e48

Please sign in to comment.