Skip to content

Commit

Permalink
[WIP] devcontainerあれこれ
Browse files Browse the repository at this point in the history
  • Loading branch information
yonta committed Oct 31, 2024
1 parent e7e7539 commit b099eea
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
10 changes: 7 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM mcr.microsoft.com/devcontainers/ruby:1-3.3-bookworm

# Install Rails
RUN su vscode -c "gem install rails webdrivers"
RUN su vscode -c "/usr/local/rvm/bin/rvm fix-permissions"
RUN su vscode -c "gem install rails webdrivers" \
&& su vscode -c "/usr/local/rvm/bin/rvm fix-permissions"

# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
# The value is a comma-separated list of allowed domains
# The value is a comma-separated list of allowed domains
ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev,.preview.app.github.dev,.app.github.dev"

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends postgresql-client=* \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*

# [Optional] Uncomment this line to install additional gems.
# RUN su vscode -c "gem install <your-gem-names-here>"
Expand Down
17 changes: 15 additions & 2 deletions .devcontainer/docker-compose.yml → .devcontainer/compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
app:
Expand All @@ -7,6 +7,17 @@ services:
dockerfile: .devcontainer/Dockerfile

volumes:
# - ../app:/workspaces/sakazuki/app:cached
# - ../config:/workspaces//sakazuki/config:cached
# - ../bin:/workspaces//sakazuki/bin:cached
# - ../config.ru:/workspaces//sakazuki/config.ru:cached
# - ../Rakefile:/workspaces//sakazuki/Rakefile:cached
# - ../lib:/workspaces//sakazuki/lib:cached
# - ../db:/workspaces//sakazuki/db:cached
# - ../spec:/workspaces//sakazuki/spec:cached
# - ../public:/workspaces//sakazuki/public:cached
# - uploads:/workspaces//sakazuki/app/public/uploads:consistent
# - builds:/workspaces//sakazuki/app/assets/builds:consistent
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
Expand All @@ -27,7 +38,7 @@ services:
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PASSWORD: password
# Your config/database.yml should use the user and password you set here,
# and host "db" (as that's the name of this service). You can use whatever
# database name you want. Use `bin/rails db:prepare` to create the database.
Expand All @@ -40,6 +51,8 @@ services:
# username: postgres
# password: postgres
# database: myapp_development
ports:
- "5432:5432"

# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
Expand Down
51 changes: 24 additions & 27 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby-rails-postgres
{
"name": "Ruby on Rails & Postgres",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"installYarnUsingApt": true,
"version": "lts",
"pnpmVersion": "none",
"nvmVersion": "latest"
},
"ghcr.io/devcontainers-extra/features/typescript:2": {
"version": "latest"
}
}
"name": "SAKAZUKI",
"dockerComposeFile": "compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-extra/features/ts-node:1": {},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
// "forwardPorts": [3000, 5432],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
// "forwardPorts": [3000, 5432],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "bundle install && rake db:setup",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bundle install && bundle exec rails db:setup && yarn install",

// Configure tool-specific properties.
// "customizations": {},
// Use 'postAttachCommand' to run commands after the container is started.
"postStartCommand": "bundle install && yarn install"

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
// Use 'postAttachCommand' to run commands after the container is attached.
// "postAttachCommand": "bundle install && yarn install"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}

0 comments on commit b099eea

Please sign in to comment.