From 811e89d3803187c9687d89f94f21231423610497 Mon Sep 17 00:00:00 2001 From: Noah Durbin <13364668+noahdurbin@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:57:33 -0600 Subject: [PATCH] feat: readme and script to start docker environment --- README.md | 17 +++++++++++++++++ db/schema.rb | 30 +++++++++++++++--------------- docker_start.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 15 deletions(-) create mode 100755 docker_start.sh diff --git a/README.md b/README.md index 3346d67..f76b273 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,28 @@ This is the backend API repository for TurLink. TurLink is a link shortener app ## Setup and Testing - clone this repo + +### traditional setup - run `bundle install` - run `rails db:{drop,create,migrate,seed}` - for the test suite, run `bundle exec rspec` - to use endpoints in development enivronment, run `rails s` and use `http://localhost:5000` as your base url +### setup with docker +- ensure you have docker installed on your local machine +- run `chmod +x docker_start.sh` to make script executable +- run `./docker_start.sh` + - builds docker images + - starts containers + - creates database + - runs migrations + - seeds database +- application should now be live at `http://localhost:3001` +- to stop the application run `docker-compose down` + +- Rails container: `docker-compose exec web bash` +- Rails console: `docker-compose run web rails c` + ## API Endpoints ### User Registration diff --git a/db/schema.rb b/db/schema.rb index 28e1791..b2a4218 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,25 +10,25 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 20_240_822_170_839) do +ActiveRecord::Schema[7.1].define(version: 2024_08_22_170839) do # These are extensions that must be enabled in order to support this database - enable_extension 'plpgsql' + enable_extension "plpgsql" - create_table 'links', force: :cascade do |t| - t.string 'original' - t.string 'short' - t.bigint 'user_id', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['user_id'], name: 'index_links_on_user_id' + create_table "links", force: :cascade do |t| + t.string "original" + t.string "short" + t.bigint "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_links_on_user_id" end - create_table 'users', force: :cascade do |t| - t.string 'email' - t.string 'password_digest' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table "users", force: :cascade do |t| + t.string "email" + t.string "password_digest" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_foreign_key 'links', 'users' + add_foreign_key "links", "users" end diff --git a/docker_start.sh b/docker_start.sh new file mode 100755 index 0000000..5a9ee98 --- /dev/null +++ b/docker_start.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status. +set -e + +echo "Starting Docker environment for turlink-be..." + +# Build Docker images +echo "Building Docker images..." +docker-compose build + +# Start the containers +echo "Starting Docker containers..." +docker-compose up -d + +# Wait for the database to be ready +echo "Waiting for database to be ready..." +sleep 10 + +# Run database setup +echo "Setting up the database..." +docker-compose run web rails db:create +docker-compose run web rails db:migrate + +# seed database +echo "Seeding the database..." +docker-compose run web rails db:seed + +echo "Setup complete! Your application should be running at http://localhost:3001"