From e576930c8ee59bae644eb427c2ac6f122fc9c409 Mon Sep 17 00:00:00 2001 From: Nicolas Da Mutten Date: Sat, 25 Mar 2023 22:59:05 +0100 Subject: [PATCH] WIP: multiple containers --- .devcontainer/create.sh | 3 ++ .devcontainer/devcontainer.json | 49 ------------------------- .devcontainer/docker-compose.yml | 14 +------ .devcontainer/generic/devcontainer.json | 40 ++++++++++++++++++++ .devcontainer/initialize.sh | 26 +++++++++++-- .devcontainer/pbs/devcontainer.json | 40 ++++++++++++++++++++ .devcontainer/update.sh | 21 +++++++++++ docker/rails.dockerfile | 10 ++--- 8 files changed, 131 insertions(+), 72 deletions(-) create mode 100644 .devcontainer/create.sh delete mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/generic/devcontainer.json create mode 100644 .devcontainer/pbs/devcontainer.json create mode 100644 .devcontainer/update.sh diff --git a/.devcontainer/create.sh b/.devcontainer/create.sh new file mode 100644 index 0000000..f44e421 --- /dev/null +++ b/.devcontainer/create.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo gem install debug \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 748619b..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,49 +0,0 @@ -// 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 index 0e32ced..3e4d1af 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,20 +1,10 @@ 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. + # Skip entrypoint which would try to migrate on entry entrypoint: [] + # 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/generic/devcontainer.json b/.devcontainer/generic/devcontainer.json new file mode 100644 index 0000000..e0cf722 --- /dev/null +++ b/.devcontainer/generic/devcontainer.json @@ -0,0 +1,40 @@ +// 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": "Hitobito Generic", + + "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", + + "workspaceFolder": "/usr/src/app", + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 3000, + 1080, + 3306 + ], + + "initializeCommand": ".devcontainer/initialize.sh https://github.com/hitobito/hitobito.git https://github.com/hitobito/hitobito_generic.git", + + "onCreateCommand": ".devcontainer/create.sh", + + "updateContentCommand": ".devcontainer/update.sh", + + "customizations": { + "vscode": { + "extensions": [ + "KoichiSasada.vscode-rdbg", + "Shopify.ruby-lsp", + "sorbet.sorbet-vscode-extension" + ] + } + } +} diff --git a/.devcontainer/initialize.sh b/.devcontainer/initialize.sh index e69c493..d8300c9 100755 --- a/.devcontainer/initialize.sh +++ b/.devcontainer/initialize.sh @@ -3,7 +3,25 @@ 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 +# Check if an argument was provided +if [ $# -eq 0 ] +then + echo "Usage: $0 url1 url2 url3 ..." + exit 1 +fi + +if [ -d "app/hitobito" ]; then + exit 0 +fi + +# Create the app directory if it doesn't exist +mkdir -p app + +# Loop over the URLs and clone each repository into the app directory +for url in "$@" +do + echo "Cloning $url into app/$(basename $url .git)" + git clone "$url" "app/$(basename $url .git)" +done + +/usr/local/bin/rails-entrypoint exit 0 \ No newline at end of file diff --git a/.devcontainer/pbs/devcontainer.json b/.devcontainer/pbs/devcontainer.json new file mode 100644 index 0000000..6dad884 --- /dev/null +++ b/.devcontainer/pbs/devcontainer.json @@ -0,0 +1,40 @@ +// 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": "Hitobito PBS", + + "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", + + "workspaceFolder": "/usr/src/app", + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 3000, + 1080, + 3306 + ], + + "initializeCommand": ".devcontainer/initialize.sh https://github.com/hitobito/hitobito.git https://github.com/hitobito/hitobito_youth.git https://github.com/hitobito/hitobito_pbs.git", + + "onCreateCommand": ".devcontainer/create.sh", + + "updateContentCommand": ".devcontainer/update.sh", + + "customizations": { + "vscode": { + "extensions": [ + "KoichiSasada.vscode-rdbg", + "Shopify.ruby-lsp", + "sorbet.sorbet-vscode-extension" + ] + } + } +} diff --git a/.devcontainer/update.sh b/.devcontainer/update.sh new file mode 100644 index 0000000..e2f3876 --- /dev/null +++ b/.devcontainer/update.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Set the directory containing git repositories +repositories_dir=app + +# Loop over the directories in the repositories directory +for repository_dir in "$repositories_dir"/*/ +do + # Check if the directory is a git repository + if [ -d "$repository_dir/.git" ] + then + # Change into the repository directory, discard all local changes, and pull the latest changes + cd "$repository_dir" + echo "Updating repository: $(basename $repository_dir)" + git reset --hard HEAD + git clean -f -d + git pull + fi +done + +SKIP_SEEDS=1 SKIP_WAGONFILE=1 /usr/local/bin/rails-entrypoint exit 0 \ No newline at end of file diff --git a/docker/rails.dockerfile b/docker/rails.dockerfile index c9a156a..6dc57ce 100644 --- a/docker/rails.dockerfile +++ b/docker/rails.dockerfile @@ -43,15 +43,11 @@ COPY ./waitfortcp /usr/local/bin RUN mkdir /opt/bundle && chmod 777 /opt/bundle RUN mkdir /seed && chmod 777 /seed 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 +ENV HOME=/home/developer +ENV NODE_PATH=/usr/lib/nodejs + ENTRYPOINT ["rails-entrypoint"] CMD [ "rails", "server", "-b", "0.0.0.0" ]