-
Notifications
You must be signed in to change notification settings - Fork 2
fix: deploy on Dokploy from .env settings with one lean image #53
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
voidash
wants to merge
5
commits into
main
Choose a base branch
from
chore/lean-runtime-image
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.
+242
−36
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22d7c6f
chore: make compose ports configurable
voidash e0e29d3
chore: ship one lean runtime image
voidash b732659
fix: take compose settings from .env as well as .env.local
voidash ddf54a7
chore: add a production compose file for Dokploy
voidash 78a7666
docs: say which compose settings are read from .env only
voidash 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Settings Docker Compose itself uses. Copy to `.env` next to docker-compose.yml. | ||
| # Compose reads these only from this `.env` or the shell, never from | ||
| # apps/api/.env.local. App settings (AUTH_*, GITHUB_*, ...) are listed in | ||
| # apps/api/.env.example; they can go in apps/api/.env.local or in this `.env`. | ||
|
|
||
| # Postgres credentials. Postgres only reads them when it first creates the | ||
| # database. Compose builds the app's DATABASE_URL from them; if you change them | ||
| # for local development, change DATABASE_URL in apps/api/.env.local to match. | ||
| POSTGRES_USER=refined | ||
| POSTGRES_PASSWORD=refined | ||
| POSTGRES_DB=refined | ||
|
|
||
| # Host ports for docker-compose.yml, if 5432 or 3000 are already taken. | ||
| DB_PORT=5432 | ||
| API_PORT=3000 |
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
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
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,31 @@ | ||
| import { config as loadEnv } from "dotenv"; | ||
| import { drizzle } from "drizzle-orm/node-postgres"; | ||
| import { migrate } from "drizzle-orm/node-postgres/migrator"; | ||
| import { Pool } from "pg"; | ||
|
|
||
| loadEnv({ path: ".env.local" }); | ||
| loadEnv(); | ||
|
|
||
| // Applies the SQL migrations in ./drizzle, relative to the working directory: | ||
| // apps/api locally, and the app directory in the production image. Drizzle | ||
| // records applied migrations, so rerunning is safe. | ||
| async function main(): Promise<void> { | ||
| const connectionString = process.env.DATABASE_URL; | ||
| if (connectionString === undefined || connectionString.length === 0) { | ||
| throw new Error("DATABASE_URL is required"); | ||
| } | ||
| const pool = new Pool({ connectionString, max: 1 }); | ||
| try { | ||
| await migrate(drizzle(pool), { migrationsFolder: "drizzle" }); | ||
| } finally { | ||
| await pool.end(); | ||
| } | ||
| console.log("Migrations applied."); | ||
| } | ||
|
|
||
| main() | ||
| .then(() => process.exit(0)) | ||
| .catch((error) => { | ||
| console.error("Migration failed:", error); | ||
| process.exit(1); | ||
| }); |
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
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,78 @@ | ||
| # Production stack for Dokploy (https://docs.dokploy.com/docs/core/docker-compose). | ||
| # | ||
| # Settings: Dokploy writes the Environment tab to `.env` next to this file but | ||
| # does not inject it, so the app and migrate services load it with `env_file`. | ||
| # Every setting is listed in apps/api/.env.example; production also needs | ||
| # POSTGRES_PASSWORD and AUTH_URL, and Compose refuses to start without them. | ||
| # | ||
| # Routing: add the domain in Dokploy's Domains tab for service `app`, port 3000. | ||
| # Nothing is published on the host; Postgres is reachable only inside the stack. | ||
| # | ||
| # Data: named volumes, so Dokploy's volume backups can include them. Do not bind | ||
| # mount paths from the repository; Dokploy clears it on every deployment. | ||
|
|
||
| x-database-url: &database-url postgres://${POSTGRES_USER:-devnepal}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD (URL-safe, e.g. openssl rand -hex 24)}@db:5432/${POSTGRES_DB:-devnepal} | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres:17-alpine@sha256:b0f9560a2de083e2cc7382e75f808c7381a32852a7ec49117deedb300e552b24 | ||
| restart: always | ||
| environment: | ||
| POSTGRES_USER: ${POSTGRES_USER:-devnepal} | ||
| POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD (URL-safe, e.g. openssl rand -hex 24)} | ||
| POSTGRES_DB: ${POSTGRES_DB:-devnepal} | ||
| volumes: | ||
| - pgdata:/var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\""] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 10 | ||
|
|
||
| # Applies migrations, then exits; the app starts only after it succeeds. | ||
| migrate: | ||
| build: | ||
| context: . | ||
| dockerfile: apps/api/Dockerfile | ||
| image: devnepal:production | ||
| command: ["node", "scripts/migrate.js"] | ||
| restart: "no" | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| DATABASE_URL: *database-url | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
|
|
||
| app: | ||
| build: | ||
| context: . | ||
| dockerfile: apps/api/Dockerfile | ||
| image: devnepal:production | ||
| restart: always | ||
| env_file: | ||
| - .env | ||
| environment: | ||
| DATABASE_URL: *database-url | ||
| STORAGE_DIR: /app/storage | ||
| # The GitHub callback URL is built from this; without it sign-in breaks. | ||
| AUTH_URL: ${AUTH_URL:?Set AUTH_URL to the public origin, e.g. https://devnepal.gov.np} | ||
| expose: | ||
| - "3000" | ||
| volumes: | ||
| - avatars:/app/storage | ||
| networks: | ||
| - default | ||
| - dokploy-network | ||
| depends_on: | ||
| migrate: | ||
| condition: service_completed_successfully | ||
|
|
||
| networks: | ||
| dokploy-network: | ||
| external: true | ||
|
|
||
| volumes: | ||
| pgdata: | ||
| avatars: |
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.