Skip to content

Commit

Permalink
Merge pull request #227 from lsst-epo/225-update-the-makefile-scripts
Browse files Browse the repository at this point in the history
Fixed `Makefile` and updated README.md with instrs
  • Loading branch information
ericdrosas87 authored Apr 15, 2024
2 parents 4ab3179 + 040de86 commit f59f4c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ clean:
clean-images:
docker images prune

# Requires argument `dbname` to specify the name of the new DB, usage: `make local-db dbname=my_db`
# Requires argument `dbname` to specify the name of the new DB, usage: `make local-db dbname=my_db dbfile=mydb.sql`
# Requires argument `dbfile` to specify the name of the DB dump file to recreate, usage: `make local-db dbname=my_db dbfile=mydb.sql`
local-db:
cd db && docker exec --workdir / rubin-obs-api-postgres-1 psql -U craft -c "create database $(dbname);"
cd db && docker exec --workdir / rubin-obs-api-postgres-1 psql -U craft -d $(dbname) -f inv_mar.sql
cd db && docker exec --workdir / rubin-obs-api-postgres-1 psql -U craft -d $(dbname) -f $(dbfile)
echo "\n\n\n\nDon't forget to update your docker-compose-local-db.yaml with the DB name: $(dbname)"

db-list:
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ This project was created with Docker version 20.10.5.
### To use a local db
#### Make scripts
---
To list your local DBs:
`make db-list`
---
To list the databases sitting around in the `prod` environment:
`make cloud-db-list`
---
To export a `prod` database to the `gs://release_db_sql_files/rubinobs/` bucket:
`make cloud-db-export dbname=prod_db`
* The argument `dbname` is required and should be one of the databases listed from `make cloud-db-list`
* Once you download the DB dump file, move it to the `./db/` folder
---
To recreate a local DB from a dump file located within `./db/`:
`make local-db dbname=my_new_local_db dbfile=prod.sql`
* The argument `dbname` is required and will be the name of the newly created database
* The argument `dbfile` is required and should be the name of the DB file to recreate, this file _must_ be in the `./db/` folder
---
#### Deprecated workflow
0. Uncomment the `COPY` line in `./db/Dockerfile`
1. Install [Docker](https://docs.docker.com/get-docker/)
2. Clone this repository
3. Add a .env file (based on .env.sample) and provide values appropriate to your local dev environment
Expand Down
3 changes: 2 additions & 1 deletion db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM postgres:13-alpine

COPY db.sql /docker-entrypoint-initdb.d/db.sql
# Commented out so that the Makefile DB scripts can do their thing
# COPY db.sql /docker-entrypoint-initdb.d/db.sql

0 comments on commit f59f4c5

Please sign in to comment.