Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to setup Graphjin with a pre-existing Postgres databse #382

Closed
gevera opened this issue Aug 17, 2022 · 10 comments
Closed

Allow to setup Graphjin with a pre-existing Postgres databse #382

gevera opened this issue Aug 17, 2022 · 10 comments
Labels
enhancement New feature or request

Comments

@gevera
Copy link

gevera commented Aug 17, 2022

What would you like to be added:
Right now, in order to start Graphjin docker-compose pulls it and Postgres docker image as its dependency for the whole setup.
Unfortunately, there is no straightforward way of setting up Graphjin using a pre-existing database

A command like

graphjin new blog --local

That will create a docker-compose with only Graphjin as a service and point graphjin to already running postgres database (barebones on my machine or remote)

Why is this needed:
For adopting Graphjin in already running projects (databases)
Will save time to deliver products

@gevera gevera added the enhancement New feature or request label Aug 17, 2022
@dosco
Copy link
Owner

dosco commented Sep 15, 2022

This is a great point should be easy enough to add.

@gedw99
Copy link

gedw99 commented Sep 16, 2022

I also would appreciate this

dosco added a commit that referenced this issue Sep 19, 2022
New argument `-db-url` on the `new` sub-command allows you to point a new app
to a local database.
Eg. graphjin new testapp --db-url=postgres://user:pass@localhost/testapp-development
@dosco
Copy link
Owner

dosco commented Sep 19, 2022

Just added support for this. Does this work you you'll?

graphjin new testapp --db-url=postgres://user:pass@localhost/testapp-development

@gedw99
Copy link

gedw99 commented Sep 20, 2022

Mhh i am probably doing something wrong, but its not working for me.

makefile

# https://github.com/dosco/graphjin

JIN_REPO_NAME=graphjin
JIN_VERSION=v0.20.29
JIN_BIN_NAME=graphjin
JIN_APP_NEW_NAME=jin-test-new
JIN_APP_EXISITNG_NAME=jin-test-existing


# https://github.com/Khan/genqlient

GQL_REPO_NAME=genqlient
GQL_VERSION=v0.5.0
GQL_BIN_NAME=genqlient


# https://github.com/medelman17/apollo-studio-client-go

APO_REPO_NAME=apollo-studio-client-go



print:
	@echo
	@echo "JIN_BIN_NAME:          $(shell which $(JIN_BIN_NAME))"
	@echo "JIN_VERSION:           $(JIN_VERSION)" 
	@echo "JIN_APP_NEW_NAME:      $(JIN_APP_NEW_NAME)" 
	@echo "JIN_APP_EXISITNG_NAME: $(JIN_APP_EXISITNG_NAME)" 
	@echo
	@echo "GQL_BIN_NAME:          $(shell which $(GQL_BIN_NAME))" 
	@echo "GQL_VERSION:           $(GQL_VERSION)" 

dep-git:
	git clone git@github.com:dosco/graphjin.git -b $(JIN_VERSION)

	git clone git@github.com:Khan/genqlient.git -b $(GQL_VERSION)

	# test clients
	git clone git@github.com:medelman17/apollo-studio-client-go.git



### JIN ( graphjin )

jin-install:
	cd $(JIN_REPO_NAME) && go install . 

# exisitng
jin-existing-create:
	# sets up using an existing postgresql.
	graphjin new $(JIN_APP_EXISITNG_NAME) --db-url=postgres://user:pass@localhost/testapp-development
jin-existing-delete:
	rm -rf $(JIN_APP_EXISITNG_NAME)
jin-existing-run:
	cd $(JIN_APP_EXISITNG_NAME) && docker-compose run api db setup
	cd $(JIN_APP_EXISITNG_NAME) && docker-compose run -p 8080:8080 api serve
	open http://localhost:8080

# new
jin-new-create:
	# generates a setup with a new postresql
	graphjin new $(JIN_APP_NEW_NAME)
jin-new-delete:
	# deletes the folder
	rm -rf $(JIN_APP_NEW_NAME)	
jin-new-run:
	cd $(JIN_APP_NEW_NAME) && docker-compose run api db setup
	cd $(JIN_APP_NEW_NAME) && docker-compose run -p 8080:8080 api serve
	open http://localhost:8080
jin-new-run-1:
	# Create the app database
	# Docker compose will start a Postgres database for your app
	cd $(JIN_APP_NEW_NAME) && docker-compose run api db create

	# Run migrations and seed it with fake data.
	# Docker compose will start a Postgres database for your app
	cd $(JIN_APP_NEW_NAME) && docker-compose run api db setup

	# Finally launch GraphJin configured for your app
	cd $(JIN_APP_NEW_NAME) && docker-compose up


New db use case:

make

JIN_BIN_NAME:          /Users/apple/workspace/go/bin/graphjin
JIN_VERSION:           v0.20.29
JIN_APP_NEW_NAME:      jin-test-new
JIN_APP_EXISITNG_NAME: jin-test-existing

GQL_BIN_NAME:          /Users/apple/workspace/go/bin/genqlient
GQL_VERSION:           v0.5.0

make jin-new-create
# generates a setup with a new postresql
graphjin new jin-test-new
INFO    Create skipped file exists: jin-test-new
INFO    Create skipped file exists: jin-test-new/Dockerfile
INFO    Create skipped file exists: jin-test-new/docker-compose.yml
INFO    Create skipped file exists: jin-test-new/config
INFO    Create skipped file exists: jin-test-new/config/dev.yml
INFO    Create skipped file exists: jin-test-new/config/prod.yml
INFO    Create skipped file exists: jin-test-new/config/seed.js
INFO    Create skipped file exists: jin-test-new/config/migrations
INFO    Create skipped file exists: jin-test-new/config/migrations/0_init.sql
INFO    Create skipped file exists: jin-test-new/config/scripts
INFO    Create skipped file exists: jin-test-new/config/queries
INFO    Create skipped file exists: jin-test-new/config/queries/getUsers.gql
INFO    App initialized: jin-test-new

make jin-new-run
cd jin-test-new && docker-compose run api db setup
[+] Running 1/1
 ⠿ Container jin-test-new-db-1  Created                                                                                                                                                     0.3s
[+] Running 1/1
 ⠿ Container jin-test-new-db-1  Started                                                                                                                                                     1.3s
FATAL   Config File "dev" Not Found in "[/config]"
make: *** [jin-new-run] Error 1

existing Db use case:

make jin-existing-create
# sets up using an existing postgresql.
graphjin new jin-test-existing --db-url=postgres://user:pass@localhost/testapp-development
INFO    Create skipped file exists: jin-test-existing
INFO    Create skipped file exists: jin-test-existing/Dockerfile
INFO    Create skipped file exists: jin-test-existing/docker-compose.yml
INFO    Create skipped file exists: jin-test-existing/config
INFO    Create skipped file exists: jin-test-existing/config/dev.yml
INFO    Create skipped file exists: jin-test-existing/config/prod.yml
INFO    Create skipped file exists: jin-test-existing/config/seed.js
INFO    Create skipped file exists: jin-test-existing/config/migrations
INFO    Create skipped file exists: jin-test-existing/config/migrations/0_init.sql
INFO    Create skipped file exists: jin-test-existing/config/scripts
INFO    Create skipped file exists: jin-test-existing/config/queries
INFO    Create skipped file exists: jin-test-existing/config/queries/getUsers.gql
INFO    App initialized: jin-test-existing
 data  make jin-existing-run
cd jin-test-existing && docker-compose run api db setup
FATAL   Config File "dev" Not Found in "[/config]"
make: *** [jin-existing-run] Error 1

@gedw99
Copy link

gedw99 commented Sep 20, 2022

Also for an existing DB use case, why gen a docker compose ? I would have thought a docker is enough and easier for people to deploy. I am using fly, and so a single docker is alot easier to work with on fly at least

@dosco
Copy link
Owner

dosco commented Sep 20, 2022

You're correct we probably don't need the docker-compose.yml when using an external db. I would suggest changing the docker-compose run db setup to graphjin db setup so no docker is used.

If you still want to use docker-compose then just mke the below change to your docker-compoose.yml

 volumes:
      - ./config:/config

@dosco
Copy link
Owner

dosco commented Sep 20, 2022

I'm making the code change to ensure that when the db-url is specified no docker-compose.yml is created

@gedw99
Copy link

gedw99 commented Sep 21, 2022

Ok thanks @dosco

will try again when it’s ready

@dosco
Copy link
Owner

dosco commented Sep 21, 2022

This has been comitted i'm closing this issue for now.

@dosco dosco closed this as completed Sep 21, 2022
@gevera
Copy link
Author

gevera commented Sep 23, 2022

Thank you. This is perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants