Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devcontainers #62

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ruby:3.1

# Install Rails
RUN gem install rails webdrivers

# 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
ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev,.preview.app.github.dev,.app.github.dev"


# Install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends postgresql-client software-properties-common gnupg tzdata

RUN mkdir -p /etc/apt/keyrings

# Install Chrome
RUN curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /etc/apt/keyrings/google.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/google.gpg] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google.list
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends google-chrome-stable

# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends nodejs

RUN npm install -g yarn@1


# [Optional] Uncomment this line to install additional gems.
# RUN su vscode -c "gem install <your-gem-names-here>"

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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": "Rails",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// 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],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bin/setup",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"GitHub.copilot",
"esbenp.prettier-vscode",
"sianglim.slim",
"Shopify.ruby-lsp",
"KoichiSasada.vscode-rdbg"
]
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
35 changes: 35 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:postgres

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

postgres:
image: postgres:15.1
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
redis:
restart: always
image: redis
network_mode: service:postgres

volumes:
postgres-data:
52 changes: 50 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,61 @@
"configurations": [
{
"type": "rdbg",
"name": "Rails Server",
"name": "RSpec File",
"request": "launch",
"command": "bin/rspec",
"script": "${file}",
"askParameters": false,
"useTerminal": true,
"presentation": {
"group": "2_test"
}
},
{
"type": "rdbg",
"name": "Rails",
"request": "launch",
"command": "bin/rails",
"script": "server",
"args": [],
"askParameters": false,
"useBundler": true
"useBundler": true,
"localfs": true,
"useTerminal": true
},
{
"type": "rdbg",
"name": "Sidekiq",
"request": "launch",
"command": "bin/sidekiq",
"script": "start",
"args": [],
"askParameters": false,
"useBundler": true,
"localfs": true,
"useTerminal": true
},
{
"type": "node",
"request": "launch",
"name": "Assets",
"runtimeExecutable": "yarn",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["build:watch"],
"presentation": {
"hidden": true
}
}
],
"compounds": [
{
"name": "Run App",
"configurations": ["Rails", "Sidekiq", "Assets"],
"stopAll": true,
"presentation": {
"group": "1_dev",
"order": 1
}
}
]
}
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ GEM
net-protocol
newrelic_rpm (8.16.0)
nio4r (2.5.9)
nokogiri (1.14.2-aarch64-linux)
racc (~> 1.4)
nokogiri (1.14.2-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.2-x86_64-darwin)
Expand Down Expand Up @@ -529,6 +531,7 @@ GEM
zeitwerk (2.6.7)

PLATFORMS
aarch64-linux
arm64-darwin-22
x86_64-darwin-21
x86_64-darwin-22
Expand Down
2 changes: 0 additions & 2 deletions app/views/components/_head.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ head
= javascript_include_tag "application", "data-turbo-track": "reload", defer: true

= yield :additional_head_tags if content_for? :additional_head_tags
- if Rails.env.development?
script src="http://localhost:35729/livereload.js?snipver=1"
27 changes: 27 additions & 0 deletions bin/sidekiq
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'sidekiq' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("sidekiq", "sidekiq")
4 changes: 2 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ default: &default
adapter: postgresql
encoding: unicode
host: 127.0.0.1
port: 54313
port: 5432
pool: <%= ENV["DB_POOL"] || ENV["RAILS_MAX_THREADS"] || 5 %>
username: <%= ENV["PG_USER"] || "postgres" %>
username: postgres
variables:
statement_timeout: <%= ENV["STATEMENT_TIMEOUT"] || 60000 %>

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lint:style": "eslint app/javascript/**/*.ts --max-warnings 0",
"lint:format": "prettier --list-different \"app/**/*.{ts,scss,json}\"",
"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",
"build:watch": "yarn build --watch",
"bundle-size": "npx source-map-explorer app/assets/builds/application.js app/assets/builds/application.js.map --no-border-checks",
"start": "yarn build --watch",
"live": "yarn livereload -e scss app/assets"
Expand Down
Loading