Skip to content

Add Docker configuration for local development#80

Open
numbpill3d wants to merge 1 commit intomainfrom
codex/create-dockerfile-with-postgres-setup
Open

Add Docker configuration for local development#80
numbpill3d wants to merge 1 commit intomainfrom
codex/create-dockerfile-with-postgres-setup

Conversation

@numbpill3d
Copy link
Collaborator

@numbpill3d numbpill3d commented Jun 8, 2025

Summary

  • add a Dockerfile for running the Node server
  • add docker-compose setup with Postgres
  • document Docker usage

Testing

  • npm test (fails: Cannot find module and missing Supabase env)

https://chatgpt.com/codex/tasks/task_e_68450dc76f68832f93ce610070f06a70

Summary by Sourcery

Provide Docker-based local development setup with a Dockerfile, Docker Compose configuration for the Node app and Postgres, and update the README with usage instructions.

Build:

  • Add Dockerfile to containerize the Node.js server
  • Add docker-compose.yml to spin up the app alongside a Postgres database

Documentation:

  • Document Docker-based local development steps in the README

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 8, 2025

Reviewer's Guide

Provides Docker-based local development setup by introducing a Dockerfile for containerizing the Node server, a docker-compose configuration to orchestrate the application and Postgres service, and accompanying usage documentation in the README.

Sequence Diagram: docker-compose up Service Initialization

sequenceDiagram
    actor Developer
    participant DockerComposeCLI as "docker-compose CLI"
    participant DockerEngine as "Docker Engine"
    participant AppImageBuilder as "App Image Builder (Dockerfile)"
    participant DBContainer as "DB Container (Postgres)"
    participant AppContainer as "App Container (Node.js)"

    Developer->>DockerComposeCLI: docker-compose up --build
    DockerComposeCLI->>DockerEngine: Read docker-compose.yml
    opt Build app image
        DockerComposeCLI->>DockerEngine: Build 'app' image (via AppImageBuilder)
        DockerEngine->>AppImageBuilder: Execute Dockerfile steps (copy files, npm ci)
        AppImageBuilder-->>DockerEngine: 'app' image built
    end
    DockerComposeCLI->>DockerEngine: Ensure 'postgres:15-alpine' image for 'db'
    DockerEngine-->>DockerComposeCLI: 'postgres' image ready
    DockerComposeCLI->>DockerEngine: Create & Start DBContainer ('db' service)
    DockerEngine->>DBContainer: Initialize Postgres
    DBContainer-->>DockerEngine: DBContainer running
    DockerComposeCLI->>DockerEngine: Create & Start AppContainer ('app' service, depends on DBContainer)
    DockerEngine->>AppContainer: Start Node.js server (CMD ["node","server.js"])
    activate AppContainer
    AppContainer->>DBContainer: (App logic on startup) Connect to database via 'db' hostname
    DBContainer-->>AppContainer: (App logic) Connection established
    deactivate AppContainer
    AppContainer-->>DockerEngine: AppContainer running & listening on port 3000
Loading

File-Level Changes

Change Details Files
Added Dockerfile for containerizing Node server
  • Base image set to node:20-alpine
  • Installed production dependencies via npm ci --omit=dev
  • Copied application files into container
  • Exposed port 3000 and configured CMD to run server.js
Dockerfile
Introduced docker-compose setup for app and Postgres service
  • Defined app and db services with build instructions and image
  • Mapped ports and environment variables from .env
  • Configured volume for Postgres data persistence
  • Set service dependency so app waits for db
docker-compose.yml
Documented Docker usage in README
  • Added “Docker Usage” section
  • Explained .env file creation
  • Provided commands to build and run containers
  • Noted application endpoint at http://localhost:3000
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gitguardian
Copy link

gitguardian bot commented Jun 8, 2025

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
17706302 Triggered Generic Password bea6656 docker-compose.yml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@qodo-code-review
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns

Sensitive information exposure:
The docker-compose.yml file contains hardcoded database credentials (postgres/postgres) which could be a security risk in production environments. Additionally, the Dockerfile copies all files without exclusions, potentially including sensitive files like .env or private keys that shouldn't be in the container image.

⚡ Recommended focus areas for review

Security Risk

The Dockerfile copies all files after installing dependencies, which may include sensitive files like .env, secrets, or development files. Consider using .dockerignore to exclude sensitive files and optimize the build.

COPY . .
EXPOSE 3000
Hardcoded Credentials

Database credentials are hardcoded in the compose file. This creates security risks and makes the setup inflexible. Consider using environment variables or Docker secrets for database credentials.

POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: wirebase

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @numbpill3d, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello team, gemini-code-assist here to provide a summary of this pull request by @numbpill3d. The main goal of this PR is to introduce a Docker-based setup for local development. This includes containerizing the Node.js application and setting up a PostgreSQL database service using docker-compose, making it significantly easier for developers to get the project running quickly without manual installation of Node.js and PostgreSQL dependencies directly on their machines.

Highlights

  • Docker Setup Added: This pull request introduces a complete Docker setup for local development. It includes a Dockerfile to build the Node.js application image and a docker-compose.yml file to orchestrate the application container alongside a PostgreSQL database service.
  • PostgreSQL Service Included: The docker-compose.yml file defines a PostgreSQL database service (db) using the postgres:15-alpine image, configured with default credentials and a persistent volume (db-data) for storing database files.
  • Local App Container: The docker-compose.yml defines an app service that builds the application image using the new Dockerfile, maps port 3000, sets necessary environment variables (including the database connection string pointing to the db service and secrets pulled from the host environment), and ensures the database service is started first via depends_on.
  • Documentation Updated: The README.md file has been updated with a new section titled "Docker Usage", providing clear instructions on how to use the new Docker setup, including creating a .env file and running the docker-compose up --build command.

Changelog

Click here to see the changelog
  • Dockerfile
    • Added a new Dockerfile to containerize the Node.js application.
    • Uses node:20-alpine as the base image.
    • Sets the working directory to /usr/src/app.
    • Copies package*.json and runs npm ci --omit=dev to install production dependencies.
    • Copies the rest of the application source code.
    • Exposes port 3000.
    • Sets the default command to run the server using node server.js.
  • README.md
    • Added a new section "Docker Usage" (starting around line 159).
    • Provides step-by-step instructions for running the application with Docker.
    • Mentions the requirement for a .env file.
    • Includes the docker-compose up --build command.
    • Specifies the local access URL (http://localhost:3000).
  • docker-compose.yml
    • Added a new docker-compose file (version '3.8').
    • Defines an app service:
      • Builds from the current directory (using the Dockerfile).
      • Maps host port 3000 to container port 3000.
      • Sets environment variables, including PORT, DATABASE_URL (pointing to the db service), and Supabase/Session secrets sourced from the host environment.
      • Depends on the db service.
    • Defines a db service:
      • Uses the postgres:15-alpine image.
      • Sets PostgreSQL environment variables (POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB).
      • Mounts the db-data volume for data persistence.
    • Defines the db-data volume.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@qodo-code-review
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Security
Make database password configurable

Using hardcoded database credentials poses a security risk. The password should
be configurable through environment variables to avoid exposing sensitive
information in the compose file.

docker-compose.yml [17-21]

 image: postgres:15-alpine
 environment:
   POSTGRES_USER: postgres
-  POSTGRES_PASSWORD: postgres
+  POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
   POSTGRES_DB: wirebase
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: This is a strong security and configuration improvement. Hardcoding credentials is a risk, even in development. Using an environment variable with a default value aligns with best practices and the existing .env file convention in the project, making the setup more secure and flexible.

Medium
General
Add database health check dependency

The app service may start before the database is ready to accept connections.
Add a health check condition to ensure the database is fully initialized before
starting the application.

docker-compose.yml [14-15]

 depends_on:
-  - db
+  db:
+    condition: service_healthy
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential race condition where the application may fail to start if the database is not ready. While the proposed solution is correct, it is incomplete as it omits the necessary healthcheck block for the db service, which is required for condition: service_healthy to work.

Medium
  • More

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Docker configuration for local development, including a Dockerfile for the Node server and a docker-compose setup with a Postgres database. This is a valuable addition for simplifying the development environment setup.

The changes are well-structured, adding the necessary files and documentation. However, there is a critical issue regarding the application's database connection logic when running within the Docker Compose environment. The application currently attempts to connect to Supabase using the SUPABASE_URL environment variable, which will point to the remote Supabase instance, rather than using the local Postgres database service defined in the docker-compose.yml file. This will prevent the application from functioning correctly with the local database setup.

Additionally, there are some areas for improvement related to Docker best practices and documentation clarity, which are detailed in the review comments.

Summary of Findings

  • Database Connection Logic in Docker: The application's server.js is hardcoded to connect to Supabase using SUPABASE_URL. When running in Docker Compose, it needs to connect to the local Postgres service (db) using the DATABASE_URL provided in the compose file. This requires changes in the application code to conditionally use the correct database connection string.
  • Dockerfile Security (Non-root User): The Dockerfile runs the application as the root user. It's a security best practice to run containers as a non-root user.
  • Dockerfile Efficiency (.dockerignore): A .dockerignore file is missing, which can lead to unnecessary files being copied into the image, increasing its size and build time.
  • README Clarity (.env variables): The README should explicitly list all environment variables required in the .env file for the Docker Compose setup.
  • Dockerfile Efficiency (Multi-stage build): While not strictly necessary for local development, a multi-stage build could be used to create a smaller final image by excluding development dependencies and build tools. (Note: Not commented on directly due to review settings).
  • Docker Compose Security (Hardcoded DB Credentials): The database credentials (POSTGRES_USER, POSTGRES_PASSWORD) are hardcoded in the docker-compose.yml. While acceptable for local development, this is not secure for production environments. (Note: Not commented on directly due to review settings).

Merge Readiness

This pull request introduces valuable Docker configurations for local development. However, the high-severity issue regarding the application's database connection logic needs to be addressed before merging. The application code must be updated to correctly connect to the local Postgres service when running via Docker Compose.

Once the database connection issue is resolved, and the medium-severity issues are considered (especially the .dockerignore for efficiency), the pull request will be in a good state to be merged. I am unable to approve the pull request directly; please have other reviewers approve this code after the necessary changes are made.

Comment on lines +7 to +13
environment:
- PORT=3000
- DATABASE_URL=postgres://postgres:postgres@db:5432/wirebase
- SUPABASE_URL=${SUPABASE_URL}
- SUPABASE_KEY=${SUPABASE_KEY}
- SUPABASE_SERVICE_KEY=${SUPABASE_SERVICE_KEY}
- SESSION_SECRET=${SESSION_SECRET}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The application's database connection logic in server.js uses process.env.SUPABASE_URL to determine the database host for Knex, and also initializes Supabase clients using the Supabase keys. This means the app will attempt to connect to the remote Supabase instance even when running in Docker Compose.

To use the local Postgres service (db) defined in this file, the application code needs to be updated to conditionally use the DATABASE_URL environment variable (which points to the db service) when running in the Docker Compose environment (e.g., based on a new IS_DOCKER environment variable). This is a critical correctness issue that will prevent the app from working with the local database.

Comment on lines +1 to +7
FROM node:20-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
CMD ["node","server.js"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's generally recommended to run containers as a non-root user for security reasons. While less critical for local development, adopting this practice early is beneficial.

FROM node:20-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
USER node
CMD ["node","server.js"]

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The COPY . . instruction copies all files from the build context into the image. Without a .dockerignore file, this can include unnecessary files like .git, node_modules (if present locally), or build artifacts, increasing image size and build time. Consider adding a .dockerignore file to exclude these.


To run Wirebase locally with Docker:

1. Create a `.env` file using the environment variables shown above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The .env file needs to contain the Supabase keys (SUPABASE_URL, SUPABASE_KEY, SUPABASE_SERVICE_KEY) and SESSION_SECRET as these are passed through to the container via docker-compose.yml. The example .env section above only lists PORT and NODE_ENV. It would be helpful to explicitly list all required variables for the Docker setup here.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @numbpill3d - I've reviewed your changes and they look great!

Blocking issues:

  • By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'. (link)
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🔴 Security: 1 blocking issue
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -0,0 +1,25 @@
version: '3.8'
services:
app:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add a restart policy for the app service

Consider adding a restart policy (e.g., unless-stopped or always) to ensure the container restarts automatically after crashes or reboots.

- SESSION_SECRET=${SESSION_SECRET}
depends_on:
- db
db:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add a healthcheck for the database service

This will help prevent startup connection errors by ensuring the app only starts when the database is ready.

@@ -0,0 +1,7 @@
FROM node:20-alpine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Add a .dockerignore to reduce build context

Exclude node_modules, .git, and logs in your .dockerignore to speed up builds and reduce image size.

Suggested implementation:

node_modules
.git
logs
*.log
npm-debug.log

Comment on lines +168 to 170
The app will be available at `http://localhost:3000`.

## License
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding instructions for stopping the Docker containers.

Including a note about using docker-compose down would help users clean up containers after running the app.

Suggested change
The app will be available at `http://localhost:3000`.
## License
The app will be available at `http://localhost:3000`.
3. To stop and remove the containers, networks, and volumes created by `up`, run:
```bash
docker-compose down

License

RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
CMD ["node","server.js"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (missing-user): By not specifying a USER, a program in the container may run as 'root'. This is a security hazard. If an attacker can control a process running as root, they may have control over the container. Ensure that the last USER in a Dockerfile is a USER other than 'root'.

Suggested change
CMD ["node","server.js"]
USER non-root
CMD ["node","server.js"]

Source: opengrep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant