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

Fix/docker image build for production #52

Merged
merged 4 commits into from
Sep 12, 2024

Conversation

BMartinos
Copy link
Collaborator

@BMartinos BMartinos commented Sep 12, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a session callback in the authentication options to enhance user state management during authentication.
    • Added necessary environment variables for database access and Keycloak integration, including configurations for NextAuth.js.
  • Bug Fixes

    • Improved formatting and readability across various files without affecting functionality.
  • Refactor

    • Modularized authentication configuration for better organization and maintainability.
  • Style

    • Standardized code formatting, including the use of single quotes in import statements and improved indentation for readability.

Reverting a code regression which was causing the production build to fail.
Nextjs routes doesnt support export of unknown fields in route files
Copy link

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes involve significant updates to the .env configuration file for a development environment, including the addition of database and Keycloak credentials. The docker-compose.yml file has been modified to change port mappings for services. Additionally, various files underwent formatting adjustments, such as consistent use of single quotes and improved readability, while maintaining existing functionality across the application.

Changes

Files Change Summary
.env Updated with database credentials, Keycloak settings, and new environment variables for authentication.
docker-compose.yml Changed port mappings for services to 3080:3000 and 8082:8080.
src/app/api/auth/[...nextauth]/route.ts, src/app/api/auth/authOptions.ts Refactored authentication configuration; removed authOptions from route file and added session callback in authOptions.
src/app/api/docs/page.tsx, src/app/api/docs/react-swagger.tsx Changed import statements from double quotes to single quotes; no functional changes.
src/app/api/v1/share-links/[id]/accesses/route.test.ts, src/app/api/v1/share-links/[id]/accesses/route.ts Reformatted code for consistency; used single quotes; no functional changes.
src/app/api/v1/share-links/[id]/deactivate/route.test.ts, src/app/api/v1/share-links/[id]/deactivate/route.ts Minor formatting changes; consistent use of single quotes; core logic remains unchanged.
src/app/api/v1/share-links/[id]/endpoints/[endpointId]/route.ts, src/app/api/v1/share-links/[id]/endpoints/route.ts Minor formatting adjustments for readability; no changes to functionality.
src/app/api/v1/share-links/route.test.ts, src/app/api/v1/share-links/route.ts Formatting improvements; consistent use of single quotes; no changes to logic.
src/app/api/v1/users/[id]/ips/route.test.ts, src/app/api/v1/users/[id]/ips/route.ts Formatting adjustments; consistent use of single quotes; no changes to functionality.
src/app/utils/authentication.ts, src/app/utils/error-handler.ts Formatting improvements for consistency; no changes to functionality.
src/domain/dtos/server-config.ts, src/domain/dtos/shlink-access.ts, src/domain/dtos/shlink-endpoint.ts, src/domain/dtos/shlink.ts, src/domain/dtos/user.ts Minor formatting changes in documentation comments; no functional changes.
src/infrastructure/clients/prisma.ts, src/lib/swagger.ts Minor formatting changes; consistent use of single quotes; no changes to functionality.
src/mappers/shlink-access-mapper.test.ts, src/mappers/shlink-access-mapper.ts Formatting adjustments for readability; no changes to functionality.
src/middleware.ts Formatting improvements in error handling; no changes to functionality.
src/usecases/shlink-access/get-shlink-accesses.test.ts, src/usecases/shlink-access/get-shlink-accesses.ts Formatting improvements for readability; no changes to functionality.
src/usecases/shlinks/deactivate-shlink.test.ts, src/usecases/shlinks/deactivate-shlink.ts Formatting adjustments; no changes to functionality.
src/usecases/shlinks/get-shlink.test.ts, src/usecases/shlinks/get-shlink.ts Minor formatting changes; no alterations to functionality.

Possibly related PRs

Poem

🐰 In the code where bunnies play,
New settings hop in, brightening the day.
Ports are changed, and quotes align,
Authentication's neat, all functions combine.
With every tweak, we leap with glee,
Crafting code as sweet as can be! 🎶


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29a1086 and 2aa8576.

Files selected for processing (3)
  • .env (1 hunks)
  • docker-compose.yml (2 hunks)
  • src/infrastructure/clients/prisma.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/infrastructure/clients/prisma.ts
Additional context used
Gitleaks
.env

11-11: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (3)
.env (1)

11-11: False positive: KEYCLOAK_CLIENT_SECRET is stored securely.

The static analysis hint from Gitleaks has flagged the KEYCLOAK_CLIENT_SECRET value as a potential generic API key. However, this appears to be a false positive in this case.

The KEYCLOAK_CLIENT_SECRET is a sensitive value used for authenticating with Keycloak, and it is appropriate to store it securely in the .env file, which should not be committed to version control. Therefore, the current handling of this value is correct.

Tools
Gitleaks

11-11: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

docker-compose.yml (2)

16-16: Verify the port change has been tested and documented.

The change to map the internal port 3000 to the external port 3080 for the app service looks good. This will help avoid potential conflicts with other services or applications that might be using port 3000.

Please ensure that:

  • The application has been tested to work correctly with this new port mapping.
  • The port change has been documented, including updating any relevant README files, configuration guides, or deployment instructions.

53-53: Verify the port change has been tested, documented, and environment variable updated.

The change to map the internal port 8080 to the external port 8082 for the keycloak service looks good. This will help free up port 8080 for other uses or services.

Please ensure that:

  • The keycloak service has been tested to work correctly with this new port mapping.
  • The port change has been documented, including updating any relevant README files, configuration guides, or deployment instructions.

Additionally, consider updating the KC_HOSTNAME_PORT environment variable to match the new external port:

  environment:
    KC_HOSTNAME: localhost
-   KC_HOSTNAME_PORT: 8080
+   KC_HOSTNAME_PORT: 8082
    KC_HOSTNAME_STRICT_BACKCHANNEL: false 

.env Outdated Show resolved Hide resolved
Copy link
Collaborator

@yassinedorbozgithub yassinedorbozgithub left a comment

Choose a reason for hiding this comment

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

yarn build

image

LGTM 👍

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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2aa8576 and a4013d6.

Files selected for processing (1)
  • .env (1 hunks)
Additional context used
Gitleaks
.env

10-10: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (10)
.env (10)

2-2: LGTM!

The modification to the PRISMA_FIELD_ENCRYPTION_HASH_SALT environment variable, replacing the placeholder value with an actual hash salt, is necessary and appropriate.


3-3: LGTM!

The addition of the POSTGRES_DB environment variable, set to postgres, is necessary for configuring the PostgreSQL database.


4-4: LGTM!

The addition of the POSTGRES_USER environment variable, set to postgres, is necessary for configuring the PostgreSQL database.


6-6: LGTM!

The addition of the EXTERNAL_URL environment variable, set to http://localhost:3001, is necessary for configuring the application's external URL.


7-7: LGTM!

The addition of the KEYCLOAK_ADMIN environment variable, set to admin, is necessary for configuring the Keycloak admin user.


9-9: LGTM!

The addition of the KEYCLOAK_CLIENT_ID environment variable, set to "nextjs", is necessary for configuring the Keycloak client ID.


11-11: LGTM!

The addition of the KEYCLOAK_ISSUER environment variable, set to "http://localhost:8082/realms/shlp", is necessary for configuring the Keycloak issuer URL.


12-12: LGTM!

The addition of the NEXTAUTH_URL environment variable, set to "http://localhost:3000", is necessary for configuring the NextAuth.js URL.


14-14: LGTM!

The addition of the NEXT_CONTAINER_KEYCLOAK_ENDPOINT environment variable, set to "http://localhost:8082", is necessary for configuring the Keycloak endpoint for the Next.js container.


15-15: LGTM!

The addition of the NEXT_LOCAL_KEYCLOAK_URL environment variable, set to "http://localhost:8082", is necessary for configuring the local Keycloak URL for Next.js.

.env Show resolved Hide resolved
.env Show resolved Hide resolved
.env Show resolved Hide resolved
.env Show resolved Hide resolved
@BMartinos BMartinos merged commit 653b873 into main Sep 12, 2024
2 checks passed
@BMartinos BMartinos deleted the fix/docker-image-build-for-production branch September 12, 2024 09:35
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.

3 participants