Skip to content

Commit

Permalink
Merge pull request #306 from tarebyte/tarebyte/create-devcontainer
Browse files Browse the repository at this point in the history
Add a Development Container for a more seamless local experience
  • Loading branch information
tarebyte authored Jul 19, 2023
2 parents 4f6e282 + aeafd94 commit 662b9e3
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 160 deletions.
50 changes: 50 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM mcr.microsoft.com/devcontainers/base:jammy

ENV DEBIAN_FRONTEND noninteractive
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

# disable installing recommended packages to save space
RUN echo "APT::Install-Recommends \"false\";" > /etc/apt/apt.conf

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
build-essential \
libffi-dev \
libjemalloc-dev \
libpq-dev \
libreadline-dev \
libssl-dev \
libxml2-dev \
libxslt-dev \
libyaml-dev \
python2 \
shared-mime-info \
tmux \
zlib1g-dev && \
apt-get autoremove -y

# Install Overmind to run multiple processes at once.
RUN curl --fail --location --output /usr/bin/overmind.gz "https://github.com/DarthSim/overmind/releases/download/v2.4.0/overmind-v2.4.0-linux-$(dpkg --print-architecture).gz" && \
curl --fail --location --output /tmp/overmind.gz.sha256sum "https://github.com/DarthSim/overmind/releases/download/v2.4.0/overmind-v2.4.0-linux-$(dpkg --print-architecture).gz.sha256sum" && \
echo $(cat /tmp/overmind.gz.sha256sum) /usr/bin/overmind.gz | sha256sum --check --status && \
gunzip /usr/bin/overmind.gz && \
chmod +x /usr/bin/overmind

# Run as the target user
# Uses the username created by the VSCode devcontainer Ubuntu base image
USER vscode
ENV USER=vscode

COPY ../.ruby-version /tmp/.ruby-version

RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv
RUN git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
RUN ~/.rbenv/bin/rbenv install $(cat /tmp/.ruby-version)

ENV OVERMIND_SOCKET=/tmp/.overmind.sock

# https://github.com/devcontainers/templates/blob/4653d4cd09e27c57b3a03969e7d9cb8de313df19/src/ruby-rails-postgres/.devcontainer/Dockerfile#L6C1-L8C89
# 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"
69 changes: 69 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "Soulmedicine",
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
"service": "workspace",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"postCreateCommand": ".devcontainer/post-create-command.sh",
"forwardPorts": [
1025,
1080,
3000,
5432,
6379,
6380
],
"portsAttributes": {
"1025": {
"label": "Mailcatcher - 1"
},
"1080": {
"label": "Mailcatcher - 2"
},
"3000": {
"label": "Web"
},
"5432": {
"label": "PostgreSQL"
},
"6379": {
"label": "Redis - Sidekiq"
},
"6380": {
"label": "Redis - Caching"
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": true,
"nonFreePackages": true
},
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
"version": "latest"
},
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "10.13"
},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
"plugins": "git npm nvm rbenv ssh-agent zsh-autosuggestions",
"omzPlugins": "https://github.com/zsh-users/zsh-autosuggestions"
}
},
"customizations": {
"vscode": {
"extensions": [
"kaiwood.endwise",
"LoranKloeze.ruby-rubocop-revived",
"ms-azuretools.vscode-docker",
"ms-vscode-remote.remote-containers",
"rebornix.Ruby"
]
}
}
}
17 changes: 17 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.7'

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

environment:
DATABASE_HOST: postgres
REDIS_URL: redis://redis-sidekiq:6379
REDIS_CACHE_URL: redis://redis-cache:6380

volumes:
- ..:/workspaces:cached

command: /bin/sh -c "while sleep 1000; do :; done"
37 changes: 37 additions & 0 deletions .devcontainer/post-create-command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e

# Create .env.local with defaults if it doesn't already exist.
if [ ! -f .env.local ]
then
touch .env.local

cat <<EOT >> .env.local
# Only necessary for devcontainers
REDIS_URL="redis://redis-sidekiq:6379"
REDIS_CACHE_URL="redis://redis-cache:6380"
STORYBLOK_TOKEN="..."
# Firebase Authentication
FIREBASE_PROJECT_ID="..."
FIREBASE_API_KEY="..."
# Rollbar (only if you want to test errors are being reported locally)
# SERVER_ROLLBAR_ACCESS_TOKEN="..." # Identified on rollbar as post_server_item
# CLIENT_ROLLBAR_ACCESS_TOKEN="..." # Identified on rollbar as post_client_item
# ROLLBAR_ENV=dev
GOOGLE_ANALYTICS_ID="..."
EOT
fi

gem install bundler:1.17.3
rbenv rehash

npm update -g npm
npm install -g yarn

./bin/setup
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ DATABASE_PASSWORD=sm_password

DATABASE_NAME=soulmedicine

REDIS_URL="redis://localhost:6379"

REDIS_CACHE_URL="redis://localhost:6380"

ENABLED_LOCALES="en,fr,de,ur,ar"

ADMIN_BASIC_AUTH="admin:password"
Expand All @@ -25,6 +21,10 @@ CONTENT_PREVIEW_MODE=true
# ------------------------------------------------------------------------------
# Set these in your .env.local

# Only necessary if not running in a devcontainer
# REDIS_URL="redis://localhost:6379"
# REDIS_CACHE_URL="redis://localhost:6380"

# STORYBLOK_TOKEN="..."

# Firebase Authentication
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Metrics/ClassLength:
Exclude:
- "spec/**/*"

Metrics/LineLength:
Layout/LineLength:
Max: 150

Metrics/MethodLength:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.7.8
2.7.8
26 changes: 26 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "bin/server - run the server",
"type": "shell",
"command": "./bin/server",
"group": "build",
"presentation": {
"panel": "dedicated",
}
},
{
"label": "bundle exec rspec - run the tests",
"type": "shell",
"command": "bundle exec rspec",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": []
}
]
}
3 changes: 3 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web: bundle exec puma -C config/puma.rb -p 3000
worker: bundle exec sidekiq -c 1
webpack-dev-server: bin/webpack-dev-server
Loading

0 comments on commit 662b9e3

Please sign in to comment.