Skip to content

Commit 5f5b20e

Browse files
Merge pull request #12 from StephenBeirlaen/feature/docker-compose-v2-support
Improve detection of active containers to support docker-compose v2
2 parents b3eeb1e + f10db9d commit 5f5b20e

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

bin/composer

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env = Environment(composepath + '/.env')
2222

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

2828
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -36,14 +36,15 @@ except KeyboardInterrupt:
3636
p.wait()
3737
out, err = p.communicate()
3838
out = out.decode('utf-8')
39+
runningContainers = out.splitlines()
3940

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

4445
cmd = dockerrun
4546

46-
if re.search('Up', out):
47+
if 'application' in runningContainers:
4748
containercmd = [
4849
os.path.dirname(sys.argv[0]) + '/run',
4950
'ps', '-q', 'application'

bin/composer1

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env = Environment(composepath + '/.env')
2222

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

2828
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -36,14 +36,15 @@ except KeyboardInterrupt:
3636
p.wait()
3737
out, err = p.communicate()
3838
out = out.decode('utf-8')
39+
runningContainers = out.splitlines()
3940

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

4445
cmd = dockerrun
4546

46-
if re.search('Up', out):
47+
if 'application' in runningContainers:
4748
containercmd = [
4849
os.path.dirname(sys.argv[0]) + '/run',
4950
'ps', '-q', 'application'

bin/mysql

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')
1313

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

1919
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -27,8 +27,9 @@ except KeyboardInterrupt:
2727
p.wait()
2828
out, err = p.communicate()
2929
out = out.decode('utf-8')
30+
runningContainers = out.splitlines()
3031

31-
if not re.search('Up', out):
32+
if not 'mysql' in runningContainers:
3233
raise Exception('We need a running mysql server')
3334

3435
cmd = [

bin/mysqldump

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')
1313

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

1919
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -27,8 +27,9 @@ except KeyboardInterrupt:
2727
p.wait()
2828
out, err = p.communicate()
2929
out = out.decode('utf-8')
30+
runningContainers = out.splitlines()
3031

31-
if not re.search('Up', out):
32+
if not 'mysql' in runningContainers:
3233
raise Exception('We need a running mysql server')
3334

3435
cmd = [

bin/mysqlimport

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if len(sys.argv) <= 1:
1616

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

2222
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -30,8 +30,9 @@ except KeyboardInterrupt:
3030
p.wait()
3131
out, err = p.communicate()
3232
out = out.decode('utf-8')
33+
runningContainers = out.splitlines()
3334

34-
if not re.search('Up', out):
35+
if not 'mysql' in runningContainers:
3536
raise Exception('We need a running mysql server')
3637

3738
cmd = [

bin/php

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')
1313

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

1919
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -27,8 +27,9 @@ except KeyboardInterrupt:
2727
p.wait()
2828
out, err = p.communicate()
2929
out = out.decode('utf-8')
30+
runningContainers = out.splitlines()
3031

31-
if re.search('Up', out):
32+
if 'application' in runningContainers:
3233
dockerrun = [os.path.dirname(sys.argv[0]) + '/run', 'exec']
3334
if not sys.stdin.isatty() or not sys.stdout.isatty():
3435
dockerrun += ['-T']

bin/redis-cli

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env = Environment(composepath + '/.env')
1313

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

1919
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -27,8 +27,9 @@ except KeyboardInterrupt:
2727
p.wait()
2828
out, err = p.communicate()
2929
out = out.decode('utf-8')
30+
runningContainers = out.splitlines()
3031

31-
if not re.search('Up', out):
32+
if not 'redis' in runningContainers:
3233
raise Exception('We need a running redis server')
3334

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

0 commit comments

Comments
 (0)