Repository navigation
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 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 f5c6d88
fix: read every compose setting from .env only
voidash 1eefd7e
chore: use the Dokploy-managed Postgres in production
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
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,65 @@ | ||
| # Production stack for Dokploy (https://docs.dokploy.com/docs/core/docker-compose). | ||
| # | ||
| # Database: a Dokploy-managed Postgres service in the same project, which gets | ||
| # Dokploy's database backups. Set DATABASE_URL to that service's Internal | ||
| # Connection URL; the app and migrate reach it over dokploy-network. | ||
| # | ||
| # Settings: Dokploy writes the Environment tab to `.env` next to this file but | ||
| # does not inject it, so both services load it with `env_file`. Every setting is | ||
| # listed in apps/api/.env.example; Compose refuses to start without | ||
| # DATABASE_URL or AUTH_URL. | ||
| # | ||
| # Routing: add the domain in Dokploy's Domains tab for service `app`, port 3000. | ||
| # Nothing is published on the host. | ||
| # | ||
| # Data: avatars live in a named volume, so Dokploy's volume backups can include | ||
| # it. Do not bind mount paths from the repository; Dokploy clears it on every | ||
| # deployment. | ||
|
|
||
| x-database-url: &database-url ${DATABASE_URL:?Set DATABASE_URL to the Dokploy Postgres service's Internal Connection URL} | ||
|
|
||
| services: | ||
| # 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 | ||
| networks: | ||
| - dokploy-network | ||
|
|
||
| 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: | ||
| - dokploy-network | ||
| depends_on: | ||
| migrate: | ||
| condition: service_completed_successfully | ||
|
|
||
| networks: | ||
| dokploy-network: | ||
| external: true | ||
|
|
||
| volumes: | ||
| 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.