Skip to content
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

Dockerfile #2418

Conversation

VanshikaSabharwal
Copy link

@VanshikaSabharwal VanshikaSabharwal commented Nov 10, 2024

What kind of change does this PR introduce?

feature

Issue Number:

Fixes #1075

Did you add tests for your changes?
No

Snapshots/Videos:

image
image
image
image

If relevant, did you update the documentation?

Summary

-->Added a Dockerfile and a docker-compose.yaml file to containerize the application.
-->Modified config.vite.ts:

  1. Set host: '0.0.0.0' to allow the application to be accessible from outside the Docker container.
  2. Set open: false to prevent the app from automatically opening in the browser on startup.

These changes were necessary because the app wasn't initially accessible when run inside a Docker container. With these adjustments, talawa-admin can now be successfully accessed while running in Docker.

Does this PR introduce a breaking change?

Other information

Have you read the contributing guide?
Yes

Summary by CodeRabbit

  • New Features

    • Introduced a .dockerignore file to optimize Docker image builds.
    • Added a new Docker-Start-Check job in the GitHub Actions workflow to verify the application starts correctly in Docker.
    • New app service in docker-compose.yaml for building the application.
  • Changes

    • Updated server settings in vite.config.ts to modify accessibility and startup behavior.
    • Implemented a multi-stage build process in the Dockerfile for improved application deployment.

Copy link

coderabbitai bot commented Nov 10, 2024

Walkthrough

This pull request introduces several changes to enhance Docker support for the Talawa Admin application. A new .dockerignore file is added to optimize the Docker build context by excluding unnecessary files and directories. The workflow file for GitHub Actions is updated to include a new job, Docker-Start-Check, which verifies that the application starts correctly within a Docker container. Additionally, a multi-stage Dockerfile is created to build the Node.js application, and the docker-compose.yaml file is modified to include a new service for the application. Finally, updates are made to the Vite configuration to change server settings.

Changes

File Change Summary
.dockerignore New file created to exclude unnecessary files and directories from the Docker build context.
.github/workflows/pull-request.yml New job Docker-Start-Check added to verify application startup in Docker after build checks.
Dockerfile Introduces a multi-stage build process for the Node.js application, setting up environment and commands.
config/vite.config.ts Modified server settings: open set to false, host set to '0.0.0.0', port changed to 4321.
docker-compose.yaml New service app added, configured to build from the current directory and expose port 4321.

Assessment against linked issues

Objective Addressed Explanation
Implement Docker support for Talawa-Admin (#1075)
Create a Dockerfile specifying necessary dependencies
Configure the application to work within Docker

🐰 In the garden where the code does grow,
A Dockerfile blooms, with a vibrant glow.
The app now starts with a joyful cheer,
In containers it dances, spreading good cheer!
With each little change, our project takes flight,
Hopping towards success, oh what a delight! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (6)
docker-compose.yaml (2)

6-7: Improve environment variable handling.

The current environment variable configuration could be more robust:

  1. No default value if the host variable is unset
  2. No validation of the URL format

Consider using an env file and adding validation:

     environment:
-      - REACT_APP_TALAWA_URL=${REACT_APP_TALAWA_URL}
+      - REACT_APP_TALAWA_URL=${REACT_APP_TALAWA_URL:-http://localhost:3000}
+    env_file:
+      - .env

Also, consider adding environment variable validation in your entrypoint script.


8-9: Consider development workflow with volumes.

The commented volume mount suggests this was intended for development. If this is meant to support both production and development workflows, consider using Docker Compose profiles.

Example implementation:

     environment:
       - REACT_APP_TALAWA_URL=${REACT_APP_TALAWA_URL}
-    # volumes:
-    # - .:/usr/src/app
+    profiles:
+      - prod
+      - dev
+    volumes:
+      - type: bind
+        source: .
+        target: /usr/src/app
+        when: service_started
+        consistency: cached

This allows running different configurations:

  • Production: docker compose --profile prod up
  • Development: docker compose --profile dev up
config/vite.config.ts (1)

26-27: LGTM! Container-friendly server configuration.

The changes to open: false and host: '0.0.0.0' are appropriate for containerized environments:

  • Disabling auto-open is correct as containers don't have browsers
  • Setting host to '0.0.0.0' is necessary to allow external access to the containerized application

Note: Ensure your container orchestration and network security controls are properly configured since the application will be listening on all network interfaces.

.github/workflows/pull-request.yml (3)

267-274: Consider enhancing Docker build and run configuration.

A few suggestions to improve robustness:

  1. Use environment variables for port mapping instead of hardcoding
  2. Add retry mechanism for build failures
  3. Verify Dockerfile includes proper HEALTHCHECK instruction
- docker run -d --name talawa-admin-app-container -p 8080:8080 talawa-admin-app
+ docker run -d --name talawa-admin-app-container -p ${PORT:-8080}:8080 talawa-admin-app
🧰 Tools
🪛 yamllint

[error] 270-270: trailing spaces

(trailing-spaces)


288-293: Add error handling to cleanup steps.

While the cleanup runs in all cases (good!), consider adding error handling for cases where the container might already be stopped or removed.

- docker stop talawa-admin-app-container
- docker rm talawa-admin-app-container
+ docker stop talawa-admin-app-container || true
+ docker rm talawa-admin-app-container || true
🧰 Tools
🪛 yamllint

[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)


Line range hint 294-304: Add newline at end of file.

Add a newline character at the end of the file to comply with POSIX standards.

🧰 Tools
🪛 yamllint

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


[error] 287-287: trailing spaces

(trailing-spaces)


[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9dd5d7f and 235d163.

📒 Files selected for processing (5)
  • .dockerignore (1 hunks)
  • .github/workflows/pull-request.yml (2 hunks)
  • Dockerfile (1 hunks)
  • config/vite.config.ts (1 hunks)
  • docker-compose.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .dockerignore
🧰 Additional context used
🪛 yamllint
.github/workflows/pull-request.yml

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


[error] 287-287: trailing spaces

(trailing-spaces)


[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)


[error] 304-304: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (3)
Dockerfile (1)

13-15: Verify port configuration and add health check.

There's a discrepancy between the exposed port (4321) and the port mentioned in the GitHub Actions workflow (8080). Additionally, a health check would improve container orchestration.

Consider adding these improvements:

+# Add environment variable for port
+ENV PORT=4321
+
 EXPOSE 4321
 
+# Add health check
+HEALTHCHECK --interval=30s --timeout=3s \
+  CMD curl -f http://localhost:4321/ || exit 1
+
 CMD ["npm", "run", "serve"]
docker-compose.yaml (1)

10-11: Verify port availability and consider using different host port.

The application uses port 4321 on both host and container. This could cause conflicts if the host port is already in use.

Let's check if this port is commonly used or mentioned in other configurations:

✅ Verification successful

Port 4321 is intentionally used as the default development server port

The port 4321 is deliberately configured as the default development server port in the application:

  • It's defined in config/vite.config.ts as the default development server port
  • It's used in the setup configuration (src/setup/askForCustomPort) with a prompt allowing users to customize it
  • The Docker configuration aligns with this default port setting

Since this is an intentional configuration with built-in customization options, there's no immediate concern about port conflicts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for port 4321 usage in the codebase
# Test: Search for port 4321 mentions. Expect: Only in Docker/deployment configs

echo "Checking for port 4321 usage in configuration files..."
rg -g "*.{json,yaml,yml,env,conf,config,js,ts}" "4321"

echo "Checking for other exposed ports in Docker configurations..."
rg -g "{Dockerfile,docker-compose.*}" "EXPOSE|ports:"

Length of output: 942

.github/workflows/pull-request.yml (1)

256-260: LGTM: Job configuration and dependencies are well structured.

The job is correctly configured to run after code quality checks and tests, ensuring Docker verification happens on validated code.

Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
Dockerfile Show resolved Hide resolved
docker-compose.yaml Show resolved Hide resolved
config/vite.config.ts Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
.github/workflows/pull-request.yml (3)

261-270: Consider optimizing Docker build for CI efficiency.

While the current setup works, consider these improvements for better CI efficiency:

  1. Add build caching to speed up subsequent builds
  2. Use proper image versioning
 - name: Build Docker image
   run: |
-    docker build -t talawa-admin-app .
+    docker build \
+      --cache-from type=gha \
+      --cache-to type=gha,mode=max \
+      --tag talawa-admin-app:${GITHUB_SHA::8} \
+      --tag talawa-admin-app:latest \
+      .
🧰 Tools
🪛 yamllint

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


288-293: Improve cleanup step reliability.

While the cleanup is thorough, add error handling to prevent cleanup failures from affecting the workflow status.

 - name: Stop Docker Container 
   if: always()
   run: |
-    docker stop talawa-admin-app-container
-    docker rm talawa-admin-app-container
+    docker stop talawa-admin-app-container || true
+    docker rm talawa-admin-app-container || true
🧰 Tools
🪛 yamllint

[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)


Line range hint 263-304: Fix YAML formatting issues.

There are several formatting issues in the file:

  1. Remove trailing spaces (lines 263, 266, 270, 287, 288, 293)
  2. Add newline at end of file (line 304)
🧰 Tools
🪛 yamllint

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


[error] 287-287: trailing spaces

(trailing-spaces)


[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 235d163 and 66f4843.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (2 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/pull-request.yml

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


[error] 287-287: trailing spaces

(trailing-spaces)


[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)


[error] 304-304: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

256-260: LGTM: Job configuration is well structured.

The job configuration is appropriate with correct dependencies and platform choice.

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.28%. Comparing base (9dd5d7f) to head (88626b7).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2418   +/-   ##
========================================
  Coverage    98.28%   98.28%           
========================================
  Files          283      283           
  Lines         8224     8224           
  Branches      2356     2356           
========================================
  Hits          8083     8083           
  Misses         132      132           
  Partials         9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
.dockerignore (3)

1-2: Consider adding more Node.js specific patterns.

While the basic Node.js patterns are covered, consider adding these additional patterns for completeness:

 node_modules
 npm-debug.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+.pnpm-debug.log*
+.npm
+.yarn

8-9: Add more specific environment file patterns.

Consider expanding environment file patterns to cover all possible variations:

 .env
 .env.*
+.env.local
+.env.development
+.env.test
+.env.production

10-12: Add more build and coverage related patterns.

Consider adding these additional build-related patterns:

 dist
 coverage
 .nyc_output
+build
+out
+.next
+.cache
+.eslintcache
.github/workflows/pull-request.yml (1)

263-293: Fix formatting issues.

The workflow file has several formatting issues:

  • Trailing spaces on multiple lines
  • Missing newline at end of file

Run the following command to fix formatting:

sed -i 's/[[:space:]]*$//' .github/workflows/pull-request.yml && echo >> .github/workflows/pull-request.yml

Also applies to: 304-304

🧰 Tools
🪛 actionlint

276-276: shellcheck reported issue in this script: SC2086:info:2:35: Double quote to prevent globbing and word splitting

(shellcheck)


276-276: shellcheck reported issue in this script: SC2086:info:6:6: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


[error] 287-287: trailing spaces

(trailing-spaces)


[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66f4843 and 88626b7.

📒 Files selected for processing (2)
  • .dockerignore (1 hunks)
  • .github/workflows/pull-request.yml (2 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/pull-request.yml

276-276: shellcheck reported issue in this script: SC2086:info:2:35: Double quote to prevent globbing and word splitting

(shellcheck)


276-276: shellcheck reported issue in this script: SC2086:info:6:6: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint
.github/workflows/pull-request.yml

[error] 263-263: trailing spaces

(trailing-spaces)


[error] 266-266: trailing spaces

(trailing-spaces)


[error] 270-270: trailing spaces

(trailing-spaces)


[error] 287-287: trailing spaces

(trailing-spaces)


[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)


[error] 304-304: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (4)
.dockerignore (1)

1-18: LGTM! Comprehensive exclusion patterns for Node.js application.

The .dockerignore file follows best practices for Node.js applications and includes all essential patterns to optimize the Docker build context.

.github/workflows/pull-request.yml (3)

256-260: LGTM! Job configuration is well structured.

The job dependencies ensure Docker verification runs after essential checks, maintaining the integrity of the workflow.


288-293: LGTM! Proper cleanup implementation.

The cleanup steps are well implemented with:

  • Guaranteed execution using if: always()
  • Complete container cleanup including both stop and remove operations
🧰 Tools
🪛 yamllint

[error] 288-288: trailing spaces

(trailing-spaces)


[error] 293-293: trailing spaces

(trailing-spaces)


275-287: ⚠️ Potential issue

Enhance container health check reliability.

The current health check implementation needs improvements:

  1. Add container logs on failure for better debugging
  2. Implement proper retry mechanism for health checks
  3. Verify the existence of /health endpoint

Apply these improvements:

 - name: Check if Talawa Admin App is running
   run: |
     timeout=${HEALTH_CHECK_TIMEOUT:-60}
+    echo "Waiting for application to start..."
     while ! nc -z localhost 4321 && [ $timeout -gt 0 ]; do
       sleep 1
       timeout=$((timeout-1))
+      echo "Waiting... ${timeout}s remaining"
     done
     if [ $timeout -eq 0 ]; then
       echo "Timeout waiting for application to start"
+      docker logs talawa-admin-app-container
       exit 1
     fi
-    curl --fail --silent http://localhost:4321/health || exit 1
+    # Implement retry mechanism for health checks
+    max_retries=3
+    for i in $(seq 1 $max_retries); do
+      if curl --fail --silent http://localhost:4321/health; then
+        echo "Health check passed!"
+        exit 0
+      fi
+      echo "Health check attempt $i failed, retrying..."
+      sleep 5
+    done
+    echo "Health check failed after $max_retries attempts"
+    docker logs talawa-admin-app-container
+    exit 1

Let's verify if the health endpoint exists:

🧰 Tools
🪛 actionlint

276-276: shellcheck reported issue in this script: SC2086:info:2:35: Double quote to prevent globbing and word splitting

(shellcheck)


276-276: shellcheck reported issue in this script: SC2086:info:6:6: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint

[error] 287-287: trailing spaces

(trailing-spaces)

.dockerignore Show resolved Hide resolved
.github/workflows/pull-request.yml Show resolved Hide resolved
@palisadoes
Copy link
Contributor

Please make code rabbit approve your changes.

You should close this PR and add the docker file changes to this PR

@palisadoes
Copy link
Contributor

During the week of November 11, 2024 we will start a code freeze on the develop branches in Talawa, Talawa Admin and Talawa-API.

We have completed a project to convert the Talawa-API backend to use PostgreSQL. Work will then begin with us merging code in the develop branches to a new develop-postrgres branch in each repository.

Planning activities for this will be managed in our #talawa-projects slack channel. A GitHub project will be created to track specially labeled issues. We completed a similar exercise last year using a similar methodology.

Starting November 12, California time no new PRs will be accepted against the develop branch. They must be applied to the develop-postrgres branch.

There are some GSoC project features that will need to be merged into develop. These will be the only exceptions.

This activity and the post GSoC 2024 start date was announced in our #general Slack channel last month as a pinned post.

@VanshikaSabharwal
Copy link
Author

Please make code rabbit approve your changes.

You should close this PR and add the docker file changes to this PR

yes I did it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants