Skip to content

Commit

Permalink
WIP: add devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverer committed Mar 25, 2023
1 parent b085e21 commit c1a61f3
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 2 deletions.
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
19 changes: 19 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions .devcontainer/initialize.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
.local
.yarnrc
/dumps
docker/home/rails
app/*
!app/.vscode
1 change: 0 additions & 1 deletion app/.gitignore

This file was deleted.

26 changes: 26 additions & 0 deletions app/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ services:

db:
image: mysql:5.7
platform: linux/amd64
command:
- --sort_buffer_size=2M
- --character-set-server=utf8mb4
Expand Down
21 changes: 20 additions & 1 deletion docker/rails.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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" ]

0 comments on commit c1a61f3

Please sign in to comment.