diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ef7e9ad2..508fc4940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - platform: [macos-latest, ubuntu-latest] + platform: [ubuntu-latest] node: ['12'] runs-on: ${{ matrix.platform }} diff --git a/src/cli.ts b/src/cli.ts index 8cb0d1492..236f6cc36 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -2,4 +2,9 @@ import { build } from 'gluegun' +process.removeAllListeners('unhandledRejection') +process.on('unhandledRejection', () => { + process.exit(1) +}) + build('supabase').src(__dirname).create().run() diff --git a/src/commands/eject.ts b/src/commands/eject.ts index e57b448dc..c58a0cd60 100644 --- a/src/commands/eject.ts +++ b/src/commands/eject.ts @@ -58,7 +58,10 @@ export default { }, }) ) - ) + ).catch(() => { + spinner.fail('Error writing Docker setup files.') + process.exit(1) + }) spinner.succeed('Supabase Docker ejected.') }, diff --git a/src/commands/init.ts b/src/commands/init.ts index 9ca6d90cd..47959f014 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -13,12 +13,19 @@ export default { spin, }, prompt: { ask }, + system: { run, which }, }: GluegunToolbox) => { if (exists('.supabase')) { error(`Project already initialized. Remove ${highlight('.supabase')} to reinitialize.`) process.exit(1) } + const dockerCompose = which('docker-compose') + if (!dockerCompose) { + error(`Cannot find ${highlight('docker-compose')} executable in PATH.`) + process.exit(1) + } + // Add .supabase to .gitignore const gitignore = read('.gitignore') if (gitignore) { @@ -72,7 +79,17 @@ export default { }, }) ) - ) + ).catch(() => { + spinner.fail('Error writing Docker setup files.') + process.exit(1) + }) + + await run( + 'docker-compose --file .supabase/docker/docker-compose.yml --project-name supabase build --no-cache --parallel --quiet' + ).catch(() => { + spinner.fail('Error running docker-compose.') + process.exit(1) + }) spinner.succeed('Project initialized.') fancy(`Supabase URL: ${highlight(`http://localhost:${kongPort}`)} diff --git a/src/commands/start.ts b/src/commands/start.ts index bf0d3830a..486274712 100644 --- a/src/commands/start.ts +++ b/src/commands/start.ts @@ -3,23 +3,37 @@ import { GluegunToolbox } from 'gluegun' export default { name: 'start', run: async ({ + filesystem: { exists }, print: { colors: { highlight }, + error, spin, }, system: { run, which }, }: GluegunToolbox) => { - const spinner = spin('Starting local Supabase...') + if (!exists('.supabase')) { + error( + `Cannot find ${highlight( + '.supabase' + )} in the current directory. Perhaps you meant to run ${highlight('supabase init')} first?` + ) + process.exit(1) + } const dockerCompose = which('docker-compose') if (!dockerCompose) { - spinner.fail(`Cannot find ${highlight('docker-compose')} executable in PATH.`) + error(`Cannot find ${highlight('docker-compose')} executable in PATH.`) process.exit(1) } + const spinner = spin('Starting local Supabase...') + await run( 'docker-compose --file .supabase/docker/docker-compose.yml --project-name supabase up --detach' - ) + ).catch(() => { + spinner.fail('Error running docker-compose.') + process.exit(1) + }) spinner.succeed('Started local Supabase.') }, diff --git a/src/commands/stop.ts b/src/commands/stop.ts index f7e108ced..93648a61d 100644 --- a/src/commands/stop.ts +++ b/src/commands/stop.ts @@ -3,21 +3,37 @@ import { GluegunToolbox } from 'gluegun' export default { name: 'stop', run: async ({ + filesystem: { exists }, print: { colors: { highlight }, + error, spin, }, system: { run, which }, }: GluegunToolbox) => { - const spinner = spin('Stopping local Supabase...') + if (!exists('.supabase')) { + error( + `Cannot find ${highlight( + '.supabase' + )} in the current directory. Perhaps you meant to run ${highlight('supabase init')} first?` + ) + process.exit(1) + } const dockerCompose = which('docker-compose') if (!dockerCompose) { - spinner.fail(`Cannot find ${highlight('docker-compose')} executable in PATH.`) + error(`Cannot find ${highlight('docker-compose')} executable in PATH.`) process.exit(1) } - await run('docker-compose --file .supabase/docker/docker-compose.yml --project-name supabase down') + const spinner = spin('Stopping local Supabase...') + + await run( + 'docker-compose --file .supabase/docker/docker-compose.yml --project-name supabase down' + ).catch(() => { + spinner.fail('Error running docker-compose.') + process.exit(1) + }) spinner.succeed('Stopped local Supabase.') }, diff --git a/src/templates/init/README.md b/src/templates/init/README.md index e2defdf4d..4792b382e 100644 --- a/src/templates/init/README.md +++ b/src/templates/init/README.md @@ -1 +1,12 @@ -Supabase instructions. \ No newline at end of file +> Why do I have a directory named ".supabase" in my project? + +The ".supabase" directory is created by the Supabase CLI. + +> What does the "docker" directory contain? + +It contains the Docker Compose file and build files for running Supabase locally. + +> Should I commit the ".supabase" directory? + +No, you should not share the ".supabase" directory with anyone. +Upon creation, it will be automatically added to your ".gitignore" file. diff --git a/src/templates/init/docker/postgres/auth-schema.sql b/src/templates/init/docker/postgres/auth-schema.sql index 9b1ae724c..8b13436e5 100644 --- a/src/templates/init/docker/postgres/auth-schema.sql +++ b/src/templates/init/docker/postgres/auth-schema.sql @@ -88,3 +88,4 @@ $$ language sql stable; GRANT ALL PRIVILEGES ON SCHEMA auth TO postgres; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA auth TO postgres; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA auth TO postgres; +ALTER ROLE postgres SET search_path = "$user", public, auth;