Skip to content

Commit

Permalink
Merge pull request #1772 from SethFalco/chore/docker-compose
Browse files Browse the repository at this point in the history
chore: upgrade docs to docker compose v2
  • Loading branch information
christianlupus authored Aug 29, 2023
2 parents 09138c6 + 3c5fac0 commit eb896b3
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 83 deletions.
1 change: 1 addition & 0 deletions .github/actions/run-tests/run-locally.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
debugpy.wait_for_client()

# print(args)
test_runner.docker_helper.initialize(args)

test_runner.ci_printer.logger = test_runner.ci_printer.CILogger(args.ci)

Expand Down
1 change: 1 addition & 0 deletions .github/actions/run-tests/test_runner/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def parseArguments():

parser.add_argument('-v', '--verbose', action='store_true', help='Do not hide the output of intermediate commands')
parser.add_argument('--debug-python', action='store_true', help='Activate the python debugger to develop the test environments.')
parser.add_argument('--use-docker-compose-legacy', action='store_true', help='Use the legacy docker-compose v1 instead of the new docker compose.')

group = parser.add_argument_group('Docker image management', 'Manage the docker images involved in the test routines.')

Expand Down
35 changes: 19 additions & 16 deletions .github/actions/run-tests/test_runner/db.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import test_runner.proc as p
import test_runner.docker_helper

class PostgresConnector:
def __init__(self, user='tester', password='tester_pass', db='nc_test'):
self.user = user
self.password = password
self.db = db

self.dockerComposeCmd = test_runner.docker_helper.instance.getDockerCompose()

def getUser(self):
return self.user

def getDb(self):
return self.db

def getPassword(self):
return self.password

def callSQL(self, input, params = [], text=True, capture_output=True, stdin=None):
cmd = [
'docker-compose', 'exec', '-T', 'postgres', 'psql', '-U', self.user, self.db,
cmd = self.dockerComposeCmd + [
'exec', '-T', 'postgres', 'psql', '-U', self.user, self.db,
'-v', 'ON_ERROR_STOP=1'
]
return p.pr.run(cmd + params, text=text, input=input, capture_output=capture_output, stdin=stdin)

def dumpDb(self, name):
cmd = [
'docker-compose', 'exec', '-T', 'postgres', 'pg_dump', '-U', self.user, self.db, '--clean', '--if-exists'
cmd = self.dockerComposeCmd + [
'exec', '-T', 'postgres', 'pg_dump', '-U', self.user, self.db, '--clean', '--if-exists'
]
with open(name, 'w') as fp:
p.pr.run(cmd, stdout=fp).check_returncode()
Expand All @@ -34,27 +36,28 @@ def __init__(self, user='tester', password='tester_pass', db='nc_test'):
self.user = user
self.password = password
self.db = db

self.dockerComposeCmd = test_runner.docker_helper.instance.getDockerCompose()

def getUser(self):
return self.user

def getDb(self):
return self.db

def getPassword(self):
return self.password

def callSQL(self, input, params = [], text=True, capture_output=True, stdin=None):
cmd = [
'docker-compose', 'exec', '-T', 'mysql', 'mysql', '-u', self.user,
cmd = self.dockerComposeCmd + [
'exec', '-T', 'mysql', 'mysql', '-u', self.user,
'-p{pwd}'.format(pwd=self.password), self.db
]
# print('input', input)
return p.pr.run(cmd + params, text=text, input=input, capture_output=capture_output, stdin=stdin)

def dumpDb(self, name):
cmd = [
'docker-compose', 'exec', '-T', 'mysql', 'mysqldump', '-u', self.user,
cmd = self.dockerComposeCmd + [
'exec', '-T', 'mysql', 'mysqldump', '-u', self.user,
'-p{pwd}'.format(pwd=self.password), '--add-drop-database', '--database', self.db
]
with open(name, 'w') as fp:
Expand Down
15 changes: 15 additions & 0 deletions .github/actions/run-tests/test_runner/docker_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class DockerHelper:
def __init__(self, args):
self.useLegacy = args.use_docker_compose_legacy

def getDockerCompose(self):
if self.useLegacy:
return ['docker-compose']
else:
return ['docker', 'compose']

instance = None

def initialize(args):
global instance
instance = DockerHelper(args)
20 changes: 13 additions & 7 deletions .github/actions/run-tests/test_runner/docker_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
import test_runner.timer
import test_runner.ci_printer as l
import test_runner.proc as p
import test_runner.docker_helper

def pullImages(args, quiet=True):
l.logger.printTask('Pulling pre-built images')
cmd = ['docker-compose', 'pull']

dockerComposeCmd = test_runner.docker_helper.instance.getDockerCompose()

cmd = dockerComposeCmd + ['pull']
if quiet:
cmd.append('--quiet')
p.pr.run(cmd).check_returncode()
Expand All @@ -29,8 +33,10 @@ def runPull(localName, remoteName):

def buildImages(args, pull=True):
l.logger.printTask('Building images')

cmd = ['docker-compose', 'build', '--force-rm']

dockerComposeCmd = test_runner.docker_helper.instance.getDockerCompose()

cmd = dockerComposeCmd + ['build', '--force-rm']
if pull:
cmd.append('--pull')
if args.ci:
Expand All @@ -41,7 +47,7 @@ def buildImages(args, pull=True):

p.pr.run(cmd).check_returncode()

p.pr.run(['docker-compose', 'build', '--pull', '--force-rm', 'mysql', 'postgres', 'www']).check_returncode()
p.pr.run(dockerComposeCmd + ['build', '--pull', '--force-rm', 'mysql', 'postgres', 'www']).check_returncode()

l.logger.printTask('Building images finished.')

Expand Down Expand Up @@ -83,14 +89,14 @@ def handleDockerImages(args):
if args.pull or args.create_images:
pullImages(args, not args.verbose)
t.toc('Pulling done')

if args.create_images:
pull = not args.pull_php_base_image
buildImages(args, pull)
t.toc('Building done')

if args.push_images:
pushImages(args)

l.logger.endGroup()
t.toc()
16 changes: 8 additions & 8 deletions .github/actions/run-tests/test_runner/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import test_runner.ci_printer as l
import test_runner.proc as p
import test_runner.docker_helper

import os

Expand All @@ -9,23 +10,23 @@ def __init__(self):
pass

def __buildRunCmd(self, args, subArgs):
cmd = ['docker-compose', 'run', '--rm', 'dut']
cmd = test_runner.docker_helper.instance.getDockerCompose() + ['run', '--rm', 'dut']

if args.run_unit_tests:
cmd.append('--run-unit-tests')

if args.run_integration_tests:
cmd.append('--run-integration-tests')

if args.run_migration_tests:
cmd.append('--run-migration-tests')

if args.extract_code_coverage:
cmd.append('--create-coverage-report')

if args.install_composer_deps:
cmd.append('--install-composer-deps')

if args.build_npm:
cmd.append('--build-npm')

Expand All @@ -42,7 +43,7 @@ def __getDebugMode(self, args):
modes.append('trace')
if args.enable_profiling:
modes.append('profile')

return ",".join(modes)

def runTests(self, args, subArgs, db):
Expand All @@ -64,4 +65,3 @@ def runTests(self, args, subArgs, db):
sp = p.pr.run(cmd, env=env)

return sp.returncode

Loading

0 comments on commit eb896b3

Please sign in to comment.