diff options
author | Daniel Weipert <code@drogueronin.de> | 2021-07-02 15:51:04 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2021-07-02 15:51:04 +0200 |
commit | eddb042815eef3488e890468bc39507a375d1081 (patch) | |
tree | f3381910dc79e9ba76e5fb022b641e158b063975 /bin |
Initial commit
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/build.php | 48 | ||||
-rwxr-xr-x | bin/run.php | 9 | ||||
-rwxr-xr-x | bin/setup.php | 28 |
3 files changed, 85 insertions, 0 deletions
diff --git a/bin/build.php b/bin/build.php new file mode 100755 index 0000000..07aa584 --- /dev/null +++ b/bin/build.php @@ -0,0 +1,48 @@ +#!/usr/bin/env php + +<?php + +require_once dirname(__DIR__) . '/vendor/autoload.php'; + +use Symfony\Component\Yaml\Yaml; + +$rootDir = dirname(__DIR__); +$buildDir = "$rootDir/build"; +@mkdir($buildDir); + +// get official compose file +$dockerCompose = Yaml::parse(file_get_contents('https://raw.githubusercontent.com/tootsuite/mastodon/main/docker-compose.yml')); + +// set missing POSTGRES_PASSWORD +$dockerCompose['services']['db']['environment'][] = 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD}'; + +// set traefik labels for external services +$dockerCompose['services']['web']['labels'] = [ + 'traefik.enable=true', + 'traefik.docker.network=${TRAEFIK_NETWORK}', + 'traefik.http.services.${COMPOSE_PROJECT_NAME}-web.loadbalancer.server.port=3000', + 'traefik.http.routers.${COMPOSE_PROJECT_NAME}-web.rule=Host(`${DOMAIN}`)', + 'traefik.http.routers.${COMPOSE_PROJECT_NAME}-web.entrypoints=websecure', + 'traefik.http.routers.${COMPOSE_PROJECT_NAME}-web.tls.certresolver=letsencrypt', +]; +$dockerCompose['services']['streaming']['labels'] = [ + 'traefik.enable=true', + 'traefik.docker.network=${TRAEFIK_NETWORK}', + 'traefik.http.services.${COMPOSE_PROJECT_NAME}-streaming.loadbalancer.server.port=4000', + 'traefik.http.routers.${COMPOSE_PROJECT_NAME}-streaming.rule=(Host(`${DOMAIN}`) && PathPrefix(`/api/v1/streaming`))', + 'traefik.http.routers.${COMPOSE_PROJECT_NAME}-streaming.entrypoints=websecure', + 'traefik.http.routers.${COMPOSE_PROJECT_NAME}-streaming.tls.certresolver=letsencrypt', +]; + +// remove build instructions to use pre-built images +unset($dockerCompose['services']['web']['build']); +unset($dockerCompose['services']['streaming']['build']); +unset($dockerCompose['services']['sidekiq']['build']); + +// set external network for use with traefik +$dockerCompose['services']['web']['networks'][] = '${TRAEFIK_NETWORK}'; +$dockerCompose['services']['streaming']['networks'][] = '${TRAEFIK_NETWORK}'; +$dockerCompose['networks']['${TRAEFIK_NETWORK}']['external'] = true; + +// write to build dir +file_put_contents("$buildDir/docker-compose.yml", Yaml::dump($dockerCompose, 99)); diff --git a/bin/run.php b/bin/run.php new file mode 100755 index 0000000..2621c5d --- /dev/null +++ b/bin/run.php @@ -0,0 +1,9 @@ +#!/usr/bin/env php + +<?php + +$rootDir = dirname(__DIR__); +$buildDir = "$rootDir/build"; + +chdir($buildDir); +exec("docker-compose up -d"); diff --git a/bin/setup.php b/bin/setup.php new file mode 100755 index 0000000..ade01c6 --- /dev/null +++ b/bin/setup.php @@ -0,0 +1,28 @@ +#!/usr/bin/env php + +<?php + +$rootDir = dirname(__DIR__); +$buildDir = "$rootDir/build"; + +// check if .env is propery set +if (! file_exists("$buildDir/.env")) { + copy("$rootDir/.env.example", "$buildDir/.env"); + exit('Adjust .env in build directory first.'); +} +else if (strpos(file_get_contents("$buildDir/.env"), 'example.org') !== false) { + exit('Adjust .env in build directory first.'); +} + +// load .env +$dotenv = \Dotenv\Dotenv::createImmutable($buildDir); +$dotenv->load(); + +// change to build dir +chdir($buildDir); + +// create .env.production for mastodon setup +exec("touch $buildDir/.env.production"); + +// run mastodon:setup +exec("docker-compose run --rm -v $buildDir/.env.production:/opt/mastodon/.env.production web bundle exec rake mastodon:setup"); |