From 752ac7dfa03c59124af5a632e1883ec584005b68 Mon Sep 17 00:00:00 2001 From: Luis Miguel Fros De Castro Date: Fri, 7 Feb 2020 15:43:55 -0300 Subject: [PATCH] feat(Dockefile): add postgresql-client for backups and restoring data --- Dockerfile | 7 ++++++- Makefile | 15 +++++++++++++++ docker-compose.yml | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8c67641..9bbb03c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM ruby:$RUBY_VERSION ENV LANG C.UTF-8 -ARG PG_MAJOR +ARG PG_VERSION ARG NODE_MAJOR ARG BUNDLER_VERSION ARG YARN_VERSION @@ -20,6 +20,11 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -\ && apt-get update \ && apt-get install -y yarn +# Add PostgreSQL to sources list +RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list \ + && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ + && apt-get update \ + && apt-get install postgresql-client-${PG_VERSION} -yq # Heroku RUN curl https://cli-assets.heroku.com/install.sh | sh diff --git a/Makefile b/Makefile index a2cdad0..8c80f10 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,18 @@ services-logs: services-port: @set -o pipefail; \ docker-compose $(DOCKER_COMPOSE_ARGS) port ${SERVICE} ${PORT} 2> /dev/null | cut -d':' -f2 || echo ${PORT} + +backup-staging: ROLE=staging +backup-production: ROLE=production +backup-%: + @echo Capturing $(ROLE).... + @heroku pg:backups:capture --remote $(ROLE) + +restore-from-staging: ROLE=staging +restore-from-production: ROLE=production +restore-from-%: + $(eval TEMP_FILE=$(shell mktemp)) + @echo Restoring from $(ROLE).... + @heroku pg:backups:download --remote $(ROLE) --output $(TEMP_FILE) + @pg_restore --verbose --clean --no-acl --no-owner -h postgresql \ + -U postgres -p $(shell make services-port SERVICE=postgresql PORT=5432) -d $(PROJECT)_development $(TEMP_FILE) diff --git a/docker-compose.yml b/docker-compose.yml index 2e171c4..d0e1c24 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: dockerfile: Dockerfile args: RUBY_VERSION: '2.5.5' - PG_MAJOR: '11' + PG_VERSION: '11.3' NODE_MAJOR: '10' YARN_VERSION: '1.13.0' BUNDLER_VERSION: '2.0.1'