-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_db.py
34 lines (25 loc) · 1.03 KB
/
block_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import modal
app = modal.App(name="bitcoin-explore-fy")
db_volume = modal.Volume.from_name("fy_mysql_db")
db_image = modal.Image.from_dockerfile("./mysql-db")
# Define the MySQL service
@app.function(
image=db_image,
keep_warm=1,
# secrets=[
# modal.Secret.from_dotenv() # Looks for `.env` in the current working directory
# ],
volumes={"/var/lib/mysql": db_volume}, # Mount volume to MySQL data directory
# secret=modal.Secret.from_dict({"MYSQL_ROOT_PASSWORD": "my-secret-pw"}), # Securely store credentials
)
def run_mysql():
import subprocess
# Start MySQL in the foreground so the function blocks here.
# 'mysqld' is the server daemon in the official MySQL image.
proc = subprocess.Popen(["mysqld"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Optionally, read or print logs
for line in proc.stderr:
print(line.decode(), end="")
# Wait for MySQL to exit (which will also end the function)
proc.wait()
print("MySQL exited with code:", proc.returncode)