@@ -4,7 +4,7 @@ const platform = require("os").platform();
4
4
const { safeRandomString } = require ( "../../scripts/lib/random" ) ;
5
5
const fsp = require ( "fs" ) . promises ;
6
6
7
- const DOTENV_PATH = `${ __dirname } /.. /../.env` ;
7
+ const DOCKER_DOTENV_PATH = `${ __dirname } /../.env` ;
8
8
9
9
if ( platform !== "win32" && ! process . env . UID ) {
10
10
console . error (
@@ -28,27 +28,38 @@ function spawnSync(command, args, options = {}) {
28
28
}
29
29
30
30
async function main ( ) {
31
- // POSTGRES_PASSWORD must be set for the Docker Postgres image to boot
32
- let data ;
31
+ // Check that docker/.env exists
33
32
try {
34
- data = await fsp . readFile ( DOTENV_PATH , "utf8" ) ;
33
+ await fsp . access ( DOCKER_DOTENV_PATH , fs . constants . F_OK ) ;
35
34
} catch ( e ) {
36
- data = "" ;
37
- }
38
- if ( ! data . includes ( "POSTGRES_PASSWORD=" ) ) {
39
- // We cannot use `dotenv` here because we exist outside of Docker, and we
40
- // don't have the module installed yet.
35
+ // Does not exist, write it
41
36
const password = safeRandomString ( 30 ) ;
42
- data += `
37
+ const data = `
38
+ # We'd like scripts ran through Docker to pretend they're in a normal
39
+ # interactive terminal.
40
+ FORCE_COLOR=2
41
+
42
+ # \`pg_dump\` is run from inside container, which doesn't have pg tools installed
43
+ # so it needs a way to still run it. \`docker-compose run\` would start an
44
+ # instance inside the current running container which doesn't work with volume
45
+ # mappings, so we must use \`docker-compose exec\`. \`-T\` is needed because our
46
+ # \`.gmrc\` checks for interactive TTY.
47
+ PG_DUMP=docker-compose exec -T db pg_dump
48
+
49
+ # Drops tables without asking in \`yarn setup\`. Reasoning: 1) docker-compose is
50
+ # not tty, 2) it's a dev env anyway.
51
+ CONFIRM_DROP=y
52
+
43
53
# POSTGRES_PASSWORD is the superuser password for PostgreSQL, it's required to
44
54
# initialize the Postgres docker volume.
45
55
POSTGRES_PASSWORD=${ password }
46
56
47
- # We're accessing Postgres via Docker:
57
+ # We're accessing Postgres via Docker, so we must use the db host and the
58
+ # relevant password.
48
59
DATABASE_HOST=db
49
60
ROOT_DATABASE_URL=postgres://postgres:${ password } @db/template1
50
61
` ;
51
- await fsp . writeFile ( DOTENV_PATH , data ) ;
62
+ await fsp . writeFile ( DOCKER_DOTENV_PATH , data ) ;
52
63
}
53
64
54
65
// The `docker-compose` project name defaults to the directory name containing
0 commit comments