Skip to content

Commit

Permalink
Add docker-compose.yml
Browse files Browse the repository at this point in the history
* added Tiltfile
We can now have a complete setup ready for development
When working use command `tilt up -- --local-app`
  • Loading branch information
fumimowdan committed Sep 14, 2023
1 parent 5d45ae7 commit b203d93
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ newer versions of tools.
4. Run `bundle exec rails server` to launch the app on <http://localhost:3000>
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:
Expand Down
42 changes: 42 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion bin/app-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions bin/worker-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh
#
# worker startup script
#

set -e

# start sidekiq
bundle exec sidekiq -C ./config/sidekiq.yml
3 changes: 3 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit b203d93

Please sign in to comment.