From 6d63a94d0a08a2af07214572f9a5bcf15730e0d9 Mon Sep 17 00:00:00 2001 From: Pratik Borole Date: Sun, 11 Feb 2024 16:27:05 +0530 Subject: [PATCH] refactor: better organized docker installation --- .gitignore | 4 ++-- .prettierignore | 2 +- README.md | 10 ++++++++-- .env.example => docker/.env.example | 0 compose.dev.yaml => docker/compose.dev.yaml | 4 +++- .../supabase-selfhost.yaml | 0 {volumes => docker/volumes}/api/kong.yml | 0 {volumes => docker/volumes}/db/init/data.sql | 0 {volumes => docker/volumes}/db/jwt.sql | 0 {volumes => docker/volumes}/db/logs.sql | 0 {volumes => docker/volumes}/db/realtime.sql | 0 {volumes => docker/volumes}/db/roles.sql | 0 {volumes => docker/volumes}/db/webhooks.sql | 0 {volumes => docker/volumes}/functions/hello/index.ts | 0 {volumes => docker/volumes}/functions/main/index.ts | 0 {volumes => docker/volumes}/logs/vector.yml | 0 useful_commands.md | 10 +++++----- 17 files changed, 19 insertions(+), 11 deletions(-) rename .env.example => docker/.env.example (100%) rename compose.dev.yaml => docker/compose.dev.yaml (79%) rename supabase-selfhost.yaml => docker/supabase-selfhost.yaml (100%) rename {volumes => docker/volumes}/api/kong.yml (100%) rename {volumes => docker/volumes}/db/init/data.sql (100%) rename {volumes => docker/volumes}/db/jwt.sql (100%) rename {volumes => docker/volumes}/db/logs.sql (100%) rename {volumes => docker/volumes}/db/realtime.sql (100%) rename {volumes => docker/volumes}/db/roles.sql (100%) rename {volumes => docker/volumes}/db/webhooks.sql (100%) rename {volumes => docker/volumes}/functions/hello/index.ts (100%) rename {volumes => docker/volumes}/functions/main/index.ts (100%) rename {volumes => docker/volumes}/logs/vector.yml (100%) diff --git a/.gitignore b/.gitignore index 4db18ef..1501b8d 100644 --- a/.gitignore +++ b/.gitignore @@ -160,5 +160,5 @@ cython_debug/ #.idea/ # Supabase self-host -volumes/db/data -volumes/storage +docker/volumes/db/data +docker/volumes/storage diff --git a/.prettierignore b/.prettierignore index f083734..f13ecd5 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,2 @@ # required in order for supabase-kong to work -volumes/api/kong.yml +docker/volumes/api/kong.yml diff --git a/README.md b/README.md index d6c9918..9cbd45b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Table of Contents: - [Setting up the project](#setting-up-the-project) - [What you'll need](#what-youll-need) - [Development](#development) + - [Environment variables](#environment-variables) - [Python virtual environment](#python-virtual-environment) - [Installing dependencies](#installing-dependencies) - [Virtual environment sanity check](#virtual-environment-sanity-check) @@ -33,6 +34,10 @@ Table of Contents: ## Development +### Environment variables + +In `/docker`, create a copy of `.env.example` as `.env`. + ### Python virtual environment #### Installing dependencies @@ -77,7 +82,7 @@ pre-commit install --hook-type commit-msg --hook-type pre-push --hook-type pre-c ``` - Run container ```sh - docker run --detach --name backend-dev --publish 8081:8081 backend-dev + docker run --name backend-dev --publish 8081:8081 backend-dev --detach ``` - Open your browser at `http://localhost/8081`. @@ -85,7 +90,8 @@ pre-commit install --hook-type commit-msg --hook-type pre-push --hook-type pre-c - Bring up the services ```sh - docker compose --detach --file compose.dev.yaml up + cd docker + docker compose --file compose.dev.yaml up --detach ``` - Open your browser at - `http://localhost/8081` for app diff --git a/.env.example b/docker/.env.example similarity index 100% rename from .env.example rename to docker/.env.example diff --git a/compose.dev.yaml b/docker/compose.dev.yaml similarity index 79% rename from compose.dev.yaml rename to docker/compose.dev.yaml index 2fdb177..fe2995a 100644 --- a/compose.dev.yaml +++ b/docker/compose.dev.yaml @@ -6,7 +6,9 @@ services: app: container_name: backend-dev build: - context: . + context: .. dockerfile: Dockerfile.dev ports: - "8081:8081" + env_file: + - .env diff --git a/supabase-selfhost.yaml b/docker/supabase-selfhost.yaml similarity index 100% rename from supabase-selfhost.yaml rename to docker/supabase-selfhost.yaml diff --git a/volumes/api/kong.yml b/docker/volumes/api/kong.yml similarity index 100% rename from volumes/api/kong.yml rename to docker/volumes/api/kong.yml diff --git a/volumes/db/init/data.sql b/docker/volumes/db/init/data.sql similarity index 100% rename from volumes/db/init/data.sql rename to docker/volumes/db/init/data.sql diff --git a/volumes/db/jwt.sql b/docker/volumes/db/jwt.sql similarity index 100% rename from volumes/db/jwt.sql rename to docker/volumes/db/jwt.sql diff --git a/volumes/db/logs.sql b/docker/volumes/db/logs.sql similarity index 100% rename from volumes/db/logs.sql rename to docker/volumes/db/logs.sql diff --git a/volumes/db/realtime.sql b/docker/volumes/db/realtime.sql similarity index 100% rename from volumes/db/realtime.sql rename to docker/volumes/db/realtime.sql diff --git a/volumes/db/roles.sql b/docker/volumes/db/roles.sql similarity index 100% rename from volumes/db/roles.sql rename to docker/volumes/db/roles.sql diff --git a/volumes/db/webhooks.sql b/docker/volumes/db/webhooks.sql similarity index 100% rename from volumes/db/webhooks.sql rename to docker/volumes/db/webhooks.sql diff --git a/volumes/functions/hello/index.ts b/docker/volumes/functions/hello/index.ts similarity index 100% rename from volumes/functions/hello/index.ts rename to docker/volumes/functions/hello/index.ts diff --git a/volumes/functions/main/index.ts b/docker/volumes/functions/main/index.ts similarity index 100% rename from volumes/functions/main/index.ts rename to docker/volumes/functions/main/index.ts diff --git a/volumes/logs/vector.yml b/docker/volumes/logs/vector.yml similarity index 100% rename from volumes/logs/vector.yml rename to docker/volumes/logs/vector.yml diff --git a/useful_commands.md b/useful_commands.md index 158e69b..a9dccc3 100644 --- a/useful_commands.md +++ b/useful_commands.md @@ -75,9 +75,9 @@ docker build --file Dockerfile.prod --tag backend-prod . #### Start the containers ```sh -docker run --detach --name backend-dev --publish 8081:8081 backend-dev -docker run --detach --name backend-staging --publish 80:80 backend-staging -docker run --detach --name backend-prod --publish 80:80 backend-prod +docker run --name backend-dev --publish 8081:8081 backend-dev --detach +docker run --name backend-staging --publish 80:80 backend-staging --detach +docker run --name backend-prod --publish 80:80 backend-prod --detach ``` #### Stop the containers @@ -113,12 +113,12 @@ docker compose --file compose.dev.yaml build #### Bring up the services ```sh -docker compose --detach --file compose.dev.yaml up +docker compose --file compose.dev.yaml up --detach ``` #### Build and bring up the services ```sh -docker compose --detach --file compose.dev.yaml up --build +docker compose --file compose.dev.yaml up --build --detach ```