Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
31 changes: 18 additions & 13 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
},
"remoteEnv": {
"MISE_DISABLE_TOOLS": "ruby"
}
}
23 changes: 23 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 6 additions & 19 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,16 @@

# 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')
sql_file = Rails.root.join('db', 'awbw_dml_only.sql')

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."
Expand All @@ -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: "[email protected]", password: "password")
Expand Down
10 changes: 10 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 0 additions & 18 deletions scripts/setup_dependencies.sh

This file was deleted.