Skip to content

Commit e41a937

Browse files
ishikawa999Redmine Patch Meetup
authored andcommitted
Add VSCode devcontainer用の設定を追加 (#82)
* Add VSCode devcontainer用の設定を追加 * Add docker-compose.yml * Move Dockerfile-for-redmine-dev-mirror to .devcontainer/Dockerfile * Fix Rubyのバージョン変更の手順 * Update README.md * Update DockerfileでADDしなくなったことによって機能しなくなっていたコードを削除
1 parent 147579f commit e41a937

14 files changed

+353
-2
lines changed

.devcontainer/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
APP_PORT=8000
2+
SELENIUM_PORT_1=4444
3+
SELENIUM_PORT_2=5900
4+
MAILCATCHER_PORT=1080
5+
RAILS_DB_ADAPTER=postgresql

.devcontainer/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
2+
ARG VARIANT=3.1-bullseye
3+
FROM mcr.microsoft.com/vscode/devcontainers/ruby:${VARIANT}
4+
5+
# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
6+
# The value is a comma-separated list of allowed domains
7+
ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev"
8+
9+
# [Choice] Node.js version: lts/*, 16, 14, 12, 10
10+
ARG NODE_VERSION="lts/*"
11+
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"
12+
13+
# [Optional] Uncomment this section to install additional OS packages.
14+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
15+
&& apt-get -y install --no-install-recommends bzr gsfonts imagemagick libmagick++-dev
16+
17+
EXPOSE $APP_PORT

.devcontainer/create-db-user.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE USER vscode CREATEDB;
2+
CREATE DATABASE vscode WITH OWNER vscode;

.devcontainer/devcontainer.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Update the VARIANT arg in docker-compose.yml to pick a Ruby version
2+
{
3+
"name": "Redmine dev mirror",
4+
"dockerComposeFile": "docker-compose.yml",
5+
"service": "app",
6+
"workspaceFolder": "/workspace",
7+
"shutdownAction": "stopCompose",
8+
// Configure tool-specific properties.
9+
"customizations": {
10+
// Configure properties specific to VS Code.
11+
"vscode": {
12+
// Add the IDs of extensions you want installed when the container is created.
13+
"extensions": [
14+
"rebornix.ruby",
15+
"eamodio.gitlens",
16+
"kaiwood.endwise",
17+
"mtxr.sqltools",
18+
"mtxr.sqltools-driver-pg",
19+
"ms-vsliveshare.vsliveshare"
20+
],
21+
"settings": {
22+
"workbench.colorCustomizations": {
23+
"activityBar.background": "#ab3e3e"
24+
},
25+
"sqltools.connections": [
26+
{
27+
"previewLimit": 50,
28+
"server": "postgresdb",
29+
"port": 5432,
30+
"driver": "PostgreSQL",
31+
"name": "app_development",
32+
"database": "app_development",
33+
"username": "db_user",
34+
"password": "password"
35+
}
36+
]
37+
}
38+
}
39+
},
40+
"postCreateCommand": "bash .devcontainer/scripts/postCreateCommand.sh",
41+
"postStartCommand": "bash .devcontainer/scripts/postStartCommand.sh",
42+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
43+
"remoteUser": "vscode"
44+
}

.devcontainer/docker-compose.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
version: '3'
2+
services:
3+
4+
# PostgreSQL
5+
postgresdb:
6+
image: postgres:14
7+
restart: on-failure:5
8+
volumes:
9+
- ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql
10+
environment:
11+
POSTGRES_USER: postgres
12+
POSTGRES_PASSWORD: postgres
13+
14+
# MySQL
15+
# mysqldb:
16+
# image: mysql:5
17+
# restart: on-failure:5
18+
# environment:
19+
# MYSQL_ROOT_PASSWORD: password
20+
# MYSQL_PASSWORD: password
21+
# MYSQL_USER: db_user
22+
23+
app:
24+
build:
25+
context: ..
26+
dockerfile: .devcontainer/Dockerfile
27+
args:
28+
APP_PORT: $APP_PORT
29+
# Update 'VARIANT' to pick a version of Ruby: 3, 3.1, 3.0, 2, 2.7, 2.6
30+
# Append -bullseye or -buster to pin to an OS version.
31+
# Use -bullseye variants on local arm64/Apple Silicon.
32+
VARIANT: "3.0-bullseye"
33+
# Optional Node.js version to install
34+
NODE_VERSION: "14"
35+
environment:
36+
RAILS_DB_ADAPTER: postgresql
37+
RAILS_DB_HOST: postgresdb
38+
RAILS_DB: app
39+
RAILS_DB_USERNAME: postgres
40+
RAILS_DB_PASSWORD: postgres
41+
RAILS_DB_ENCODING: utf8
42+
RAILS_ENV: development
43+
env_file: .env
44+
tty: true
45+
ports:
46+
- $APP_PORT:3000
47+
depends_on:
48+
- postgresdb
49+
# - mysqldb
50+
command: sleep infinity
51+
volumes:
52+
- ..:/workspace:cached
53+
54+
# For selenium test
55+
# chrome:
56+
# M1の場合はselenium/standalone-chrome-debugが動かないため、seleniarm/standalone-chromium:latestを代わりに使うこと。
57+
# image: selenium/standalone-chrome-debug:3.141.59-20210913
58+
# ports:
59+
# - $SELENIUM_PORT_1:4444
60+
# - $SELENIUM_PORT_2:5900
61+
# shm_size: 2gb
62+
63+
smtp:
64+
image: schickling/mailcatcher
65+
ports:
66+
- $MAILCATCHER_PORT:1080
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Rails server",
6+
"type": "Ruby",
7+
"request": "launch",
8+
"cwd": "${workspaceRoot}",
9+
"program": "${workspaceRoot}/bin/rails",
10+
"args": [
11+
"server",
12+
"-b",
13+
"0"
14+
]
15+
}
16+
]
17+
}

.devcontainer/files/Gemfile.local

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
gem 'pry-rails'
2+
gem 'pry-byebug'
3+
gem 'binding_of_caller'
4+
gem 'better_errors'
5+
gem 'view_source_map'
6+
gem 'parallel_tests'
7+
gem 'benchmark-ips'
8+
gem 'activeresource'
9+
gem 'timecop'
10+
if Gem.ruby_version < Gem::Version.new('3.1.0')
11+
gem 'ruby-debug-ide'
12+
gem 'debase', '~> 0.2.5beta2'
13+
end
14+
if Gem.ruby_version >= Gem::Version.new('2.7.0')
15+
gem 'debug'
16+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# redmine-dev-mirror用ファイル
2+
3+
# ログの保存箇所をvolumesの対象外にして同期による負かを軽くする
4+
config.logger = Logger.new('/logs/redmine.log', 2, 1000000)

.devcontainer/files/configuration.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# redmine-dev-mirror
2+
3+
development:
4+
email_delivery:
5+
delivery_method: :smtp
6+
smtp_settings:
7+
address: 'smtp'
8+
port: 1025
9+
test:
10+
production:

.devcontainer/files/database.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# redmine-dev-mirror
2+
3+
production:
4+
adapter: <%= ENV['RAILS_DB_ADAPTER'] %>
5+
database: <%= ENV['RAILS_DB'] %>
6+
username: <%= ENV['RAILS_DB_USERNAME'] %>
7+
password: <%= ENV['RAILS_DB_PASSWORD'] %>
8+
host: <%= ENV['RAILS_DB_HOST'] %>
9+
encoding: <%= ENV['RAILS_DB_ENCODING'] %>
10+
development:
11+
adapter: <%= ENV['RAILS_DB_ADAPTER'] %>
12+
database: <%= ENV['RAILS_DB'] %>_development
13+
username: <%= ENV['RAILS_DB_USERNAME'] %>
14+
password: <%= ENV['RAILS_DB_PASSWORD'] %>
15+
host: <%= ENV['RAILS_DB_HOST'] %>
16+
encoding: <%= ENV['RAILS_DB_ENCODING'] %>
17+
test:
18+
adapter: <%= ENV['RAILS_DB_ADAPTER'] %>
19+
database: <%= ENV['RAILS_DB'] %>_test
20+
username: <%= ENV['RAILS_DB_USERNAME'] %>
21+
password: <%= ENV['RAILS_DB_PASSWORD'] %>
22+
host: <%= ENV['RAILS_DB_HOST'] %>
23+
encoding: <%= ENV['RAILS_DB_ENCODING'] %>

0 commit comments

Comments
 (0)