1
0
Fork 0
forked from OpenNeo/impress

[WIP] Build a dev container

Idk why, but unlike my previous experience with Rails devcontainers, this time the setup process is running so wildly slowly?

Might just be a transient issue on my machine, maybe something that would be improved with a restart and trying again another time? Or could be something about the MySQL image that doesn't run great in this context?

In any case, I'm just gonna set this down for now!
This commit is contained in:
Emi Matchu 2023-08-29 11:39:12 -07:00
parent 8034e8689a
commit 2f3294b899
7 changed files with 106 additions and 4 deletions

15
.devcontainer/Dockerfile Normal file
View file

@ -0,0 +1,15 @@
FROM mcr.microsoft.com/devcontainers/ruby:1-3.1-bullseye
# 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 <your-package-list-here>
# [Optional] Uncomment this line to install additional gems.
# RUN 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

View file

@ -0,0 +1,5 @@
CREATE DATABASE openneo_impress;
GRANT ALL PRIVILEGES ON openneo_impress.* TO impress_dev;
CREATE DATABASE openneo_id;
GRANT ALL PRIVILEGES ON openneo_id.* TO impress_dev;

View file

@ -0,0 +1,39 @@
// 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": "Dress to Impress",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "lts"
}
},
// 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": ".devcontainer/post-create.sh",
// HACK: Out of the box, this dev container doesn't allow installation to the
// default GEM_HOME, because of a weird thing going on with RVM. Instead, we
// set a custom GEM_HOME and GEM_PATH in our home directory!
// https://github.com/devcontainers/templates/issues/188
"containerEnv": {
"GEM_HOME": "~/.rubygems",
"GEM_PATH": "~/.rubygems"
}
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}

View file

@ -0,0 +1,29 @@
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:db
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
db:
image: mysql:latest
restart: unless-stopped
volumes:
- ./create-db.sql:/docker-entrypoint-initdb.d/create-db.sql
environment:
MYSQL_ROOT_PASSWORD: impress_dev
MYSQL_USER: impress_dev
MYSQL_PASSWORD: impress_dev

13
.devcontainer/post-create.sh Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e # Quit if any part of this script fails.
# Mark all git repositories as safe to execute, including cached gems.
# NOTE: This would be dangerous to run on a normal multi-user machine,
# but for a dev container that only we use, it should be fine!
git config --global safe.directory '*'
# Install the app's Ruby gem dependencies.
bundle install
# Set up the databases: create the schema, and load in some default data.
rake db:schema:load db:seed

View file

@ -2,8 +2,8 @@ development:
primary:
adapter: mysql2
database: openneo_impress
username: openneo_impress
password: openneo_impress
username: impress_dev
password: impress_dev
pool: 5
variables:
sql_mode: TRADITIONAL
@ -11,8 +11,8 @@ development:
openneo_id:
adapter: mysql2
database: openneo_id
username: openneo_impress
password: openneo_impress
username: impress_dev
password: impress_dev
pool: 2
variables:
sql_mode: TRADITIONAL

1
vendor/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/bundle