Skip to content

Commit

Permalink
WIP: multiple containers
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverer committed Mar 25, 2023
1 parent d7bfb61 commit f92c602
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sudo gem install debug
49 changes: 0 additions & 49 deletions .devcontainer/devcontainer.json

This file was deleted.

14 changes: 2 additions & 12 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
40 changes: 40 additions & 0 deletions .devcontainer/generic/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
26 changes: 22 additions & 4 deletions .devcontainer/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
40 changes: 40 additions & 0 deletions .devcontainer/pbs/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
21 changes: 21 additions & 0 deletions .devcontainer/update.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 2 additions & 7 deletions docker/rails.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,13 @@ COPY ./rails-entrypoint /usr/local/bin
COPY ./webpack-entrypoint /usr/local/bin
COPY ./waitfortcp /usr/local/bin

USER $USERNAME

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

ENTRYPOINT ["rails-entrypoint"]
CMD [ "rails", "server", "-b", "0.0.0.0" ]

0 comments on commit f92c602

Please sign in to comment.