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

Portable devcontainer #674

Merged
merged 1 commit into from
Dec 30, 2024
Merged

Portable devcontainer #674

merged 1 commit into from
Dec 30, 2024

Conversation

horcsinbalint
Copy link
Member

This devcontainer setup does not need any kind of dependency to be installed on the development machine except for VS Code, Docker (Compose) unlike the previous dev container setup in this project which required php to be installed on the machine hindering its usability.

This devcontainer setup does not need any kind of dependency to be installed on the development machine except for VS Code, Docker (Compose) unlike the previous dev container setup in this project which required php to be installed on the machine hindering its usability.
@horcsinbalint horcsinbalint requested a review from a team as a code owner December 30, 2024 21:50
Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

📝 Walkthrough

Walkthrough

The pull request introduces comprehensive modifications to the development environment configuration. The changes primarily focus on restructuring the Docker-based setup, renaming services from "laravel.test" to "mars_dev", updating container configurations, and introducing new Makefile targets for build, seed, and serve operations. The modifications aim to create a more tailored and streamlined development workflow with updated MySQL version, container settings, and development toolchain.

Changes

File Change Summary
.devcontainer/devcontainer.json Renamed container to "Mars development", updated service name, workspace path, and remote user
Makefile Added new targets: build, seed, and serve for application management
docker-compose.yml Removed laravel.test service, updated mysql service, added new mars_dev service
docker-dev-setup/Dockerfile Added make utility to package installations
Deleted Files Removed docker-compose.gitpod.yml and docker-dev-setup/docker-compose.yml

Sequence Diagram

sequenceDiagram
    participant Developer
    participant Makefile
    participant Docker
    participant Application

    Developer->>Makefile: make build
    Makefile->>Docker: Build container
    Docker->>Application: Install dependencies
    Docker->>Application: Run migrations
    
    Developer->>Makefile: make serve
    Makefile->>Application: Start server on 0.0.0.0
Loading

Possibly Related PRs


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
Contributor

@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 comments (2)
docker-dev-setup/Dockerfile (2)

Line range hint 1-1: Consider using a current stable Ubuntu release

I say, the specified Ubuntu 24.04 release isn't yet available, which could lead to stability issues. Might I suggest using Ubuntu 22.04 LTS instead? This would provide a more stable foundation for your development environment.

-FROM ubuntu:24.04
+FROM ubuntu:22.04

Node.js installation approach requires updating to current best practices

I say, the current installation method using the NodeSource repository, whilst functional, isn't quite the recommended approach for Docker containers. The proper method would be to use the official Node.js Docker image as a base or to employ the official Node.js binary distribution.

The current approach:

  • Uses a third-party repository (NodeSource)
  • Requires additional system dependencies
  • Creates unnecessary layers in the Docker image

Might I suggest either:

  1. Using node:20-slim as the base image instead of Ubuntu
  2. Or, if Ubuntu is required, downloading the official Node.js binary tarball from nodejs.org and extracting it

This would result in a more maintainable and secure container setup, following Docker best practices.

🔗 Analysis chain

Line range hint 15-16: Verify Node.js installation approach

The Node.js installation looks proper, but let's verify if this is the recommended approach for Ubuntu containers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check official Node.js Docker documentation for recommended installation method

# Search for Node.js installation instructions in documentation files
rg -i "node.*install.*ubuntu" $(fd -t f -e md -e txt)

# Check if there are any existing Node.js related Dockerfiles in the project
fd Dockerfile | xargs rg -l "nodejs|node"

Length of output: 276


Script:

#!/bin/bash
# Let's check the official Node.js Docker documentation from their GitHub repository
curl -s https://raw.githubusercontent.com/nodejs/docker-node/main/README.md | grep -A 5 "Installation"

# Let's examine our Dockerfile more thoroughly
cat docker-dev-setup/Dockerfile

# Let's also check if there are any other Node.js installation methods in other Dockerfiles
rg -A 5 "RUN.*curl.*node" 

Length of output: 1357

🧹 Nitpick comments (5)
docker-compose.yml (1)

32-32: Add newline at end of file

I do apologise for being rather pedantic, but the file should end with a proper newline character. This is considered good practice and prevents potential issues with text processing tools.

volumes:
  mars_db:
+
🧰 Tools
🪛 yamllint (1.35.1)

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

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

.devcontainer/devcontainer.json (1)

Line range hint 11-16: Consider enabling recommended extensions

I notice we have some rather useful Laravel development extensions commented out. These would provide a jolly good development experience for the team. Might I suggest enabling them?

  "extensions": [
-    // "mikestead.dotenv",
-    // "amiralizadeh9480.laravel-extra-intellisense",
-    // "ryannaddy.laravel-artisan",
-    // "onecentlin.laravel5-snippets",
-    // "onecentlin.laravel-blade"
+    "mikestead.dotenv",
+    "amiralizadeh9480.laravel-extra-intellisense",
+    "ryannaddy.laravel-artisan",
+    "onecentlin.laravel5-snippets",
+    "onecentlin.laravel-blade"
  ],
Makefile (1)

1-13: Enhance Makefile with proper declarations and dependencies

A few suggestions to make this Makefile more robust, if I may:

  1. Add .PHONY declarations for targets
  2. Establish proper dependencies between targets
+.PHONY: build seed serve
+
 build:
     npm install
     composer install
     npm run dev
     cp .env.example .env
     php artisan key:generate
     php artisan migrate

-seed:
+seed: build
     php artisan db:seed

-serve:
+serve: build
     php artisan serve --host=127.0.0.1
docker-dev-setup/Dockerfile (2)

12-12: Splendid addition of the make utility

The addition of make is quite sensible given the new build automation approach. However, might I kindly suggest adding a comment explaining its purpose for future maintainers?

-                          make \
+                          make \ # Required for build automation and development workflows

Line range hint 6-9: Consider pinning specific PHP package versions

While the PHP 8.3 setup is comprehensive, might I suggest pinning specific versions for better reproducibility? This would help ensure consistent development environments across the team.

-                          php8.3-cli php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmath \
+                          php8.3-cli=8.3.0* php8.3-mysql=8.3.0* php8.3-zip=8.3.0* php8.3-gd=8.3.0* \
+                          php8.3-mbstring=8.3.0* php8.3-curl=8.3.0* php8.3-xml=8.3.0* php8.3-bcmath=8.3.0* \
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a05f8e4 and 9bbe9c9.

📒 Files selected for processing (7)
  • .devcontainer/devcontainer.json (2 hunks)
  • Makefile (1 hunks)
  • docker-compose.gitpod.yml (0 hunks)
  • docker-compose.yml (1 hunks)
  • docker-dev-setup/Dockerfile (1 hunks)
  • docker-dev-setup/README.md (0 hunks)
  • docker-dev-setup/docker-compose.yml (0 hunks)
💤 Files with no reviewable changes (3)
  • docker-compose.gitpod.yml
  • docker-dev-setup/docker-compose.yml
  • docker-dev-setup/README.md
🧰 Additional context used
🪛 yamllint (1.35.1)
docker-compose.yml

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

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

🔇 Additional comments (2)
docker-compose.yml (1)

18-29: Verify the docker-dev-setup directory

I notice we're referencing a build context at ./docker-dev-setup. Let's ensure this directory exists with proper Dockerfile configuration.

✅ Verification successful

Build context verified and properly configured

I say, the docker-dev-setup directory is present and properly configured with all the necessary components. The Dockerfile contains:

  • A suitable base image (Ubuntu 24.04)
  • All required PHP 8.3 dependencies and development tools
  • Node.js 20.x installation
  • Appropriate workspace configuration at /workspace/mars

Everything appears to be in perfect order, and the build context referenced in the docker-compose.yml is entirely valid.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the build context exists and contains necessary files
if [ -d "./docker-dev-setup" ]; then
    echo "Build context directory exists"
    ls -la ./docker-dev-setup
else
    echo "Warning: Build context directory not found"
fi

Length of output: 301


Script:

#!/bin/bash
# Let's examine the contents of the Dockerfile
cat ./docker-dev-setup/Dockerfile

Length of output: 886

.devcontainer/devcontainer.json (1)

8-8: Verify workspace path consistency

Splendid attention to detail ensuring the workspace path /workspace/mars matches between the devcontainer configuration and the volume mount in docker-compose.yml. This maintains proper consistency.

Also applies to: 27-27

Comment on lines +4 to +17
mysql:
container_name: mysql
image: mysql:8.3
environment:
MYSQL_DATABASE: 'mars'
MYSQL_USER: 'mars'
MYSQL_PASSWORD: 'secret'
MYSQL_ROOT_PASSWORD: 'secret'
ports:
- '127.0.0.1:3307:3306'
expose:
- '3306'
volumes:
- mars_db:/var/lib/mysql
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using environment variables for MySQL credentials

I say, it would be rather prudent to move these credentials to a .env file instead of having them directly in the compose file. This would align splendidly with security best practices.

Here's a proper British way to do it:

  mysql:
    container_name: mysql
    image: mysql:8.3
    environment:
-      MYSQL_DATABASE: 'mars'
-      MYSQL_USER: 'mars'
-      MYSQL_PASSWORD: 'secret'
-      MYSQL_ROOT_PASSWORD: 'secret'
+      MYSQL_DATABASE: ${MYSQL_DATABASE:-mars}
+      MYSQL_USER: ${MYSQL_USER:-mars}
+      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-secret}
+      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-secret}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mysql:
container_name: mysql
image: mysql:8.3
environment:
MYSQL_DATABASE: 'mars'
MYSQL_USER: 'mars'
MYSQL_PASSWORD: 'secret'
MYSQL_ROOT_PASSWORD: 'secret'
ports:
- '127.0.0.1:3307:3306'
expose:
- '3306'
volumes:
- mars_db:/var/lib/mysql
mysql:
container_name: mysql
image: mysql:8.3
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE:-mars}
MYSQL_USER: ${MYSQL_USER:-mars}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-secret}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-secret}
ports:
- '127.0.0.1:3307:3306'
expose:
- '3306'
volumes:
- mars_db:/var/lib/mysql

Comment on lines +12 to +13
serve:
php artisan serve --host=0.0.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Restrict service binding to localhost

I must point out that binding to 0.0.0.0 might be a tad too permissive. Since we're in a development container, we should restrict this to localhost for improved security.

serve:
-    php artisan serve --host=0.0.0.0
+    php artisan serve --host=127.0.0.1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
serve:
php artisan serve --host=0.0.0.0
serve:
php artisan serve --host=127.0.0.1

Copy link
Member

@BertalanD BertalanD left a comment

Choose a reason for hiding this comment

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

Tried this locally, seems to work fine (macOS host, no php installed locally)

@BertalanD BertalanD merged commit 44925cd into development Dec 30, 2024
4 of 6 checks passed
@BertalanD BertalanD deleted the better-dev-container branch December 30, 2024 23:05
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
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