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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// https://aka.ms/devcontainer.json
{
"name": "Existing Docker Compose (Extend)",
"name": "Mars development",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "laravel.test",
"workspaceFolder": "/var/www/html",
"service": "mars_dev",
"workspaceFolder": "/workspace/mars",
"settings": {},
"extensions": [
// "mikestead.dotenv",
Expand All @@ -14,9 +14,9 @@
// "onecentlin.laravel5-snippets",
// "onecentlin.laravel-blade"
],
"remoteUser": "sail",
"postCreateCommand": "chown -R 1000:1000 /var/www/html"
"remoteUser": "ubuntu",
"postCreateCommand": "make build"
// "forwardPorts": [],
// "runServices": [],
// "shutdownAction": "none",
}
}
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
build:
npm install
composer install
npm run dev
cp .env.example .env
php artisan key:generate
php artisan migrate

seed:
php artisan db:seed

serve:
php artisan serve --host=0.0.0.0
Comment on lines +12 to +13
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

20 changes: 0 additions & 20 deletions docker-compose.gitpod.yml

This file was deleted.

82 changes: 29 additions & 53 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
# For more information: https://laravel.com/docs/sail
version: '3'

services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
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
mars_dev:
Comment on lines +4 to +17
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

container_name: mars_dev
image: mars_image:latest
pull_policy: never
build:
context: ./docker-dev-setup
depends_on:
- mysql
volumes:
- ".:/workspace/mars"
ports:
- '127.0.0.1:8000:8000'

volumes:
sail-mysql:
driver: local
mars_db:
1 change: 1 addition & 0 deletions docker-dev-setup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN apt-get update \
libzip-dev libpng-dev libonig-dev libcurl4-openssl-dev libxml2-dev \
php8.3-cli php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmath \
texlive-latex-base texlive-latex-extra texlive-lang-european \
make \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Node.js
Expand Down
120 changes: 0 additions & 120 deletions docker-dev-setup/README.md

This file was deleted.

32 changes: 0 additions & 32 deletions docker-dev-setup/docker-compose.yml

This file was deleted.

Loading