Simplifying local development (#32)

* simplified local development

* fixed linting errors

* should fix

* fix indentation
This commit is contained in:
Karthik Sankar
2025-03-20 11:57:08 +08:00
committed by GitHub
parent 051ed583b8
commit f21d6f94db
3 changed files with 79 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
# README
# Harbor README
## Local development
@@ -8,23 +8,44 @@ $ git clone https://github.com/hackclub/harbor && cd harbor
# Set your config
$ cp .env.example .env
# The only thing you need to set is SEED_USER_API_KEY, which should be your key
```
# Build & run the project
Edit your `.env` file to include the following:
```
# Database configurations - these work with the Docker setup
DATABASE_URL=postgres://postgres:secureorpheus123@db:5432/app_development
WAKATIME_DATABASE_URL=postgres://postgres:secureorpheus123@db:5432/app_development
SAILORS_LOG_DATABASE_URL=postgres://postgres:secureorpheus123@db:5432/app_development
# Generate these with `rails secret` or use these for development
SECRET_KEY_BASE=alallalalallalalallalalalladlalllalal
ENCRYPTION_PRIMARY_KEY=32characterrandomstring12345678901
ENCRYPTION_DETERMINISTIC_KEY=32characterrandomstring12345678902
ENCRYPTION_KEY_DERIVATION_SALT=16charssalt1234
```
## Build & Run the project
```
$ docker compose run --service-ports web /bin/bash
# Now, setup the database using:
app# bin/rails db:create db:schema:load db:seed
# Now you're inside docker & you can do all the fun rails things...
app# bin/rails s -b 0.0.0.0 # this hosts the server on your computer w/ default port 3000
app# bin/rails c # start an interactive irb!
app# bin/rails db:migrate # migrate the database
```
You can now access the app at http://localhost:3000/
Use email authentication from the homepage with test@example.com (you can view emails at http://localhost:3000/letter_opener)!
Ever need to setup a new database?
```sh
# start a shell inside docker
$ docker compose run web --service-ports /bin/bash
# once inside, reset the db
```
# inside the docker container, reset the db
app# $ bin/rails db:drop db:create db:migrate db:seed
```

View File

@@ -15,6 +15,9 @@ Rails.application.configure do
# Enable server timing.
config.server_timing = true
# Disable CSRF protection in development
config.action_controller.forgery_protection_origin_check = false
# Enable/disable Action Controller caching. By default Action Controller caching is disabled.
# Run rails dev:cache to toggle Action Controller caching.
if Rails.root.join("tmp/caching-dev.txt").exist?

View File

@@ -1,9 +1,50 @@
# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Example:
#
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
# Only seed test data in development environment
if Rails.env.development?
# Creating test user
test_user = User.find_or_create_by(slack_uid: 'TEST123456') do |user|
user.username = 'testuser'
user.is_admin = true
end
# Add email address
email = test_user.email_addresses.find_or_create_by(email: 'test@example.com')
# Create API key
api_key = test_user.api_keys.find_or_create_by(name: 'Development API Key') do |key|
key.token = 'dev-api-key-12345'
end
# Create a sign-in token that doesn't expire
token = test_user.sign_in_tokens.find_or_create_by(token: 'testing-token') do |t|
t.expires_at = 1.year.from_now
t.auth_type = :email
end
puts "Created test user:"
puts " Username: #{test_user.username}"
puts " Email: #{email.email}"
puts " API Key: #{api_key.token}"
puts " Sign-in Token: #{token.token}"
# Create sample heartbeats
if test_user.heartbeats.count == 0
5.times do |i|
test_user.heartbeats.create!(
time: (Time.current - i.hours).to_f,
entity: "test/file_#{i}.rb",
project: "test-project",
language: "ruby",
source_type: :direct_entry
)
end
puts "Created 5 sample heartbeats for the test user"
else
puts "Sample heartbeats already exist for the test user"
end
else
puts "Skipping development seed data in #{Rails.env} environment"
end