Skip to content

Commit

Permalink
Merge pull request #1 from LuisFros/feat-postgresql-client
Browse files Browse the repository at this point in the history
feat(Dockerfile): add postgresql-client for backups and restoring data
  • Loading branch information
LuisFros authored Feb 7, 2020
2 parents 524b1e8 + 752ac7d commit d8a46af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit d8a46af

Please sign in to comment.