diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..fcb5d56c3 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,81 @@ +# Same as production +ARG VARIANT=22.04 +FROM ubuntu:${VARIANT} + +ARG USERNAME=dev +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN apt-get update && apt-get install -y \ + curl \ + xvfb \ + git \ + nano \ + unzip \ + bash-completion \ + less \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Create the user with the same UID/GID as host user +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# Set up NVM and Node.js +ENV NVM_DIR=/usr/local/nvm +ENV NODE_VERSION=v20.16.0 +RUN mkdir -p /usr/local/nvm \ + && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \ + && . $NVM_DIR/nvm.sh \ + && nvm install $NODE_VERSION \ + && nvm alias default $NODE_VERSION \ + && nvm use default \ + && chown -R $USERNAME:$USERNAME $NVM_DIR +ENV NODE_PATH=/usr/local/nvm/versions/node/$NODE_VERSION/bin +ENV PATH=$NODE_PATH:$PATH + +# Set up Bun +USER $USERNAME +WORKDIR /home/$USERNAME +RUN curl -fsSL https://bun.sh/install | bash +ENV BUN_PATH=/home/$USERNAME/.bun +ENV PATH=$BUN_PATH/bin:$PATH + +# Set up bash +RUN echo 'export PS1="\[\e[01;32m\]\u\[\e[m\]:\[\e[01;34m\]\w\[\e[m\]\$ "' >> ~/.bashrc \ + && echo "export PATH=\"$BUN_PATH/bin:\$PATH\"" >> ~/.bashrc \ + && echo 'export NVM_DIR="/usr/local/nvm"' >> ~/.bashrc \ + && echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc + +# Create workspace directory with correct permissions +USER root +RUN mkdir -p /workspace \ + && chown $USERNAME:$USERNAME /workspace + +# Entrypoint script +COPY <<-"EOF" /usr/local/bin/entrypoint.sh +#!/bin/bash +if [ "$1" = "dev" ]; then + # If first argument is "dev", start the dev server with host binding + . ~/.bashrc && exec bun dev --host 0.0.0.0 +else + # Otherwise, forward all arguments to bun + . ~/.bashrc && exec bun "$@" +fi +EOF + +RUN chmod +x /usr/local/bin/entrypoint.sh + +USER $USERNAME +WORKDIR /workspace +ENV CONTAINER=true + +# Verify installations +RUN . ~/.bashrc && bun --version && node --version + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD ["dev"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..c136f2118 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,30 @@ +{ + "name": "Cockpit Development", + "build": { + "dockerfile": "Dockerfile", + "args": { + "USERNAME": "dev", + "USER_UID": "1000", + "USER_GID": "1000" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "dbaeumer.vscode-eslint", + "vue.volar", + "bradlc.vscode-tailwindcss", + "spencerwmiles.vscode-task-buttons" + ], + "settings": { + "task.quickOpen.detail": true, + "task.quickOpen.skip": false, + "terminal.integrated.defaultProfile.linux": "bash" + } + } + }, + "forwardPorts": [5173], + "postCreateCommand": "git submodule update --init --recursive && bun install && exit 0", + "remoteUser": "dev", + "updateRemoteUserUID": true +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..18b7a8d79 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,46 @@ +{ + "VsCodeTaskButtons.showCounter": true, + "VsCodeTaskButtons.tasks": [ + { + "label": "๐Ÿณ Docker", + "task": "๐Ÿ—๏ธ Build Docker Container", + "tooltip": "Build the Docker container", + "hide": "${env:REMOTE_CONTAINERS}" + }, + { + "label": "$(server-process) DevServer", + "task": "๐Ÿš€ Start Dev Server", + "description": "$(debug-start) Start the development server" + }, + { + "label": "$(package) Dependencies", + "tasks": [ + { + "label": "๐Ÿ“ฆ Install Dependencies", + "task": "๐Ÿ“ฆ Install Dependencies", + "description": "$(package) Install project dependencies" + }, + { + "label": "๐Ÿงน Clean Install", + "task": "๐Ÿงน Clean Install", + "description": "$(trash) Remove and reinstall all dependencies" + } + ] + }, + { + "label": "$(tools) Build", + "tasks": [ + { + "label": "๐Ÿ”จ Build Project", + "task": "๐Ÿ”จ Build", + "description": "$(gear) Build the project" + } + ] + }, + { + "label": "$(beaker) Test", + "task": "๐Ÿงช Run Tests", + "tooltip": "๐Ÿงช Run project tests" + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..b02ba3b40 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,91 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "๐Ÿ—๏ธ Build Docker Container", + "type": "shell", + "command": "echo 'Building Docker container...' && docker build -t bun-cockpit-container .devcontainer/ && echo 'โœ… Container built successfully!'", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "shared", + "showReuseMessage": false, + "clear": true + }, + "group": "build", + "options": { + "env": { + "INSIDE_CONTAINER": "${env:REMOTE_CONTAINERS}" + } + }, + "runOptions": { + "runOn": "default" + } + }, + { + "label": "๐Ÿš€ Start Dev Server", + "type": "shell", + "command": "if [ -z \"$CONTAINER\" ]; then docker run -it -v ${workspaceFolder}:/workspace -p 5173:5173 bun-cockpit-container dev; else bun dev --host 0.0.0.0; fi", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "dedicated", + "showReuseMessage": false, + "clear": true, + "close": false + }, + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "๐Ÿ“ฆ Install Dependencies", + "type": "shell", + "command": "if [ -z \"$CONTAINER\" ]; then docker run -v ${workspaceFolder}:/workspace bun-cockpit-container install; else bun install; fi", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "๐Ÿงช Run Tests", + "type": "shell", + "command": "if [ -z \"$CONTAINER\" ]; then docker run -v ${workspaceFolder}:/workspace bun-cockpit-container test; else bun test; fi", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "๐Ÿ”จ Build", + "type": "shell", + "command": "if [ -z \"$CONTAINER\" ]; then docker run -v ${workspaceFolder}:/workspace bun-cockpit-container run build; else bun run build; fi", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "๐Ÿงน Clean Install", + "type": "shell", + "command": "if [ -z \"$CONTAINER\" ]; then docker run -v ${workspaceFolder}:/workspace bun-cockpit-container bash -c \"rm -rf node_modules bun.lockb && bun install\"; else rm -rf node_modules bun.lockb && bun install; fi", + "problemMatcher": [], + "presentation": { + "reveal": "always", + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + } + ] +}