diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7942f2fb6..4fcf775dd 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,12 +1,7 @@ -FROM ruby:2.6 - -# Install Node.js LTS -RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.2/install.sh | bash -RUN . "$HOME/.nvm/nvm.sh" +FROM ruby:3.3.8-bookworm # Install Ruby bundler RUN gem install bundler -v 2.4.22 # TODO: once we have a newer version of rails, remove version specifier # Install mysql -RUN apt update -RUN apt install -y mariadb-server # Apt cannot find mysql-server ¯\_(ツ)_/¯ +RUN apt update -qq && apt install -y mariadb-server diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 04417eee3..d54198e2d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,15 +1,20 @@ { - "name": "Ruby", - "build": {"dockerfile": "Dockerfile"}, - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {} - }, - "postCreateCommand": "bash scripts/setup_dependencies.sh", - "customizations": { - "vscode": { - "extensions": [ - "ms-azuretools.vscode-docker" - ] - } + "name": "Ruby", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {} + }, + "postCreateCommand": "bash .devcontainer/setup.sh", + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-docker" + ] } -} \ No newline at end of file + }, + "remoteEnv": { + "MISE_DISABLE_TOOLS": "ruby" + } +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100644 index 000000000..2ce8afa44 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -ex + +# Start database +service mariadb start + +echo "Setting up Mise" +curl https://mise.run | sh +echo 'eval "$(~/.local/bin/mise activate bash)"' >>~/.bashrc +source ~/.bashrc +mise trust -a +mise settings add idiomatic_version_file_enable_tools ruby + +# Allow root to connect without password +mysql -u root -e " + ALTER USER 'root'@'localhost' IDENTIFIED BY ''; + FLUSH PRIVILEGES; +" + +# app setup +mise i +mise run setup +echo "Start the server by running mise server" diff --git a/sample.env b/.env.sample similarity index 100% rename from sample.env rename to .env.sample diff --git a/README.md b/README.md index a7c810eeb..6e1469b97 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,7 @@ offers a place for workshop leaders to provide input and information about works ## Using Codespaces -As part of rubyforgood/awbw-dashboard#9, the development container configuration has been set up to be used in Codespaces. This means that there should be no set up needed, and one will only need to run the rails project via: -```shell -rails server -``` +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/rubyforgood/awbw/tree/main?quickstart=1) ## Local development diff --git a/bin/setup b/bin/setup index 5853b5ea8..114226b79 100755 --- a/bin/setup +++ b/bin/setup @@ -20,10 +20,10 @@ FileUtils.chdir APP_ROOT do # Install JavaScript dependencies # system('bin/yarn') - # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' - # end + puts "\n== Copying env files ==" + unless File.exist?('.env') + FileUtils.cp '.env.sample', '.env' + end puts "\n== Preparing database ==" system! 'bin/rails db:prepare' diff --git a/config/environments/development.rb b/config/environments/development.rb index 66df51f6f..213e04034 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -59,4 +59,7 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + # needed for codespaces + config.hosts << ".app.github.dev" end diff --git a/db/seeds.rb b/db/seeds.rb index 807fb241f..05b34bf54 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -4,11 +4,7 @@ # Extract credentials adapter = env_config['adapter'] -host = env_config['host'] || 'localhost' -port = env_config['port'] || 3306 database = env_config['database'] -username = env_config['username'] -password = env_config['password'] # Only run if MySQL is the DB if adapter.include?('mysql') @@ -16,18 +12,8 @@ puts "Loading SQL dump from #{sql_file}..." - # Build the shell command - command = [ - "mysql", - "-h", host.to_s, - "-P", port.to_s, - "-u", username.to_s, - ("-p#{password}" if password.to_s.present?), - database.to_s, - "< #{sql_file}" - ].compact.join(' ') - # Run the command + command = "rails dbconsole < #{sql_file}" system(command) || raise("Failed to load SQL dump into #{database}") puts "SUCCESS! SQL dump loaded successfully." @@ -37,11 +23,12 @@ # wrapping in a tx for now ActiveRecord::Base.transaction do - # Load DML operations from dml_seeds.rb - Admin.all.each { |a| a.update!(password: password) } + admin_password = Devise::Encryptor.digest(Admin, 'password') + Admin.update_all(encrypted_password: admin_password) - User.all.find_in_batches(batch_size: 100) do |batch| - batch.each { |u| u.update!(password: password) } + user_password = Devise::Encryptor.digest(User, 'password') + User.in_batches do |batch| + batch.update_all(encrypted_password: user_password) end Admin.create!(first_name: "Amy", last_name: "Admin", email: "amy.admin@example.com", password: "password") diff --git a/mise.toml b/mise.toml new file mode 100644 index 000000000..58c9a25b5 --- /dev/null +++ b/mise.toml @@ -0,0 +1,10 @@ +[tools] +ruby = "3.3.8" + +[tasks.setup] +description = "Set up the project for local non-docker developement." +run = "bin/setup" + +[tasks.server] +description = "Start the rails server" +run = "bin/rails s" diff --git a/scripts/setup_dependencies.sh b/scripts/setup_dependencies.sh deleted file mode 100644 index 67641c5fe..000000000 --- a/scripts/setup_dependencies.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -set -ex - -echo "Installing node 22" -. "$HOME/.nvm/nvm.sh" -nvm install 22 -echo "Installing Rails dependencies" -bundler install - -# Run DB on docker -docker run --name awbw_mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_DATABASE=awbw_development -p 3306:3306 -d mysql:latest -a -# Wait for DB to be available -echo "Waiting for database to be ready..." -sleep 15 # Let's wait a bit for the DB to be ready -# Migrate schemas -rake db:migrate -# Set up users -rake db:seed \ No newline at end of file