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

Feature: Added Github codespaces configurations #1541 #1557

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b5c331b
Add VSCode codespace support for dev enviroment
akhilgkrishnan Oct 11, 2023
86b329e
VSCode settings added
akhilgkrishnan Oct 11, 2023
160d3ef
Elasticport added
akhilgkrishnan Oct 11, 2023
78af86c
Intendation fix
akhilgkrishnan Oct 11, 2023
b084360
Docker compose fix
akhilgkrishnan Oct 11, 2023
944b14a
Docker compose fix
akhilgkrishnan Oct 11, 2023
1744671
fix container
akhilgkrishnan Oct 11, 2023
318d9bd
feature(devcontainer): updated devcontainer configurations
Shrest4647 Oct 19, 2023
f6a2f68
feat(docker): Updated the docker files
Shrest4647 Oct 19, 2023
5c22004
fix(file): fix for the file encoding problem with lf and crlf
Shrest4647 Oct 19, 2023
4e21fb1
fix(db): get db host from env
Shrest4647 Oct 19, 2023
bcea023
fix(docker): remove args from compose
Shrest4647 Oct 19, 2023
7bab963
fix(db): removing the port mapping
Shrest4647 Oct 19, 2023
cacc9ed
fix(compose): remove the network mode
Shrest4647 Oct 19, 2023
9965bfe
fix(devcontainer): reorderd start command
Shrest4647 Oct 19, 2023
5bc7728
fix(devcontainer): removing all post install commands
Shrest4647 Oct 19, 2023
c33cca6
fix(devcontainer): added post attach command
Shrest4647 Oct 19, 2023
fadaf0b
fix(docker): updated the mount folder
Shrest4647 Oct 19, 2023
665bc2a
fix(devcontainer): playing with install order
Shrest4647 Oct 19, 2023
efb916d
chore(devcontainer): running clean ups
Shrest4647 Oct 19, 2023
3655623
Merge branch 'develop' into feature/codespaces-configurations
Shrest4647 Oct 19, 2023
cb96337
feat(codespaces): configuration to allow requests from the codespaces…
Shrest4647 Oct 19, 2023
437025a
Merge branch 'feature/codespaces-configurations' of https://github.co…
Shrest4647 Oct 19, 2023
2e04aca
Merge branch 'develop' into feature/codespaces-configurations
Shrest4647 Oct 19, 2023
b14e7cb
chore(script): deleted the unused script file
Shrest4647 Oct 19, 2023
7446234
Merge branch 'feature/codespaces-configurations' of https://github.co…
Shrest4647 Oct 19, 2023
1b026dc
Rubocop fix
akhilgkrishnan Oct 19, 2023
1c94061
Fixed actiondispatch issue and added base url
akhilgkrishnan Oct 19, 2023
dde5039
Removed deprecated the extensions
akhilgkrishnan Oct 19, 2023
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
71 changes: 71 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#syntax=docker/dockerfile:1
ARG VARIANT=3.2
FROM mcr.microsoft.com/vscode/devcontainers/ruby:${VARIANT} AS base

# Update args in docker-compose.yaml to set the UID/GID of the "vscode" user.
# ARG USER_UID=1000
# ARG USER_GID=$USER_UID
# RUN if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
# groupmod --gid $USER_GID vscode \
# && usermod --uid $USER_UID --gid $USER_GID vscode \
# && chmod -R $USER_UID:$USER_GID /home/vscode; \
# fi

ARG NODE_VERSION=18.14.2

ENV BUNDLE_PATH="/usr/local/bundle"
ENV GEM_HOME="/usr/local/bundle/gems"
ENV GEM_PATH="/usr/local/bundle/gems"

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

RUN apt-get update && apt-get install -y --no-install-recommends curl gnupg2 && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
curl -sL https://deb.nodesource.com/setup_lts.x | bash - && \
apt-get install -y --no-install-recommends nodejs yarn && \
npm --version && \
apt-get clean && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*


RUN curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update && apt-get install google-chrome-stable -y --no-install-recommends postgresql-client && \
apt-get clean && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

# Install gh
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh


FROM base AS build-deps

RUN apt-get update && apt-get install -y --no-install-recommends git build-essential libpq-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*


FROM build-deps AS gems

RUN gem install bundler -v 2.3.11

COPY Gemfile Gemfile.lock ./

RUN bundle install && rm -rf vendor/bundle/ruby/*/cache

FROM base AS node_modules

COPY package.json yarn.lock ./

RUN yarn install --check-files

FROM base


COPY --from=gems /app /app
COPY --from=gems /usr/local/bundle /usr/local/bundle
COPY --from=node_modules /app/node_modules /app/node_modules
COPY . ./
64 changes: 64 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
Copy link
Member

@akhilgkrishnan akhilgkrishnan Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the indentation is correct for this page. Use 2 spaces?

// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Miru Web Codespace",
// 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",
// 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": "app",
// 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": "/app",
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"customizations": {
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"Shopify.ruby-lsp",
"misogi.ruby-rubocop",
"davidpallinder.rails-test-runner",
"eamodio.gitlens",
"github.copilot",
"mrmlnc.vscode-duplicate"
],
"settings": {
"terminal.integrated.shell.linux": "/bin/zsh"
}
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
3000,
3035,
9200
],
// 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",
// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "",
"postAttachCommand": "bundle exec rails s -p 3000 -b 0.0.0.0 && bundle exec rails db:prepare",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
"remoteEnv": {
"APP_BASE_URL": "${localEnv:CODESPACE_NAME}-3000.${localEnv:GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}",
},

"remoteUser": "root",
"portsAttributes": {
"3000": {
"label": "Rails Server"
},
"3035": {
"label": "Webpack Dev Server"
},
"9200": {
"label": "Elasticsearch"
}
}
}
126 changes: 126 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
version: "3.9"
services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
# command: bash -c "bundle install && bundle exec rails db:prepare && bundle exec rails s -p 3000 -b 0.0.0.0" || sleep infinity
# Overrides default command so things don't shut down after the process ends.
command: sleep infinity
ports:
- "3000:3000"
image: miru-web:latest
working_dir: /app
volumes:
- ../:/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/app/node_modules
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
- DATABASE_URL=postgres://postgres:postgres@database:5432/
- DB_HOST=database
- DB_USER=postgres
- DB_PASS=postgres
- DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL="true"
- POSTGRES_PASSWORD="postgres"
- POSTGRES_USER="postgres"
- REDIS_URL=redis://redis:6379/1
- ELASTICSEARCH_URL=http://elastic:x2Sy5FK51zu@elasticsearch:9200
- PIDFILE=/tmp/pids/server.pid
depends_on:
- database
- redis
- elasticsearch
tmpfs:
- /tmp/pids/
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
# network_mode: service:database
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

database:
image: postgres:13.8
restart: unless-stopped
# ports:
# - "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
# 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.
#
# Example:
#
# development:
# <<: *default
# host: db
# username: postgres
# password: postgres
# database: myapp_development

# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
redis:
image: redis:6.2.7
command: redis-server
restart: always
ports:
- "6379:6379"
volumes:
- redis:/data

webpack:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
command: bin/webpacker-dev-server
image: miru-web:latest
ports:
- "3035:3035"
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
- DATABASE_URL=postgres://postgres:postgres@database:5432/
- DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL="true"
- POSTGRES_PASSWORD="postgres"
- POSTGRES_USER="postgres"
- REDIS_URL=redis://redis:6379/1
- ELASTICSEARCH_URL=http://elastic:x2Sy5FK51zu@elasticsearch:9200
depends_on:
- database

sidekiq:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
command: bundle exec sidekiq -C config/sidekiq.yml
volumes:
- ..:/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/app/node_modules
environment:
- DATABASE_URL=postgres://postgres:postgres@database:5432/
- REDIS_URL=redis://redis:6379/1
depends_on:
- redis
- database
- app

elasticsearch:
image: elasticsearch:7.13.3
environment:
discovery.type: single-node
network.host: 0.0.0.0
xpack.security.enabled: "true"
ELASTIC_PASSWORD: "x2Sy5FK51zu"
ports:
- "9200:9200"

volumes:
gem_cache:
postgres:
node_modules:
redis:
42 changes: 22 additions & 20 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"[ruby]": {
"editor.autoClosingBrackets": "beforeWhitespace",
"editor.formatOnSave": true,
"editor.defaultFormatter": "rebornix.ruby"
},
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"[ruby]": {
"editor.autoClosingBrackets": "beforeWhitespace",
"editor.formatOnSave": true,
"yaml.format.enable": true,
"ruby.useBundler": true, //run non-lint commands with bundle exec
"ruby.useLanguageServer": true, // use the internal language server (see below)
"ruby.lint": {
"rubocop": {
"useBundler": true,
"lint": true, // enable lint cops
"rails": true // requires rubocop-rails gem for RuboCop >= 0.72.0
}
},
"ruby.format": "rubocop",
"ruby.intellisense": "rubyLocate"
}
"editor.defaultFormatter": "rebornix.ruby",
"editor.tabSize": 2,
},
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"editor.formatOnSave": true,
"yaml.format.enable": true,
"ruby.useBundler": true, //run non-lint commands with bundle exec
"ruby.useLanguageServer": true, // use the internal language server (see below)
"ruby.lint": {
"rubocop": {
"useBundler": true,
"lint": true, // enable lint cops
"rails": true // requires rubocop-rails gem for RuboCop >= 0.72.0
}
},
"ruby.format": "rubocop",
"ruby.intellisense": "rubyLocate",
"files.eol": "\n"
}
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default: &default
adapter: postgresql
encoding: unicode
host: localhost
host: <%= ENV.fetch("DB_HOST") { "localhost" } %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
user: <%= ENV.fetch("DB_USER") { "" } %>
password: <%= ENV.fetch("DB_PASS") { "" } %>
Expand Down
10 changes: 10 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@
end

config.serve_static_assets = true

if ENV["CODESPACES"] == "true"
codespace_domain = ENV["GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN"]
codespace_host = "#{ENV['CODESPACE_NAME']}-3000.#{codespace_domain}"
config.hosts << codespace_host

config.action_dispatch.default_headers = {
"X-Frame-Options" => "ALLOW-FROM #{codespace_domain}"
}
end
end