generated from medeirosinacio/basic-php-project-structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a46b18f
commit cf987b1
Showing
5 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
# Set variables | ||
SDDB_USER=user | ||
SDDB_PASS=password | ||
SDDB_DATABASE=default | ||
|
||
# replicate set initiate | ||
echo "Checking mongo container..." | ||
until mongosh --host mongo --eval "print(\"waited for connection\")" | ||
do | ||
sleep 1 | ||
done | ||
|
||
echo "Initializing replicaset..." | ||
mongosh --host mongo <<EOF | ||
rs.initiate( | ||
{ | ||
_id: "rs0", | ||
version: 1, | ||
members: [ | ||
{ _id: 0, host: "mongo:27017"} | ||
] | ||
} | ||
) | ||
rs.status() | ||
EOF | ||
|
||
|
||
echo "Creating admin user: root@root/admin" | ||
mongosh --host mongo <<EOF | ||
db.getSiblingDB('admin').createUser( | ||
{ | ||
user: "root", | ||
pwd: "root", | ||
roles: [ { role: "root", db: "admin" } ] | ||
} | ||
) | ||
rs.status() | ||
EOF | ||
|
||
echo "Creating normal user: ${SDDB_USER}:${SDDB_PASS}/${SDDB_DATABASE}" | ||
mongosh --host mongo <<EOF | ||
use ${SDDB_DATABASE} | ||
db.createUser( | ||
{ | ||
user: "${SDDB_USER}", | ||
pwd: "${SDDB_PASS}", | ||
roles: [ { role: "dbOwner", db: "${SDDB_DATABASE}" } ] | ||
} | ||
) | ||
EOF | ||
|
||
echo "Confirm normal user account" | ||
echo "---------------------------------------" | ||
mongosh --eval 'rs.status()' "mongodb://${SDDB_USER}:${SDDB_PASS}@mongo:27017/${SDDB_DATABASE}" | ||
echo "---------------------------------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- melhorar container do mongodb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
#!/usr/bin/make | ||
|
||
.SILENT: clean | ||
.PHONY: all | ||
.DEFAULT_GOAL := help | ||
|
||
##@ Development resources | ||
|
||
setup: ## Setup the project | ||
@chmod +x ./.docker/mongo/init.sh | ||
@chmod +x ./migrations/mongo/records_collection.sh | ||
docker-compose down -v | ||
docker-compose pull | ||
docker-compose up -d --build --remove-orphans --force-recreate | ||
sleep 5 | ||
make setup-database | ||
|
||
setup-database: ## Setup the database | ||
make database-cleanup | ||
make database-migrate | ||
|
||
database-cleanup: ## Cleanup the database | ||
docker-compose exec mongo bash -c "mongosh \"mongodb://mongo/default?replicaSet=rs0&readPreference=primary\" --quiet --eval 'db.getCollectionNames().forEach(c => db.getCollection(c).drop());'" | ||
|
||
database-migrate: ## Migrate the database | ||
docker-compose exec mongo bash -c "find /migrations/ -name \"*.sh\" -exec {} \;" | ||
|
||
playground: ## Start a PHP playground dockerized environment | ||
@make check-docker | ||
@docker-compose exec php bash | ||
|
||
check-docker: ## Check if Docker is installed | ||
@docker --version > /dev/null 2>&1 || (echo "Docker is not installed. Please install Docker and try again." && exit 1) | ||
|
||
help: ## Show this help message | ||
@echo "Usage: make [command]" | ||
@echo "" | ||
@echo "Commands available:" | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters