forked from reworkd/AgentGPT
-
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.
🐋 Put MySQL DB in docker (reworkd#492)
- Loading branch information
1 parent
8b16800
commit f0c137a
Showing
9 changed files
with
102 additions
and
53 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
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,3 @@ | ||
FROM mysql:8.0 | ||
|
||
ADD setup.sql /docker-entrypoint-initdb.d |
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,11 @@ | ||
-- Prisma requires DB creation privileges to create a shadow database (https://pris.ly/d/migrate-shadow) | ||
-- This is not available to our user by default, so we must manually add this | ||
|
||
-- Create the user | ||
CREATE USER IF NOT EXISTS 'reworkd_platform'@'%' IDENTIFIED BY 'reworkd_platform'; | ||
|
||
-- Grant the necessary permissions | ||
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT ON *.* TO 'reworkd_platform'@'%'; | ||
|
||
-- Apply the changes | ||
FLUSH PRIVILEGES; |
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
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,20 +1,20 @@ | ||
#!/bin/env sh | ||
|
||
# copy .env file if not exists | ||
[ ! -f .env ] && cp .env.example .env | ||
[ ! -f .env ] && [ -f .env.example ] && cp .env.example .env | ||
source .env | ||
|
||
# change schema.prisma | ||
sed -ie 's/mysql/sqlite/g' prisma/schema.prisma | ||
sed -ie 's/@db.Text//' prisma/schema.prisma | ||
# Ensure DB is available before running Prisma commands | ||
./wait-for-db.sh db 3306 | ||
|
||
# Add Prisma and generate Prisma client | ||
npx prisma generate | ||
# Generate db when not exists | ||
source .env | ||
# Run Prisma commands | ||
if [[ ! -f "/app/prisma/${DATABASE_URL:5}" ]]; then | ||
npx prisma migrate dev --name init | ||
npx prisma db push | ||
fi | ||
|
||
# Generate Prisma client | ||
npx prisma generate | ||
|
||
# run cmd | ||
exec "$@" |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
host="$1" | ||
port="$2" | ||
|
||
until echo "SELECT 1;" | nc "$host" "$port" > /dev/null 2>&1; do | ||
>&2 echo "Database is unavailable - Sleeping..." | ||
sleep 2 | ||
done | ||
|
||
>&2 echo "Database is available! Continuing..." |
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