From b203d93566b060af058d93a710e312788c85e897 Mon Sep 17 00:00:00 2001 From: fumimowdan Date: Thu, 14 Sep 2023 15:01:05 +0100 Subject: [PATCH] Add docker-compose.yml * added Tiltfile We can now have a complete setup ready for development When working use command `tilt up -- --local-app` --- .env.example | 3 +++ README.md | 10 +++++++++ Tiltfile | 42 ++++++++++++++++++++++++++++++++++++++ bin/app-startup.sh | 4 +++- bin/worker-startup.sh | 9 +++++++++ config/database.yml | 3 +++ db/seeds.rb | 3 +++ docker-compose.yml | 47 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 Tiltfile create mode 100755 bin/worker-startup.sh create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example index 1c574d12..558f35c6 100644 --- a/.env.example +++ b/.env.example @@ -6,3 +6,6 @@ AZURE_CLIENT_ID= AZURE_CLIENT_SECRET= AZURE_TENANT_ID= REDIS_URL=redis://localhost:6379 +DB_USER=gtrp +DB_PASSWORD=gtrp +LOCAL_USER_EMAIL= \ No newline at end of file diff --git a/README.md b/README.md index dfa28529..98f37b4a 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,16 @@ newer versions of tools. 4. Run `bundle exec rails server` to launch the app on 5. Run `./bin/webpack-dev-server` in a separate shell for faster compilation of assets + +## Setup using Tilt +To have a development environment setup quickly with all the dependencies you can use [Tilt](https://tilt.dev/). +1. Create your local `.env` file from `.env.example` +2. Update your local `.env` with relevant information +3. Add your education.gov.uk email address to `LOCAL_USER_EMAIL` in `.env` +4. Run `tilt up` to start the server + +For development convenience you should use `tilt up -- --local-app` + ## Running specs Run the full test suite with: diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 00000000..66ecf438 --- /dev/null +++ b/Tiltfile @@ -0,0 +1,42 @@ +# point Tilt at the existing docker-compose configuration. +docker_compose("./docker-compose.yml") + +config.define_bool("local-app") + +cfg = config.parse() + +local_app = cfg.get("local-app", False) + +resources = [ + "redis", + "database", + "app", + "worker" +] + + +if local_app: + resources.remove("app") + resources.remove("worker") + local_resource( + "local_app", + serve_cmd="./bin/app-startup.sh", + serve_env={ + "RAILS_ENV": "development" + }, + resource_deps=["database", "redis"], + readiness_probe=probe( + period_secs=15, http_get=http_get_action(port=3000, path="/healthcheck") + ), + ) + local_resource( + "local_worker", + serve_cmd="./bin/worker-startup.sh", + resource_deps=["database", "redis"], + ) + resources.append("local_app") + resources.append("local_worker") + + +config.clear_enabled_resources() +config.set_enabled_resources(resources) diff --git a/bin/app-startup.sh b/bin/app-startup.sh index e28122a7..0df4c416 100755 --- a/bin/app-startup.sh +++ b/bin/app-startup.sh @@ -3,11 +3,13 @@ # Dockerfile application startup script # +set -e + # run migrations bundle exec rails db:migrate # add seed data in review environment -if [ "$RAILS_ENV" = "review" ]; then +if [[ "$RAILS_ENV" = "review" || "$RAILS_ENV" = "development" ]]; then echo "Running rails db:seed" bundle exec rails db:seed fi diff --git a/bin/worker-startup.sh b/bin/worker-startup.sh new file mode 100755 index 00000000..db93cf14 --- /dev/null +++ b/bin/worker-startup.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +# +# worker startup script +# + +set -e + +# start sidekiq +bundle exec sidekiq -C ./config/sidekiq.yml diff --git a/config/database.yml b/config/database.yml index 418a4cc8..2096a8f9 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,6 +23,9 @@ default: &default development: <<: *default + username: <%= ENV["DB_USER"] %> + password: <%= ENV["DB_PASSWORD"] %> + host: localhost database: get_an_international_relocation_payment_development # The specified database role being used to connect to postgres. diff --git a/db/seeds.rb b/db/seeds.rb index e423cc24..d8145132 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -26,3 +26,6 @@ service_start_date: 1.day.ago, service_end_date: 1.year.from_now, ) + +local_user_email = ENV.fetch("LOCAL_USER_EMAIL", nil) +User.create!(email: local_user_email) if local_user_email diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..cd617931 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +version: '3.9' +services: + + redis: + image: redis:6.0-alpine + networks: + - gtrp + ports: + - 6379:6379 + + database: + image: postgres:15-alpine + networks: + - gtrp + environment: + - POSTGRES_USER=gtrp + - POSTGRES_PASSWORD=gtrp + - POSTGRES_DB=get_an_international_relocation_payment_development + ports: + - 5432:5432 + + app: &app + build: + context: . + args: + - COMMIT_SHA=shafoo + - GOVUK_NOTIFY_API_KEY + - GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID + networks: + - gtrp + depends_on: [ database, redis ] + ports: + - 3000:3000 + environment: + - DATABASE_URL=postgresql://gtrp:gtrp@database/get_an_international_relocation_payment_development + - REDIS_URL=redis://redis + - RAILS_ENV=development + env_file: + - .env + + worker: + <<: *app + ports: + - 3001:3001 + command: ./bin/worker-startup.sh +networks: + gtrp: