diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..18cdf9516 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,25 @@ +FROM partdb-dev:local + +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=${USER_UID} + +RUN groupadd --gid "${USER_GID}" "${USERNAME}" \ + && useradd --uid "${USER_UID}" --gid "${USER_GID}" --create-home --shell /bin/bash "${USERNAME}" \ + && usermod --append --groups www-data "${USERNAME}" \ + && printf '%s ALL=(root) NOPASSWD:ALL\n' "${USERNAME}" > "/etc/sudoers.d/${USERNAME}" \ + && chmod 0440 "/etc/sudoers.d/${USERNAME}" + +COPY .devcontainer/apache-ssl.conf /etc/apache2/sites-available/partdb-dev-ssl.conf + +RUN mkdir -p /etc/apache2/ssl \ + && openssl req -x509 -newkey rsa:2048 -nodes -days 825 \ + -keyout /etc/apache2/ssl/partdb-dev.key \ + -out /etc/apache2/ssl/partdb-dev.crt \ + -subj "/CN=localhost" \ + -addext "subjectAltName=DNS:localhost,IP:127.0.0.1,IP:::1" \ + && chmod 0600 /etc/apache2/ssl/partdb-dev.key \ + && a2enmod ssl \ + && a2ensite partdb-dev-ssl + +EXPOSE 443 diff --git a/.devcontainer/apache-ssl.conf b/.devcontainer/apache-ssl.conf new file mode 100644 index 000000000..207f17f31 --- /dev/null +++ b/.devcontainer/apache-ssl.conf @@ -0,0 +1,25 @@ + + + ServerName localhost + ServerAdmin admin@localhost + DocumentRoot /var/www/html/public + + SSLEngine on + SSLCertificateFile /etc/apache2/ssl/partdb-dev.crt + SSLCertificateKeyFile /etc/apache2/ssl/partdb-dev.key + + + AllowOverride All + Require all granted + + + + + Require all denied + + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + diff --git a/.devcontainer/compose.devcontainer.yaml b/.devcontainer/compose.devcontainer.yaml new file mode 100644 index 000000000..3d103e753 --- /dev/null +++ b/.devcontainer/compose.devcontainer.yaml @@ -0,0 +1,59 @@ +services: + setup: + image: partdb-devcontainer:local + pull_policy: never + user: vscode + entrypoint: [] + working_dir: /var/www/html + environment: + HOME: /home/vscode + COMPOSER_HOME: /home/vscode/.composer + COMPOSER_CACHE_DIR: /home/vscode/.cache/composer + YARN_CACHE_FOLDER: /home/vscode/.cache/yarn + APP_ENV: dev + APP_DEBUG: "1" + DATABASE_URL: "sqlite:///%kernel.project_dir%/var/db/app.db" + APP_SECRET: "partdb-development-secret" + DEFAULT_LANG: en + DEFAULT_TIMEZONE: UTC + BASE_CURRENCY: USD + INSTANCE_NAME: "Part-DB Development" + CHECK_FOR_UPDATES: "0" + USE_GRAVATAR: "0" + ALLOW_ATTACHMENT_DOWNLOADS: "0" + volumes: + - .:/var/www/html + - ./public/media:/var/www/html/public/media + - ./uploads:/var/www/html/uploads + command: + - sh + - -lc + - >- + composer install + && php bin/console about + && yarn install --network-timeout 600000 + && yarn build + && php bin/console doctrine:migrations:migrate --no-interaction + restart: "no" + + partdb: + build: + context: . + dockerfile: .devcontainer/Dockerfile + image: partdb-devcontainer:local + ports: + - "8443:443" + volumes: + - ./public/media:/var/www/html/public/media + - ./uploads:/var/www/html/uploads + depends_on: + setup: + condition: service_completed_successfully + + assets: + volumes: + - ./public/media:/var/www/html/public/media + - ./uploads:/var/www/html/uploads + depends_on: + setup: + condition: service_completed_successfully diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..4be0285ca --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +{ + "name": "Part-DB Development", + "initializeCommand": "docker build --file Dockerfile --tag partdb-local-dev-base . && docker compose --file compose.dev.yaml build partdb", + "dockerComposeFile": [ + "../compose.dev.yaml", + "compose.devcontainer.yaml" + ], + "service": "partdb", + "runServices": [ + "partdb", + "assets" + ], + "workspaceFolder": "/var/www/html", + "remoteUser": "vscode", + "updateRemoteUserUID": true, + "overrideCommand": false, + "shutdownAction": "stopCompose", + "portsAttributes": { + "80": { + "label": "Part-DB HTTP", + "onAutoForward": "ignore" + }, + "443": { + "label": "Part-DB HTTPS", + "onAutoForward": "ignore" + } + } +} diff --git a/.docker/dev/dev-entrypoint.sh b/.docker/dev/dev-entrypoint.sh index c2700b426..ab064a076 100755 --- a/.docker/dev/dev-entrypoint.sh +++ b/.docker/dev/dev-entrypoint.sh @@ -24,7 +24,8 @@ prepare_runtime() "$APP_DIR/uploads" \ "$APP_DIR/public/media" \ "$APP_DIR/public/build" \ - "$APP_DIR/public/bundles" + "$APP_DIR/public/bundles" \ + "$APP_DIR/public/kicad" chown -R www-data:www-data "$DEV_HOME" @@ -39,7 +40,8 @@ prepare_runtime() "$APP_DIR/uploads" \ "$APP_DIR/public/media" \ "$APP_DIR/public/build" \ - "$APP_DIR/public/bundles" + "$APP_DIR/public/bundles" \ + "$APP_DIR/public/kicad" export HOME="$DEV_HOME" export COMPOSER_HOME="$DEV_HOME/.composer" diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 965f9a996..790454cc5 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -67,6 +67,28 @@ git clone https://github.com/Part-DB/Part-DB-server.git cd Part-DB-server ``` +### Visual Studio Code Dev Container + +The first setup can take several minutes. When it finishes, open either: + +``` +http://localhost:8080/ +https://localhost:8443/ +``` + +The HTTPS endpoint uses a self-signed development certificate. Your browser will show a certificate warning until you explicitly accept the certificate or add it to your local trust store. The command-line Docker setup only exposes HTTP. + +During the first database migration an administrator account is created. To retrieve its generated password, open a local terminal and inspect the setup service logs: + +```bash +docker compose -f compose.dev.yaml \ + -f .devcontainer/compose.devcontainer.yaml logs setup +``` + +The automatic setup runs again when the Dev Container is rebuilt. Docker, Composer, and Yarn reuse their caches, and database migrations only apply migrations that have not already run. + +### Command-line Setup + Build the upstream production base image: ```bash