Skip to content

Commit

Permalink
chore: upgrade docs to docker compose v2
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Falco <seth@falco.fun>
  • Loading branch information
SethFalco committed Jul 30, 2023
1 parent 46ecc67 commit 5bf30fa
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 60 deletions.
24 changes: 12 additions & 12 deletions .github/actions/run-tests/test_runner/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ def __init__(self, user='tester', password='tester_pass', db='nc_test'):
self.user = user
self.password = password
self.db = db

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,
'docker', 'compose', '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'
'docker', 'compose', '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 +34,27 @@ def __init__(self, user='tester', password='tester_pass', db='nc_test'):
self.user = user
self.password = password
self.db = db

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,
'docker', 'compose', '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,
'docker', 'compose', '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
14 changes: 7 additions & 7 deletions .github/actions/run-tests/test_runner/docker_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def pullImages(args, quiet=True):
l.logger.printTask('Pulling pre-built images')
cmd = ['docker-compose', 'pull']
cmd = ['docker', 'compose', 'pull']
if quiet:
cmd.append('--quiet')
p.pr.run(cmd).check_returncode()
Expand All @@ -29,8 +29,8 @@ def runPull(localName, remoteName):

def buildImages(args, pull=True):
l.logger.printTask('Building images')
cmd = ['docker-compose', 'build', '--force-rm']

cmd = ['docker', 'compose', 'build', '--force-rm']
if pull:
cmd.append('--pull')
if args.ci:
Expand All @@ -41,7 +41,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(['docker', 'compose', 'build', '--pull', '--force-rm', 'mysql', 'postgres', 'www']).check_returncode()

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

Expand Down Expand Up @@ -83,14 +83,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()
15 changes: 7 additions & 8 deletions .github/actions/run-tests/test_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ def __init__(self):
pass

def __buildRunCmd(self, args, subArgs):
cmd = ['docker-compose', 'run', '--rm', 'dut']
cmd = ['docker', 'compose', '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 +42,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 +64,3 @@ def runTests(self, args, subArgs, db):
sp = p.pr.run(cmd, env=env)

return sp.returncode

62 changes: 31 additions & 31 deletions .github/actions/run-tests/test_runner/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self):
def ensureFolderStructureExists(self):
if not os.path.isdir('volumes'):
os.mkdir('volumes')

volumeFolders = (
'nextcloud', 'data', 'cookbook', 'mysql', 'postgres', 'www',
'dumps', 'coverage', 'output'
Expand All @@ -22,10 +22,10 @@ def ensureFolderStructureExists(self):
p = os.path.join('volumes', f)
if os.path.exists(p) and not os.path.isdir(p):
raise Exception('Cannot create folder structure appropriately. Offending folder is %s' % p)

if not os.path.exists(p):
os.mkdir(os.path.join('volumes', f))

def startDatabase(self, db):
def startMysql():
def checkRunning():
Expand All @@ -36,13 +36,13 @@ def checkRunning():
if sp.stdout.strip() == 'healthy':
return
time.sleep(1)

raise Exception('Starting of MySQL container failed.')

l.logger.printDebug('Starting MySQL database container')
p.pr.run(['docker-compose', 'up', '-d', 'mysql']).check_returncode()
p.pr.run(['docker', 'compose', 'up', '-d', 'mysql']).check_returncode()
checkRunning()

def startPostgresql():
def checkRunning(pgCaller):
for i in range(0,20):
Expand All @@ -51,10 +51,10 @@ def checkRunning(pgCaller):
return
time.sleep(1)
raise Exception('Starting of PostgreSQL failed.')

l.logger.printDebug('Starting PostgreSQL container')
p.pr.run(['docker-compose', 'up', '-d', 'postgres']).check_returncode()
p.pr.run(['docker', 'compose', 'up', '-d', 'postgres']).check_returncode()

pgCaller = test_runner.db.PostgresConnector()
checkRunning(pgCaller)

Expand All @@ -74,7 +74,7 @@ def startSqlite():
def stopDatabase(self, db):
def stopContainer(name):
l.logger.printTask('Stopping container {name}'.format(name=name))
p.pr.run(['docker-compose', 'stop', name]).check_returncode()
p.pr.run(['docker', 'compose', 'stop', name]).check_returncode()

def handleMySql():
stopContainer('mysql')
Expand All @@ -91,10 +91,10 @@ def handleSqlite():
'sqlite': handleSqlite,
}
mapping[db]()

def stopContainers(self):
l.logger.printTask('Stopping remaining containers')
p.pr.run(['docker-compose', 'stop']).check_returncode()
p.pr.run(['docker', 'compose', 'stop']).check_returncode()

def __dropEnvironment(self, db):
def cleanMysql():
Expand All @@ -106,7 +106,7 @@ def cleanMysql():
sqls = ['DROP TABLE {t};'.format(t=t) for t in tables if t != '']
sql = "\n".join(sqls)
caller.callSQL(sql, capture_output=True).check_returncode()

def cleanPostgres():
caller = test_runner.db.PostgresConnector()
sql = '''DROP SCHEMA public CASCADE;
Expand All @@ -115,10 +115,10 @@ def cleanPostgres():
GRANT ALL ON SCHEMA public TO PUBLIC;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO PUBLIC;'''.format(user=caller.getUser())
caller.callSQL(sql, capture_output=True).check_returncode()

def cleanSqlite():
pass

l.logger.printTask('Dropping the environment')

mappingDb = {
Expand All @@ -130,7 +130,7 @@ def cleanSqlite():
l.logger.printTask('Cleaning the database')
mappingDb[db]()
l.logger.printTask('Database has been reset.')

l.logger.printTask('Cleaning out the NC files.')
p.pr.run('rm -rf volumes/{data,nextcloud}/{*,.??*}', shell=True).check_returncode()
l.logger.printTask('Removal of files done.')
Expand All @@ -141,12 +141,12 @@ def cleanSqlite():
def __runPhpScript(self, filename):
with open(filename, 'r') as fp:
data = fp.read()

return p.pr.run(
['docker-compose', 'run', '--rm', '-T', 'php'], input=data,
['docker', 'compose', 'run', '--rm', '-T', 'php'], input=data,
capture_output=True, text=True
)

def __setupServer(self, db, branch):
l.logger.printTask('Starting installing the server')

Expand All @@ -164,18 +164,18 @@ def __setupServer(self, db, branch):
'git', 'submodule', 'update', '--init', '--depth', '1'
], cwd='volumes/nextcloud').check_returncode()
timer.toc('Checkout of git repos')

l.logger.printTask('Create folder structure for correct permissions')
p.pr.run(['mkdir', '-p', 'custom_apps/cookbook', 'data'], cwd='volumes/nextcloud').check_returncode()

def installGeneric(options):
cmd = [
'docker-compose', 'run', '--rm', '-T', 'occ', 'maintenance:install',
'docker', 'compose', 'run', '--rm', '-T', 'occ', 'maintenance:install',
'--admin-user', 'admin', '--admin-pass', 'admin'
] + options

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

def installWithMysql():
caller = test_runner.db.MysqlConnector()
installGeneric([
Expand All @@ -190,7 +190,7 @@ def installWithPgSQL():
])
def installWithSQLite():
installGeneric(['--database', 'sqlite'])

mappingDb = {
'mysql': installWithMysql,
'pgsql': installWithPgSQL,
Expand Down Expand Up @@ -218,7 +218,7 @@ def setupApp(self, installUntested):
if installUntested:
l.logger.printTask('Adding exception for app to be allowed as untested app')
self.__runPhpScript('scripts/enable_app_install_script.php')

l.logger.printTask('Synchronize the app code base to volume')
excludes = ['/.git/', '/.github/actions/run-tests/volumes/', '/node_modules/']
excludePairs = [['--exclude', x] for x in excludes]
Expand All @@ -232,7 +232,7 @@ def setupApp(self, installUntested):

l.logger.printTask('Activate the cookbook app in the server')
p.pr.run(
['docker-compose', 'run', '--rm', '-T', 'occ', 'app:enable', 'cookbook']
['docker', 'compose', 'run', '--rm', '-T', 'occ', 'app:enable', 'cookbook']
).check_returncode()

l.logger.printTask('Installation of cookbook finished')
Expand All @@ -245,19 +245,19 @@ def prepareBasicEnvironment(self, db, branch):

l.logger.startGroup('Preparing server environment')
totalTimer.tic()

timer.tic()
self.startDatabase(db)
timer.toc('Started database')

timer.tic()
self.__dropEnvironment(db)
timer.toc('Environment cleaned')

timer.tic()
self.__setupServer(db, branch)
timer.toc('Server installed')

totalTimer.toc('Environment preparation')
l.logger.endGroup()

Expand All @@ -267,15 +267,15 @@ def __finishEnvironment(self, http_server):
timer.tic()

l.logger.printTask('Start fpm and www containers')
p.pr.run(['docker-compose', 'up', '-d', 'www', 'fpm']).check_returncode()
p.pr.run(['docker', 'compose', 'up', '-d', 'www', 'fpm']).check_returncode()

httpMapper = {
'apache': 'apache',
'nginx': 'nginx',
}
l.logger.printTask('Start HTTP server')
p.pr.run(
['docker-compose', 'up', '-d', httpMapper[http_server]]
['docker', 'compose', 'up', '-d', httpMapper[http_server]]
).check_returncode()

l.logger.printTask('Started all containers')
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/contributing/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ There are multiple methods to set up the Nextcloud development environment.
Follow the instructions in this repository, noting that the default username/password are admin/admin.<br>
Please pay attention to the warning from that repository:
> :warning: DO NOT USE THIS IN PRODUCTION Various settings in this setup are considered insecure and default passwords and secrets are used all over the place
1. There is also [this repository](https://github.com/christianlupus/nextcloud-docker-debug) that contains a configuration using docker-compose as well. This setup is tailored down to allow easy debugging and profiling of apps. The repository has an extensive documentation attached in form of a README file on how to setup.<br>
1. There is also [this repository](https://github.com/christianlupus/nextcloud-docker-debug) that contains a configuration using Docker Compose as well. This setup is tailored down to allow easy debugging and profiling of apps. The repository has an extensive documentation attached in form of a README file on how to setup.<br>
**This repository is only for development purposes. Do not use for productive usage!**

## Add Cookbook to your Nextcloud environment's apps directory
Expand All @@ -39,7 +39,7 @@ The easiest way might be to add a new line in this section after cloning [`nextc
```
You might need to adopt the path specification according to your local setup. Also note that docker-compose needs the correct indentation (spaces and no tabs!) to work well.

Be sure to recreate the containers after modifying `docker-compose.yml` using `docker-compose up -d`.
Be sure to recreate the containers after modifying `docker-compose.yml` using `docker compose up -d`.

## Install PHP dependencies

Expand Down

0 comments on commit 5bf30fa

Please sign in to comment.