From c1a61f3f9be97825cb26faef580959218740449a Mon Sep 17 00:00:00 2001 From: Nicolas Da Mutten Date: Sat, 25 Mar 2023 14:11:51 +0100 Subject: [PATCH] WIP: add devcontainer --- .devcontainer/devcontainer.json | 49 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 19 +++++++++++++ .devcontainer/initialize.sh | 9 ++++++ .gitignore | 3 ++ app/.gitignore | 1 - app/.vscode/launch.json | 26 +++++++++++++++++ docker-compose.yml | 1 + docker/rails.dockerfile | 21 +++++++++++++- 8 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100755 .devcontainer/initialize.sh delete mode 100644 app/.gitignore create mode 100644 app/.vscode/launch.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..748619b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,49 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-docker-compose +// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml. +{ + "name": "Existing Docker Compose (Extend)", + + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. + "dockerComposeFile": [ + "../docker-compose.yml", + "docker-compose.yml" + ], + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "rails", + + // The optional 'workspaceFolder' property is the path VS Code should open by default when + // connected. This is typically a file mount in .devcontainer/docker-compose.yml + "workspaceFolder": "/usr/src/app", + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line if you want start specific services in your Docker Compose config. + // runServices": [], + + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + "initializeCommand": ".devcontainer/initialize.sh", + + //"postStartCommand": "/usr/local/bin/rails-entrypoint", + + // Uncomment the next line to run commands after the container is created - for example installing curl. + "postCreateCommand": "sudo gem install debug", + + // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. + //"remoteUser": "vscode", + "customizations": { + "vscode": { + "extensions": [ + "KoichiSasada.vscode-rdbg", + "Shopify.ruby-lsp", + "sorbet.sorbet-vscode-extension" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..045930f --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3.4' +services: + rails: + + volumes: + # Update this to wherever you want VS Code to mount the folder of your project + - .:/workspace:cached + + # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details. + # - /var/run/docker.sock:/var/run/docker.sock + + # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. + #cap_add: + # - SYS_PTRACE + #security_opt: + # - seccomp:unconfined + + # Overrides default command so things don't shut down after the process ends. + command: /bin/bash -c "while sleep 1000; do :; done" \ No newline at end of file diff --git a/.devcontainer/initialize.sh b/.devcontainer/initialize.sh new file mode 100755 index 0000000..e69c493 --- /dev/null +++ b/.devcontainer/initialize.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +docker volume create hitobito_bundle +docker volume create hitobito_yarn_cache + +if [ ! -d "app/hitobito" ]; then + mkdir -p app/hitobito + git clone https://github.com/hitobito/hitobito.git app/hitobito +fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6092f1e..2b900de 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ .local .yarnrc /dumps +docker/home/rails +app/* +!app/.vscode \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 72e8ffc..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/app/.vscode/launch.json b/app/.vscode/launch.json new file mode 100644 index 0000000..5462edb --- /dev/null +++ b/app/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Verwendet IntelliSense zum Ermitteln möglicher Attribute. + // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen. + // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "rdbg", + "name": "Debug Server", + "request": "launch", + "script": "bin/rails", + "args": ["server", "-b", "0.0.0.0"], + "useBundler": true, + "cwd": "${workspaceFolder}/hitobito" + }, + { + "type": "rdbg", + "name": "Debug Tests", + "request": "launch", + "script": "bin/rspec", + "useBundler": true, + "askParameters": true, + "cwd": "${workspaceFolder}/hitobito" + } + ] +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8e9514e..5ceee7b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -82,6 +82,7 @@ services: db: image: mysql:5.7 + platform: linux/amd64 command: - --sort_buffer_size=2M - --character-set-server=utf8mb4 diff --git a/docker/rails.dockerfile b/docker/rails.dockerfile index ea11163..c9a156a 100644 --- a/docker/rails.dockerfile +++ b/docker/rails.dockerfile @@ -7,6 +7,9 @@ USER root ENV RAILS_ENV=development ENV RAILS_DB_ADAPTER=mysql2 ENV BUNDLE_PATH=/opt/bundle +ARG USERNAME=hitobito +ARG USER_UID=1000 +ARG USER_GID=$USER_UID WORKDIR /usr/src/app/hitobito @@ -18,10 +21,19 @@ RUN \ python3-pip direnv \ xvfb chromium chromium-driver \ default-mysql-client pv \ - less && \ + less \ + sudo && \ curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash && \ npm install -g yarn +# Create the user +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \ + # + # [Optional] Add sudo support. Omit if you don't need to install software after connecting. + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + RUN bash -c 'gem install bundler -v 2.1.4' COPY ./rails-entrypoint /usr/local/bin @@ -34,5 +46,12 @@ RUN mkdir /home/developer && chmod 777 /home/developer ENV HOME=/home/developer ENV NODE_PATH=/usr/lib/nodejs +# ******************************************************** +# * Anything else you want to do like clean up goes here * +# ******************************************************** + +# [Optional] Set the default user. Omit if you want to keep the default as root. +USER $USERNAME + ENTRYPOINT ["rails-entrypoint"] CMD [ "rails", "server", "-b", "0.0.0.0" ]