docker deploy

This commit is contained in:
leo
2023-12-31 16:35:43 +08:00
parent ef5b45eb21
commit bf2a285716
2 changed files with 18 additions and 3 deletions

7
docker-compose.yml Normal file
View File

@@ -0,0 +1,7 @@
version: "3"
services:
build_self:
build: .
ports:
- "5001:80"

14
main.py
View File

@@ -1,6 +1,7 @@
import os import os
import streamlit as st import streamlit as st
from loguru import logger
from app.core import settings from app.core import settings
@@ -13,13 +14,20 @@ def new_file():
new_file_name = st.session_state.new_file new_file_name = st.session_state.new_file
if not new_file_name.endswith('.py'): if not new_file_name.endswith('.py'):
new_file_name = f'{new_file_name}.py' new_file_name = f'{new_file_name}.py'
with open(os.path.join(settings.BASE_DIR, 'pages', new_file_name), 'w') as f: logger.debug(f"create new file: {new_file_name}")
f.write('''
content = '''
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import streamlit as st import streamlit as st
{add_content}
st.write('Hello World!') st.write('Hello World!')
''') '''
with open(os.path.join(settings.BASE_DIR, 'pages', new_file_name), 'w') as f:
content = content.format(add_content=f"""st.markdown("# {st.session_state.new_file}")""").strip()
st.write(f"create new file: {new_file_name}, write: ")
st.code(content, language='python')
f.write(content)
with st.sidebar: with st.sidebar: