Skip to content

Instantly share code, notes, and snippets.

@mocoso
Last active January 2, 2019 09:09
Show Gist options
  • Save mocoso/f0416e16bc3e0ddfc2a0b20abf1df953 to your computer and use it in GitHub Desktop.
Save mocoso/f0416e16bc3e0ddfc2a0b20abf1df953 to your computer and use it in GitHub Desktop.
Makefile to set up a development environment for a rails/postgres app in docker
LOCAL_DUMP=./tmp/local-dump.sql
APP_CONTAINER_NAME=prepfortests_app
all: build run create_databases load_data test smoke_test
./config/database.yml:
@echo "---> Create database config symlink"
ln -s database.example.yml ./config/database.yml
build: ./config/database.yml
@echo '--> Build containers'
docker-compose build
run:
docker-compose up -d
create_databases:
@echo '--> Creating databases'
docker-compose exec app bundle exec rake db:setup
load_data: restore_data sanitise_data
$(LOCAL_DUMP):
@echo '--> Downloading database dump'
heroku pg:backups:download --app pft --output=$(LOCAL_DUMP)
restore_data: $(LOCAL_DUMP)
@echo '--> Restoring from database dump'
docker-compose exec -T postgres pg_restore --verbose --clean --no-acl --no-owner -d pft_development -U postgres < $(LOCAL_DUMP) || true
sanitise_data:
@echo '--> Sanitise data'
docker-compose exec app bundle exec rake data:sanitise
test:
@echo '--> Run the tests'
docker-compose exec app bundle exec rake
smoke_test:
@echo '--> Check the app is running'
curl --head --url http://localhost:3021
@echo 'You are ready to go, visit http://localhost:3021'
clean:
-rm ./config/database.yml
-rm $(LOCAL_DUMP)
-docker-compose down
-docker rmi $(APP_CONTAINER_NAME)
.PHONY: all build run create_databases restore_data load_data sanitise_data test smoke_test clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment