Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Improve detection of active containers to support docker-compose v2 #12

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
5 changes: 3 additions & 2 deletions bin/composer
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env = Environment(composepath + '/.env')

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'application'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -36,14 +36,15 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

dockerrun = ['docker', 'run', '--rm']
if sys.stdin.isatty() and sys.stdout.isatty():
dockerrun += ['-it']

cmd = dockerrun

if re.search('Up', out):
if 'application' in runningContainers:
containercmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', '-q', 'application'
Expand Down
5 changes: 3 additions & 2 deletions bin/composer1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env = Environment(composepath + '/.env')

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'application'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -36,14 +36,15 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

dockerrun = ['docker', 'run', '--rm']
if sys.stdin.isatty() and sys.stdout.isatty():
dockerrun += ['-it']

cmd = dockerrun

if re.search('Up', out):
if 'application' in runningContainers:
containercmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', '-q', 'application'
Expand Down
5 changes: 3 additions & 2 deletions bin/mysql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'mysql'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -27,8 +27,9 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

if not re.search('Up', out):
if not 'mysql' in runningContainers:
raise Exception('We need a running mysql server')

cmd = [
Expand Down
5 changes: 3 additions & 2 deletions bin/mysqldump
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'mysql'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -27,8 +27,9 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

if not re.search('Up', out):
if not 'mysql' in runningContainers:
raise Exception('We need a running mysql server')

cmd = [
Expand Down
5 changes: 3 additions & 2 deletions bin/mysqlimport
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if len(sys.argv) <= 1:

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'mysql'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -30,8 +30,9 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

if not re.search('Up', out):
if not 'mysql' in runningContainers:
raise Exception('We need a running mysql server')

cmd = [
Expand Down
5 changes: 3 additions & 2 deletions bin/php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'application'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -27,8 +27,9 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

if re.search('Up', out):
if 'application' in runningContainers:
dockerrun = [os.path.dirname(sys.argv[0]) + '/run', 'exec']
if not sys.stdin.isatty() or not sys.stdout.isatty():
dockerrun += ['-T']
Expand Down
5 changes: 3 additions & 2 deletions bin/redis-cli
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')

cmd = [
os.path.dirname(sys.argv[0]) + '/run',
'ps', 'redis'
'ps', '--services', '--filter', 'status=running'
]

p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
Expand All @@ -27,8 +27,9 @@ except KeyboardInterrupt:
p.wait()
out, err = p.communicate()
out = out.decode('utf-8')
runningContainers = out.splitlines()

if not re.search('Up', out):
if not 'redis' in runningContainers:
raise Exception('We need a running redis server')

dockerrun = [os.path.dirname(sys.argv[0]) + '/run', 'exec']
Expand Down