Skip to content

Commit

Permalink
ci: Github Codespaces configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmechlark committed Feb 13, 2024
1 parent a26fcd0 commit b02ef1e
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 61 deletions.
52 changes: 52 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/ruby/.devcontainer/base.Dockerfile

# [Choice] Ruby version: 3, 3.3, 3.2, 3.1, 3.0, 2, 2.7, 2.6
ARG VARIANT="2"
FROM mcr.microsoft.com/devcontainers/ruby:${VARIANT}

# 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"

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
postgresql-client \
postgresql-contrib \
libpq-dev

# Install MongoDB Shell
ARG MONGOSH_VERSION="2.1.4"
RUN ARCH=$(dpkg --print-architecture) \
&& if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "arm64" ]; then \
wget -qO /tmp/mongosh.deb "https://downloads.mongodb.com/compass/mongodb-mongosh_${MONGOSH_VERSION}_${ARCH}.deb" \
&& apt-get install -y /tmp/mongosh.deb \
&& rm -rf /tmp/*; \
fi

# Install supported Ruby versions
# https://www.ruby-lang.org/en/downloads/releases/
RUN /bin/bash -c "source /usr/local/rvm/scripts/rvm \
&& rvm install 2.7.8 \
&& rvm install 3.0.6 \
&& rvm install 3.1.4 \
&& rvm install 3.2.3 \
&& rvm install 3.3.0"

# Set the default bundle path
ENV BUNDLE_PATH=/usr/local/bundle

# Install gem dependencies
RUN mkdir -p /tmp/gem/lib/devise/auth0
COPY gemfiles /tmp/gem/gemfiles
COPY lib/devise/auth0/version.rb /tmp/gem/lib/devise/auth0
COPY Appraisals devise_auth0.gemspec Gemfile Gemfile.lock /tmp/gem/
RUN mkdir -p ${BUNDLE_PATH} \
&& gem install bundler:2.4.21 \
&& cd /tmp/gem \
&& bundle install --jobs=3 --retry=3 \
&& bundle exec appraisal install \
&& rm -rf /tmp/gem
VOLUME ["/usr/local/bundle"]

RUN chown -R vscode:vscode /usr/local/rvm ${BUNDLE_PATH}
9 changes: 9 additions & 0 deletions .devcontainer/boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo chown -R vscode:vscode ${BUNDLE_PATH} && \
bundle install --jobs=3 --retry=3 && \
bundle exec appraisal install

# Rebuild PostgreSQL
dropdb --if-exists devise_auth0_test
dropdb --if-exists devise_auth0_development
createdb -E UTF8 -T template0 devise_auth0_test --lc-collate en_US.UTF-8
createdb -E UTF8 -T template0 devise_auth0_development --lc-collate en_US.UTF-8
47 changes: 20 additions & 27 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// 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/typescript-node
// 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": "Devise Auth0",
"image": "mcr.microsoft.com/devcontainers/ruby:3-bullseye",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/java:latest": {},
"ghcr.io/devcontainers/features/github-cli:latest": {},
"ghcr.io/devcontainers/features/git-lfs:latest": {},
"ghcr.io/devcontainers/features/ruby:latest": {
"version": "3.2"
},
"ghcr.io/itsmechlark/features/trivy": {}
"ghcr.io/devcontainers/features/java:latest": {},
"ghcr.io/itsmechlark/features/trivy:latest": {}
},

"containerEnv": {
"PGHOST": "postgres",
"PGUSER": "postgres",
"PGPASSWORD": "postgres",
"DATABASE_URL": "postgres://postgres:postgres@postgres:5432/devise_auth0_test",
"MONGODB_URI": "mongodb://mongodb:mongodb@mongodb:27017"
},
"mounts": [
"type=volume,target=${containerWorkspaceFolder}/coverage",
"type=volume,target=${containerWorkspaceFolder}/vendor/bundle"
],
"runArgs": [
"--env-file",
".env"
],

"postCreateCommand": ".devcontainer/boot.sh",

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
Expand All @@ -37,19 +36,13 @@
"rebornix.Ruby",
"shopify.ruby-lsp",
"visualstudioexptteam.vscodeintellicode",
"ms-vsliveshare.vsliveshare"
"ms-vsliveshare.vsliveshare",
"ms-azuretools.vscode-docker"
]
}
},

"remoteEnv": {
"BUNDLE_PATH": "${containerWorkspaceFolder}/vendor/bundle"
},

"onCreateCommand": "sudo chown -R vscode:vscode ${containerWorkspaceFolder}/coverage ${containerWorkspaceFolder}/vendor/bundle",
"postStartCommand": "gem install bundler:2.3.6 && bundle install --jobs=3 --retry=3",

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

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

volumes:
- ../..:/workspaces:cached
- bundle-data:/usr/local/bundle

# 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.
networks:
- default

depends_on:
- mongodb
- postgres

mongodb:
image: mongodb/mongodb-community-server
restart: unless-stopped
networks:
- default
volumes:
- mongodb-data:/data/db
environment:
MONGODB_INITDB_ROOT_USERNAME: mongodb
MONGODB_INITDB_ROOT_PASSWORD: mongodb

postgres:
image: postgres:latest
restart: unless-stopped
networks:
- default
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres

networks:
default:

volumes:
bundle-data:
mongodb-data:
postgres-data:
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "6-1-stable"

gem "ruby-lsp", require: false
platforms :ruby do
gem "sqlite3"
end
Expand Down
38 changes: 11 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,19 @@ GEM
dotenv (2.8.1)
drb (2.2.0)
ruby2_keywords
dry-configurable (1.1.0)
dry-configurable (1.0.1)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-core (1.0.1)
dry-core (1.0.0)
concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6)
erubi (1.12.0)
faker (3.2.2)
i18n (>= 1.8.11, < 2)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday (2.0.0)
ruby2_keywords (>= 0.0.4)
faraday-http-cache (2.5.1)
faraday (>= 0.8)
faraday-net_http (3.1.0)
net-http
faraday-retry (2.2.0)
faraday (~> 2.0)
globalid (1.2.1)
Expand Down Expand Up @@ -195,8 +193,6 @@ GEM
multi_xml (0.6.0)
multipart-parser (0.1.1)
mutex_m (0.2.0)
net-http (0.4.1)
uri
net-imap (0.4.9.1)
date
net-protocol
Expand All @@ -208,16 +204,16 @@ GEM
net-protocol
netrc (0.11.0)
nio4r (2.7.0)
nokogiri (1.16.2)
nokogiri (1.15.5)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.2-aarch64-linux)
nokogiri (1.15.5-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.2-arm64-darwin)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.2-x86_64-darwin)
nokogiri (1.15.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.2-x86_64-linux)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
Expand All @@ -244,7 +240,6 @@ GEM
parser (3.2.2.3)
ast (~> 2.4.1)
racc
prism (0.19.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -332,10 +327,6 @@ GEM
rubocop-factory_bot (~> 2.22)
rubocop-shopify (2.14.0)
rubocop (~> 1.51)
ruby-lsp (0.13.4)
language_server-protocol (~> 3.17.0)
prism (>= 0.19.0, < 0.20)
sorbet-runtime (>= 0.5.10782)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.22.0)
Expand All @@ -348,27 +339,21 @@ GEM
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
sorbet-runtime (0.5.11219)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.7.1)
sqlite3 (1.7.2)
mini_portile2 (~> 2.8.0)
sqlite3 (1.7.1-aarch64-linux)
sqlite3 (1.7.1-arm64-darwin)
sqlite3 (1.7.1-x86_64-darwin)
sqlite3 (1.7.1-x86_64-linux)
thor (1.3.0)
timecop (0.9.8)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
uri (0.13.0)
vcr (6.2.0)
version_gem (1.1.3)
warden (1.2.9)
Expand Down Expand Up @@ -410,7 +395,6 @@ DEPENDENCIES
rubocop-rake
rubocop-rspec
rubocop-shopify (~> 2.14)
ruby-lsp
simplecov (>= 0.21.2)
simplecov-lcov
sqlite3
Expand All @@ -419,4 +403,4 @@ DEPENDENCIES
webmock (~> 3.4)

BUNDLED WITH
2.3.6
2.4.21
1 change: 0 additions & 1 deletion gemfiles/rails_5.2_stable.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "5-2-stable"
gem "ruby-lsp", require: false

platforms :ruby do
gem "sqlite3", "~> 1.3.6"
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_6.0_stable.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "6-0-stable"
gem "ruby-lsp", require: false

platforms :ruby do
gem "sqlite3", "~> 1.4"
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_6.1_stable.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "6-1-stable"
gem "ruby-lsp", require: false
gem "rspec-rails", "~> 6.0"

platforms :ruby do
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_7.0_stable.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "7-0-stable"
gem "ruby-lsp", require: false
gem "responders", "~> 3.0"
gem "rspec-rails", "~> 6.0"

Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_7.1_stable.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "7-1-stable"
gem "ruby-lsp", require: false
gem "responders", "~> 3.0"
gem "rspec-rails", "~> 6.0"

Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: :main
gem "ruby-lsp", require: false
gem "responders", "~> 3.0"
gem "rspec-rails", "~> 6.0"

Expand Down

0 comments on commit b02ef1e

Please sign in to comment.