From 70703590b7e2ebd1ea018bd2f6ac78abfdb48761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=9B=88=20=EB=B3=80?= Date: Fri, 21 Jun 2024 10:44:44 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B5=9C=EC=B4=88=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 20 ++++++++++++++ app/app.py | 63 ++++++++++++++++++++++++++++++++++++++++++++ app/requirements.txt | 4 +++ 3 files changed, 87 insertions(+) create mode 100644 Dockerfile create mode 100644 app/app.py create mode 100644 app/requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9c2e6d4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.9-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + build-essential \ + curl \ + software-properties-common \ + git \ + && rm -rf /var/lib/apt/lists/* + +COPY ./app/ . + +RUN pip3 install -r requirements.txt + +EXPOSE 8501 + +HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health + +ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"] diff --git a/app/app.py b/app/app.py new file mode 100644 index 0000000..1d76547 --- /dev/null +++ b/app/app.py @@ -0,0 +1,63 @@ +import streamlit as st +import pandas as pd +import requests +import os +import git +import json + +token = os.environ['GIT_TOKEN'] +# 사용자 목록 +user = ['변정훈1', '변정훈2', '변정훈3'] + +repo_url = f'https://sa_8001:{token}@lab.jhcloud.kr/sa_8001/test_json.git' +local_path = 'repo' + +# JSON 데이터 가져오기 +if os.path.exists(local_path): + repo = git.Repo(local_path) + repo.remote().pull() +else: + repo = git.Repo.clone_from(repo_url, local_path) + +json_file_path = os.path.join(local_path, 'test_json.json') + +with open(json_file_path, 'r', encoding='utf-8') as file: + data = json.load(file) + +# response = requests.get(json_url) +# data = response.json() + +# DataFrame으로 변환 +df = pd.DataFrame(data) + +# 테이블로 표시 +st.title('버전 관리') +cols = st.columns([5,5]) + +edited_df = cols[0].data_editor(df, + key="version_table", + hide_index=True, + column_config={ + 'name': st.column_config.TextColumn(label='이름', disabled=True), + 'version': st.column_config.TextColumn(label='버전', disabled=False), + 'user': st.column_config.SelectboxColumn(label='사용자', options=user, required=True), + } + ) + +cols[1].write(st.session_state["version_table"]["edited_rows"]) + +button_cols = st.columns([1, 1]) + +with button_cols[0]: + if st.button('새로고침'): + repo = git.Repo(local_path) + repo.remote().pull() + st.success("새로고침 완료") + +with button_cols[1]: + if st.button('업데이트'): + edited_df.to_json(json_file_path, orient='records', indent=4) + repo.index.add(["/app/"+json_file_path]) + repo.index.commit("버전 업데이트") + repo.remote().push() + st.success("업데이트 완료") diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..e6b1d0c --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1,4 @@ +streamlit +pandas +requests +gitpython