-
Notifications
You must be signed in to change notification settings - Fork 782
Prepare self host mode #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
djhi
wants to merge
7
commits into
main
Choose a base branch
from
docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d449692
Prepare self host mode
djhi 46f0139
Initialize documentation for self hosting
c647dd3
Remove production files
3215885
Merge branch 'main' into docker
5fdc08f
Improve documentation
cb7af98
Mention that any change in env files requires to restart the docker c…
e009c82
Merge branch 'main' into docker
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,6 @@ dist/ | |
|
|
||
| # Shadcn Registry | ||
| public/r/ | ||
| docker/* | ||
| !docker/docker-compose-atomic.yml | ||
| !docker/Dockerfile | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- | ||
| title: Self Hosting | ||
| description: This document explains how to host Atomic CRM and Supabase yourself. | ||
| --- | ||
|
|
||
| In order to facilitate self-hosting Atomic CRM with Supabase, we provide a few Make commands. | ||
|
|
||
| First, initialize the docker setup by running: | ||
|
|
||
| ```sh | ||
| make docker-init | ||
| ``` | ||
|
|
||
| This command will ask you to allow writing an `./docker/.env` file for Supabase. When it's done, feel free to customize this file. Refer to the [Supabase documentation](https://supabase.com/docs/guides/self-hosting/docker#configuring-and-securing-supabase) for details about each variable. | ||
|
|
||
| ## Development | ||
|
|
||
| Once this is done, you can run the following command to start the development environment: | ||
|
|
||
| ```sh | ||
| make docker-start | ||
| ``` | ||
|
|
||
| To setup the database and edge functions required by Atomic CRM migrations, run the following command, replacing the `[POOLER_TENANT_ID]` and `[POSTGRES_PASSWORD]` placeholders with the values from the Supabase `./docker/.env` file: | ||
|
|
||
| ```sh | ||
| PGSSLMODE=disable npx supabase db push --db-url "postgres://postgres.[POOLER_TENANT_ID]:[POSTGRES_PASSWORD]@[your-domain]:5432/postgres" | ||
| ``` | ||
|
|
||
| `PGSSLMODE=disable` is required to access the local postgres instance. | ||
|
|
||
| Finally, update the frontend application `.env` file to target the local supabase instance: | ||
|
|
||
| ```sh | ||
| FRONTEND_HTTP_HOST=true | ||
| FRONTEND_HTTP_PORT=3000 | ||
| FRONTEND_HMR_PORT=3001 | ||
| VITE_SUPABASE_URL=http://localhost:8000 | ||
| VITE_SUPABASE_ANON_KEY=Put the ANON_KEY value from ./docker/.env | ||
| SUPABASE_SERVICE_ROLE_KEY=Put the SERVICE_ROLE_KEY value from ./docker/.env | ||
| ``` | ||
|
|
||
| Replace the port of the `VITE_SUPABASE_URL` variable with the one you choose for `SUPABASE_PUBLIC_URL` in the Supabase `./docker/.env` file. | ||
|
|
||
| If you edit any value in either the frontend `.env` or `./docker/.env` files, you'll have to restart the docker containers. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| FROM node:24-alpine | ||
| ARG FRONTEND_HTTP_HOST=5173 | ||
| ARG FRONTEND_HMR_PORT=5174 | ||
| USER node | ||
| WORKDIR /app | ||
| COPY ../package.json ../package-lock.json ./ | ||
| RUN npm install --no-save | ||
| EXPOSE ${FRONTEND_HTTP_HOST} | ||
| EXPOSE ${FRONTEND_HMR_PORT} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: AtomicCRM | ||
|
|
||
| services: | ||
| frontend: | ||
| image: atomic-crm-frontend | ||
| build: | ||
| context: .. | ||
| dockerfile: ./docker/Dockerfile | ||
| command: npm run dev | ||
| environment: | ||
| NODE_ENV: development | ||
| FRONTEND_HTTP_HOST: ${FRONTEND_HTTP_HOST} | ||
| FRONTEND_HTTP_PORT: ${FRONTEND_HTTP_PORT} | ||
| FRONTEND_HMR_PORT: ${FRONTEND_HMR_PORT} | ||
| VITE_SUPABASE_URL: ${VITE_SUPABASE_URL} | ||
| VITE_SUPABASE_ANON_KEY: ${VITE_SUPABASE_ANON_KEY} | ||
| VITE_IS_DEMO: ${VITE_IS_DEMO} | ||
| VITE_INBOUND_EMAIL: ${VITE_INBOUND_EMAIL} | ||
| SKIP_PREFLIGHT_CHECK: ${SKIP_PREFLIGHT_CHECK} | ||
| ports: | ||
| - ${FRONTEND_HTTP_PORT}:${FRONTEND_HTTP_PORT}/tcp | ||
| - ${FRONTEND_HMR_PORT}:${FRONTEND_HMR_PORT}/tcp | ||
| volumes: | ||
| - ../index.html:/app/index.html | ||
| - ../demo:/app/demo | ||
| - ../src:/app/src | ||
| - ../public:/app/public | ||
| - ../vite.config.ts:/app/vite.config.ts | ||
| - ../vite.demo.config.ts:/app/vite.demo.config.ts | ||
| - ../tsconfig.json:/app/tsconfig.json | ||
| - ../tsconfig.app.json:/app/tsconfig.app.json | ||
| - ../tsconfig.node.json:/app/tsconfig.node.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'supabase-clone-temp') | ||
| git clone --depth 1 https://github.com/supabase/supabase $tmpdir | ||
| mkdir -p ./docker | ||
| cp -rf $tmpdir/docker/* ./docker | ||
| cp $tmpdir/docker/.env.example ./docker/.env | ||
| echo "You can safely answer yes to the next script step as it will only modify the .env file we just created for supabase" | ||
| cd ./docker && sh ./utils/generate-keys.sh | ||
| rm -rf $tmpdir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,76 @@ | ||
| import path from "node:path"; | ||
| import { defineConfig } from "vite"; | ||
| import { defineConfig, loadEnv } from "vite"; | ||
| import tailwindcss from "@tailwindcss/vite"; | ||
| import react from "@vitejs/plugin-react"; | ||
| import { visualizer } from "rollup-plugin-visualizer"; | ||
| import createHtmlPlugin from "vite-plugin-simple-html"; | ||
|
|
||
| // https://vitejs.dev/config/ | ||
| export default defineConfig({ | ||
| plugins: [ | ||
| react(), | ||
| tailwindcss(), | ||
| visualizer({ | ||
| open: process.env.NODE_ENV !== "CI", | ||
| filename: "./dist/stats.html", | ||
| }), | ||
| createHtmlPlugin({ | ||
| minify: true, | ||
| inject: { | ||
| data: { | ||
| mainScript: `src/main.tsx`, | ||
| export default defineConfig(({ mode }) => { | ||
| const env = loadEnv(mode, process.cwd(), ""); | ||
| return { | ||
| plugins: [ | ||
| react(), | ||
| tailwindcss(), | ||
| visualizer({ | ||
| open: process.env.NODE_ENV !== "CI", | ||
| filename: "./dist/stats.html", | ||
| }), | ||
| createHtmlPlugin({ | ||
| minify: true, | ||
| inject: { | ||
| data: { | ||
| mainScript: `src/main.tsx`, | ||
| }, | ||
| }, | ||
| }), | ||
| ], | ||
| define: | ||
| env.NODE_ENV === "production" && env.VITE_SUPABASE_URL | ||
| ? { | ||
| "import.meta.env.VITE_IS_DEMO": JSON.stringify(env.VITE_IS_DEMO), | ||
| "import.meta.env.VITE_SUPABASE_URL": JSON.stringify( | ||
| env.VITE_SUPABASE_URL, | ||
| ), | ||
| "import.meta.env.VITE_SUPABASE_ANON_KEY": JSON.stringify( | ||
| env.VITE_SUPABASE_ANON_KEY, | ||
| ), | ||
| "import.meta.env.VITE_INBOUND_EMAIL": JSON.stringify( | ||
| env.VITE_INBOUND_EMAIL, | ||
| ), | ||
| } | ||
| : undefined, | ||
| base: "./", | ||
| esbuild: { | ||
| keepNames: true, | ||
| }, | ||
| build: { | ||
| sourcemap: true, | ||
| }, | ||
| resolve: { | ||
| preserveSymlinks: true, | ||
| alias: { | ||
| "@": path.resolve(__dirname, "./src"), | ||
| }, | ||
| }), | ||
| ], | ||
| define: | ||
| process.env.NODE_ENV === "production" && process.env.VITE_SUPABASE_URL | ||
| ? { | ||
| "import.meta.env.VITE_IS_DEMO": JSON.stringify( | ||
| process.env.VITE_IS_DEMO, | ||
| ), | ||
| "import.meta.env.VITE_SUPABASE_URL": JSON.stringify( | ||
| process.env.VITE_SUPABASE_URL, | ||
| ), | ||
| "import.meta.env.VITE_SUPABASE_ANON_KEY": JSON.stringify( | ||
| process.env.VITE_SUPABASE_ANON_KEY, | ||
| ), | ||
| "import.meta.env.VITE_INBOUND_EMAIL": JSON.stringify( | ||
| process.env.VITE_INBOUND_EMAIL, | ||
| ), | ||
| } | ||
| : undefined, | ||
| base: "./", | ||
| esbuild: { | ||
| keepNames: true, | ||
| }, | ||
| build: { | ||
| sourcemap: true, | ||
| }, | ||
| resolve: { | ||
| preserveSymlinks: true, | ||
| alias: { | ||
| "@": path.resolve(__dirname, "./src"), | ||
| }, | ||
| }, | ||
| server: { | ||
| host: env.FRONTEND_HTTP_HOST === "true" ? true : env.FRONTEND_HTTP_HOST, | ||
| port: env.FRONTEND_HTTP_PORT | ||
| ? parseInt(env.FRONTEND_HTTP_PORT) | ||
| : undefined, | ||
| strictPort: !!env.FRONTEND_HTTP_PORT, | ||
| origin: `http://0.0.0.0:${env.FRONTEND_HTTP_PORT}`, | ||
| hmr: { | ||
| port: env.FRONTEND_HMR_PORT | ||
| ? parseInt(env.FRONTEND_HMR_PORT) | ||
| : undefined, | ||
| }, | ||
| }, | ||
| preview: { | ||
| host: env.FRONTEND_HTTP_HOST, | ||
| port: env.FRONTEND_HTTP_PORT | ||
| ? parseInt(env.FRONTEND_HTTP_PORT) | ||
| : undefined, | ||
| strictPort: !!env.FRONTEND_HTTP_PORT, | ||
| }, | ||
| }; | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't start everything without setting these params first:
FRONTEND_HTTP_HOST=trueFRONTEND_HTTP_PORT=3000FRONTEND_HMR_PORT=3001make docker-startoutput:docker compose -p atomic-crm --env-file .env.development --env-file ./docker/.env -f ./docker/docker-compose.yml -f ./docker/docker-compose-atomic.yml up
WARN[0000] The "FRONTEND_HMR_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "FRONTEND_HTTP_HOST" variable is not set. Defaulting to a blank string.
WARN[0000] The "FRONTEND_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "FRONTEND_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "FRONTEND_HTTP_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "FRONTEND_HMR_PORT" variable is not set. Defaulting to a blank string.
WARN[0000] The "FRONTEND_HMR_PORT" variable is not set. Defaulting to a blank string.
invalid proto:
make: *** [makefile:102: docker-start] Error 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's explained in the self hosting documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ you are right