-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
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.
📝 WalkthroughWalkthroughThe 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
Sequence DiagramsequenceDiagram
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
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 releaseI 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:
- Using
node:20-slim
as the base image instead of Ubuntu- 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 approachThe 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 fileI 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 extensionsI 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 dependenciesA few suggestions to make this Makefile more robust, if I may:
- Add .PHONY declarations for targets
- 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.1docker-dev-setup/Dockerfile (2)
12-12
: Splendid addition of the make utilityThe 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 versionsWhile 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
📒 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
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 |
There was a problem hiding this comment.
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.
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 |
serve: | ||
php artisan serve --host=0.0.0.0 |
There was a problem hiding this comment.
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.
serve: | |
php artisan serve --host=0.0.0.0 | |
serve: | |
php artisan serve --host=127.0.0.1 |
There was a problem hiding this 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)
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.