diff --git a/README.md b/README.md index 19dee5b..9b2d52d 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,10 @@ The actual implementation of these steps will vary based on which language (Java - [Ring](https://www.graphqlize.org/docs/getting_started/clojure/ring) - [Vanilla Clojure](https://www.graphqlize.org/docs/getting_started/clojure/vanilla) +### Getting started with Docker + +Some examples include docker and docker-compose files to get you started faster. + +They will allow you to play around with the API generated by graphqlize over a sample database or your own. + ![graphqlize-docker-demo](graphqlize-boot-docker.gif) diff --git a/java/spring-boot/README.md b/java/spring-boot/README.md index dfbd679..c76cfca 100644 --- a/java/spring-boot/README.md +++ b/java/spring-boot/README.md @@ -19,4 +19,43 @@ Important: Since the database takes some time to initialize the first time, you # Once you are done stop docker compose and delete the database volumes docker-compose down -``` \ No newline at end of file +``` + +## Build an API on top of your own data + +The Docker setup uses the sakila sample databse, however you can use your own very easily. This way you can explore very fast how grapqhlize will look on top of your existing database structure. + +Please use this feature and contribute with feedback. If you are a developer and you find the project useful but in need of improvement approach the community for code contributions. + +The steps to use your date are as follows: + +* Export your data from your existing databse or take a copy from backup. +* Copy your data to `docker-entrypoint-initdb.d`. We are using the import features provided by the docker image. See image docs for help. +* Update the databse configureation in `config/docker-application.properties` to match your database name, etc +* Start your containers `docker-compose up -d && docker-compose logs -f` +* Explore your Graphqlize API + +The docker images for both PostgreSQL and MySQL/MariaDB offer ways to load data before the container is started. +We are going to use that feature to load another database instead of sakiladb. + +**Note**: Database initialization happens only once during the initial docker start. You may want to remove your volumes with `docker-compose down -v` to force initialization. + +### Using your own data with PostgreSQL + +For PostgreSQL we are going to use the functionality described in the [Initialization scripts](https://hub.docker.com/_/postgres) section of the image documentation. + +> If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary). +> After the entrypoint calls initdb to create the default postgres user and database, it will run any *.sql files, run any executable *.sh scripts, and source any non-executable *.sh scripts found in that directory to do further initialization before starting the service. + +If you are on a Linux system you can run the following commands: + +```sh + # Export your data with pg_dump or just take it from your backups. + sudo -u postgres pg_dump my_db | gzip > my_db.sql.gz + # Copy your data to docker-entrypoint-initdb.d + # Update config/docker-application.properties with your database name and other credentials + # Start the container + docker-compose up -d && docker-compose logs -f +``` + +In my personal setup I took a database dump generated by `autopostgresqlbackup`. I had to customize postgresql image locale and also add an initialization script to create the roles that my database dump was expecting. diff --git a/java/spring-boot/config/docker-application.properties b/java/spring-boot/config/docker-application.properties index 45bcf5c..d74b45b 100644 --- a/java/spring-boot/config/docker-application.properties +++ b/java/spring-boot/config/docker-application.properties @@ -1,7 +1,7 @@ logging.level.root=INFO -#spring.datasource.url=jdbc:mysql://sakiladb:3306/sakila +#spring.datasource.url=jdbc:mysql://db:3306/sakila #spring.datasource.username=sakila #spring.datasource.password=p_ssW0rd -spring.datasource.url=jdbc:postgresql://sakiladb:5432/sakila +spring.datasource.url=jdbc:postgresql://db:5432/sakila spring.datasource.username=sakila spring.datasource.password=p_ssW0rd \ No newline at end of file diff --git a/java/spring-boot/docker-compose.yaml b/java/spring-boot/docker-compose.yaml index 8513699..d72407d 100644 --- a/java/spring-boot/docker-compose.yaml +++ b/java/spring-boot/docker-compose.yaml @@ -9,7 +9,7 @@ volumes: services: graphqlize: build: . - command: bash -c 'while !