Skip to content

Conversation

@gocanto
Copy link
Collaborator

@gocanto gocanto commented Jul 10, 2025

Summary by CodeRabbit

  • Chores
    • Updated Docker build and runtime configuration for the API service, including new and revised build arguments, improved directory structure, and enhanced user setup within the container.
    • Changed default application version and binary name for consistency across build and deployment.
    • Refined permissions and setup for SSL certificate files.
    • Improved comments and organization in configuration files for better clarity.

@coderabbitai
Copy link

coderabbitai bot commented Jul 10, 2025

Walkthrough

The changes update Docker build and runtime configuration by introducing new build arguments, unifying directory references under APP_DIR, and improving user and storage directory setup in the Dockerfile. The Makefile target for database SSL file permissions is clarified and made more explicit. No changes to exported code entities were made.

Changes

File(s) Change Summary
config/makefile/db.mk Refined db:chmod target: removed comments, replaced a single chmod with explicit sudo chmod for key and cert.
docker-compose.yml Updated api build args: changed APP_VERSION, added APP_DIR and BINARY_NAME.
docker/dockerfile-api Major refactor: unified directory args, improved user setup, clarified storage creation, changed entrypoint.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Docker as Docker Build System
    participant Image as API Container Image

    Dev->>Docker: Build API image (docker-compose)
    Docker->>Docker: Set build args (APP_VERSION, APP_DIR, BINARY_NAME)
    Docker->>Docker: Build Go binary in ${APP_DIR}
    Docker->>Image: Create non-root user/group, set up directories
    Docker->>Image: Copy binary and fixtures to ${APP_DIR}
    Docker->>Image: Set ownership and permissions
    Docker->>Image: Set ENV variables (APP_DIR, BINARY_NAME)
    Docker->>Image: Set entrypoint to exec ${APP_DIR}/${BINARY_NAME}
    Dev->>Image: Run container as non-root user
Loading

Possibly related PRs

  • [hotfix] Tweak Dokerfile #50: Also modifies the Dockerfile for the API container, focusing on user setup, ownership, and environment variables—directly related to these Dockerfile changes.
  • Tide DB #22: Introduces and manages the db:chmod Makefile target and SSL security commands, which are further refined in this PR.
  • [DB] Production Ready #39: Removes the db:chmod target and refactors database Makefile logic, overlapping with the Makefile changes in this PR.

Poem

In a Docker burrow, neat and bright,
A bunny set the permissions right.
With oullin_api now named anew,
And folders made for logs and stew.
Hop, hop, hop—non-root delight!
The containers run secure tonight.
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@gocanto gocanto changed the title Hotfix/docker user [hotfix] Add/Switch (to) docker non-root user Jul 11, 2025
@gocanto gocanto marked this pull request as ready for review July 11, 2025 02:40
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8aff1ec and d197c3e.

📒 Files selected for processing (3)
  • config/makefile/db.mk (1 hunks)
  • docker-compose.yml (1 hunks)
  • docker/dockerfile-api (1 hunks)
🔇 Additional comments (6)
docker-compose.yml (2)

113-113: Verify the version downgrade is intentional.

The APP_VERSION was changed from v1.0.0-release to 0.0.0.1, which appears to be a downgrade from a release version to a development version. Please confirm this change is intentional and aligns with your release strategy.


117-118: LGTM: Build arguments align with Dockerfile refactoring.

The new APP_DIR and BINARY_NAME build arguments properly align with the Dockerfile changes and help standardize the container configuration.

config/makefile/db.mk (1)

49-50: LGTM: Improved SSL file permissions following security best practices.

The explicit permission settings are correct:

  • 600 for the private key (owner read/write only)
  • 644 for the certificate (world readable, owner writable)

This is more secure and explicit than the previous single command approach.

docker/dockerfile-api (3)

36-53: LGTM: Excellent builder stage improvements.

The builder stage changes are well-implemented:

  • Proper use of APP_DIR for consistency
  • Correct Go cache and module cache configuration
  • Clean directory structure

96-133: LGTM: Excellent non-root user security implementation.

The non-root user setup follows security best practices:

  • Creates dedicated system user and group
  • Sets proper home directory
  • Creates necessary storage directories
  • Assigns correct ownership to the non-root user
  • Switches to non-root user for runtime

This significantly improves container security by avoiding running as root.


144-144: Review the shell-form entrypoint for security implications.

The shell-form entrypoint ["/bin/sh", "-c", "exec ${APP_DIR}/${BINARY_NAME}"] allows environment variable expansion but introduces a shell layer that could potentially be exploited if environment variables are not properly sanitized.

Consider whether the exec-form would be more secure:

ENTRYPOINT ["/app/oullin_api"]

However, if you need the flexibility of environment variable expansion, the current approach is acceptable with proper environment variable validation.

@gocanto gocanto force-pushed the hotfix/docker-user branch from 48c7194 to 1b64eb3 Compare July 11, 2025 02:51
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

🧹 Nitpick comments (1)
docker/dockerfile-api (1)

144-144: Consider simplifying the entrypoint.

While the current entrypoint works correctly, it could be simplified by using the exec form with environment variable substitution.

-# Launch the binary (shell-form so that environment variables are expanded).
-ENTRYPOINT ["/bin/sh", "-c", "exec ${APP_DIR}/${BINARY_NAME}"]
+# Launch the binary directly.
+ENTRYPOINT ["sh", "-c", "exec $APP_DIR/$BINARY_NAME"]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d197c3e and 1b64eb3.

📒 Files selected for processing (1)
  • docker/dockerfile-api (1 hunks)
🔇 Additional comments (8)
docker/dockerfile-api (8)

1-32: Well-organized global build arguments section.

The restructuring of build arguments with detailed comments and the introduction of APP_DIR as a unified directory reference improves maintainability and clarity.


44-51: Excellent Go build cache configuration.

The Go environment variables are properly configured to use APP_DIR as the base, which keeps the build artifacts organized within the container's application directory.


69-73: Well-structured multi-line Go build command.

The build command is clearly formatted with proper comments explaining each flag. The static linking and version injection are correctly implemented.


96-107: Excellent non-root user setup.

The user and group creation is properly structured with separate commands for clarity. The explicit home directory creation ensures proper ownership setup.


128-134: Proper ownership and user switching.

The ownership assignment and user switching to non-root is correctly implemented for security best practices.


135-144: Correct handling of runtime environment variables.

The solution to expose build arguments as environment variables for runtime use is appropriate. The shell-form entrypoint correctly allows environment variable expansion.


36-36: Base image golang:1.24-alpine is available on Docker Hub

The tag golang:1.24-alpine exists (including variants 1.24-alpine and 1.24.5-alpine), so you can safely use it as your builder image.


78-78: Alpine 3.22 tag verified on Docker Hub

The FROM alpine:3.22 line is valid—Alpine 3.22 exists in the official registry, so no change is needed.

  • File: docker/dockerfile-api
  • Line: 78

@gocanto gocanto merged commit 3fca82c into main Jul 11, 2025
4 checks passed
@gocanto gocanto deleted the hotfix/docker-user branch July 11, 2025 02:59
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.

2 participants