diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..2cc67040 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -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 + +# [Optional] Uncomment this line to install additional gems. +# RUN gem install + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 diff --git a/.devcontainer/create-db.sql b/.devcontainer/create-db.sql new file mode 100644 index 00000000..b5a805a1 --- /dev/null +++ b/.devcontainer/create-db.sql @@ -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; diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..56ca1e0f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,44 @@ +// 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", + + "containerEnv": { + // Because the database is hosted on the local network at the hostname `db`, + // we partially override `config/database.yml` to connect to `db`! + "DATABASE_URL_PRIMARY_DEV": "mysql2://db", + "DATABASE_URL_OPENNEO_ID_DEV": "mysql2://db", + + // 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 + "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" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 00000000..87dae876 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -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 diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100755 index 00000000..1aff43ad --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,19 @@ +#!/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. +bin/rails db:schema:load db:seed + +# Install the app's JS dependencies. +yarn install + +# Run a first-time build of the app's JS, in development mode. +yarn build:dev diff --git a/config/database.yml b/config/database.yml index c17385f8..81a389e9 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,18 +1,24 @@ development: primary: + # You can override these default settings with this environment variable, + # fully or partially. We do this in the .devcontainer setup! + url: <%= ENV['DATABASE_URL_PRIMARY_DEV'] %> adapter: mysql2 database: openneo_impress - username: openneo_impress - password: openneo_impress + username: impress_dev + password: impress_dev pool: 5 variables: sql_mode: TRADITIONAL openneo_id: + # You can override these default settings with this environment variable, + # fully or partially. We do this in the .devcontainer setup! + url: <%= ENV['DATABASE_URL_OPENNEO_ID_DEV'] %> adapter: mysql2 database: openneo_id - username: openneo_impress - password: openneo_impress + username: impress_dev + password: impress_dev pool: 2 variables: sql_mode: TRADITIONAL diff --git a/package.json b/package.json index 98488824..f341db16 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "scripts": { "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets --asset-names=[name]-[hash].digested --loader:.js=jsx --loader:.png=file --loader:.svg=file --loader:.min.js=text", - "dev": "yarn build --watch --public-path=/dev-assets" + "build:dev": "yarn build --public-path=/dev-assets", + "dev": "yarn build:dev --watch" } } diff --git a/vendor/.gitignore b/vendor/.gitignore new file mode 100644 index 00000000..3bd6b832 --- /dev/null +++ b/vendor/.gitignore @@ -0,0 +1 @@ +/bundle \ No newline at end of file