()
| 15 | } |
| 16 | |
| 17 | async function main() { |
| 18 | // Check that docker/.env exists |
| 19 | try { |
| 20 | await fsp.access(DOCKER_DOTENV_PATH, fs.constants.F_OK); |
| 21 | } catch (e) { |
| 22 | // Does not exist, write it |
| 23 | const password = safeRandomString(30); |
| 24 | const data = ` |
| 25 | # We'd like scripts ran through Docker to pretend they're in a normal |
| 26 | # interactive terminal. |
| 27 | FORCE_COLOR=2 |
| 28 | |
| 29 | # \`pg_dump\` is run from inside container, which doesn't have pg tools installed |
| 30 | # so it needs a way to still run it. \`docker-compose run\` would start an |
| 31 | # instance inside the current running container which doesn't work with volume |
| 32 | # mappings, so we must use \`docker-compose exec\`. \`-T\` is needed because our |
| 33 | # \`.gmrc\` checks for interactive TTY. |
| 34 | PG_DUMP=docker-compose exec -T db pg_dump |
| 35 | |
| 36 | # Drops tables without asking in \`yarn setup\`. Reasoning: 1) docker-compose is |
| 37 | # not tty, 2) it's a dev env anyway. |
| 38 | CONFIRM_DROP=y |
| 39 | |
| 40 | # POSTGRES_PASSWORD is the superuser password for PostgreSQL, it's required to |
| 41 | # initialize the Postgres docker volume. |
| 42 | POSTGRES_PASSWORD=${password} |
| 43 | |
| 44 | # We're accessing Postgres via Docker, so we must use the db host and the |
| 45 | # relevant password. |
| 46 | DATABASE_HOST=db |
| 47 | ROOT_DATABASE_URL=postgres://postgres:${password}@db/postgres |
| 48 | `; |
| 49 | await fsp.writeFile(DOCKER_DOTENV_PATH, data); |
| 50 | } |
| 51 | |
| 52 | // The `docker-compose` project name defaults to the directory name containing |
| 53 | // `docker-compose.yml`, which is the root folder of our project. Let's call |
| 54 | // that 'ROOT'. We're in ROOT/docker/scripts and we want to get the name of |
| 55 | // ROOT: |
| 56 | const projectName = basename(dirname(dirname(resolve(__dirname)))); |
| 57 | |
| 58 | // On Windows we must run 'yarn.cmd' rather than 'yarn' |
| 59 | const yarnCmd = platform === "win32" ? "yarn.cmd" : "yarn"; |
| 60 | |
| 61 | runSync(yarnCmd, ["down"]); |
| 62 | runSync(yarnCmd, ["db:up"]); |
| 63 | |
| 64 | // Fix permissions |
| 65 | runSync(yarnCmd, [ |
| 66 | "compose", |
| 67 | "run", |
| 68 | "server", |
| 69 | "sudo", |
| 70 | "bash", |
| 71 | "-c", |
| 72 | "chmod o+rwx /var/run/docker.sock && chown -R node /work/node_modules /work/@app/*/node_modules", |
| 73 | ]); |
| 74 |
no test coverage detected