score-spec / score-compose

Reference implementation for docker-compose target platform support
https://score.dev/
Apache License 2.0
445 stars 40 forks source link

feat(provisioners): added mongodb default provisioner #123

Closed astromechza closed 4 months ago

astromechza commented 4 months ago

We have datastore implementations for postgres and redis, and this PR introduces a new provisioner for a document DB: mongodb.

This provisions a single mongo container with persistent data and healthcheck. An exec command is provided to support working with the data.

generate:

$ score-compose generate score.yaml
INFO: Loaded state directory with docker compose project '11-mongodb-document-database'
INFO: Validated workload 'hello-world'
INFO: Successfully loaded 9 resource provisioners
INFO: mongodb.default#hello-world.db: To connect to mongo: "docker exec -ti 11-mongodb-document-database-mongo-JTyNG0-1 mongosh -u user-HCEtQlbs -p XtCgk7PWMqpORIsn"
INFO: Provisioned 1 resources
INFO: Converting workload 'hello-world' to Docker compose

And docker compose up returns:

[+] Running 3/4
 ⠋ Volume "mongo-G9ssoa-data"                                   Created                                                                                                                                                                                                                    6.0s
 ✔ Container 11-mongodb-document-database-mongo-G9ssoa-1        Healthy                                                                                                                                                                                                                    5.4s
 ✔ Container 11-mongodb-document-database-wait-for-resources-1  Started                                                                                                                                                                                                                    5.6s
 ✔ Container 11-mongodb-document-database-hello-world-first-1   Started

Our hello world container contains the connection string

$ docker exec -ti 4946f4727f28 sh -c 'echo $CONNECT_1'
mongodb://user-SUGtvhox:zvrTunGR4fjqJASR@mongo-G9ssoa:27017/

And running the exec command returns:

Current Mongosh Log ID: 6627c9a9767c46ab553b9273
Connecting to:      mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.4
Using MongoDB:      7.0.8
Using Mongosh:      2.2.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

test> show databases
admin   100.00 KiB
config   12.00 KiB
local    72.00 KiB

Good stuff 🎉