1. 컨테이너 내에 리브레오피스 설치 실행
FROM python:3.8-slim
RUN apt-get update && apt-get install -y \
python3-pip \
libaio1 unzip \
libpq-dev \
openjdk-17-jdk \
libreoffice \
fonts-unfonts-core \
wget \
gnupg && \
rm -rf /var/lib/apt/lists/*
RUN wget -O /tmp/H2Orestart-0.6.6.oxt https://extensions.libreoffice.org/assets/downloads/2303/1720302570/H2Orestart-0.6.6.oxt && \
libreoffice --headless --norestore --nofirststartwizard --accept="socket,host=0.0.0.0,port=2002;urp;" --nodefault --nologo & \
sleep 10 && \
unopkg add --shared /tmp/H2Orestart-0.6.6.oxt && \
pkill -f soffice
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64
ENV PATH $JAVA_HOME/bin:$PATH
ENV ORACLE_HOME /opt/oracle/instantclient_21_12
ENV LD_LIBRARY_PATH /opt/oracle/instantclient_21_12
ENV PATH $PATH:/opt/oracle/instantclient_21_12
ENV PATH $PATH:/usr/lib/libreoffice/program
COPY ./oracle_client/instantclient-basic-linux.x64-21.12.0.0.0dbru.zip /tmp/
RUN unzip /tmp/instantclient-basic-linux.x64-21.12.0.0.0dbru.zip -d /opt/oracle
RUN groupadd -r django && useradd -r -g django -d /django_back -s /sbin/nologin -c "Docker image user" django
WORKDIR /django_back
COPY requirements.txt /django_back/requirements.txt
RUN pip install -r /django_back/requirements.txt
RUN python -m spacy download en_core_web_sm
RUN python -m spacy download ko_core_news_sm
COPY . /django_back
RUN chown -R django:django /django_back
USER django
RUN python3 --version
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
from django.core.files.temp import NamedTemporaryFile
def convert_doc_to_docx(input_file):
with NamedTemporaryFile(delete=False, suffix='.doc') as tmp:
for chunk in input_file.chunks():
tmp.write(chunk)
tmp_path = tmp.name
output_path = tmp_path.replace('.doc', '.docx')
subprocess.run([
'libreoffice', '--convert-to', 'docx', '--headless',
'--outdir', os.path.dirname(tmp_path), tmp_path
], check=True)
with open(output_path, 'rb') as f:
docx_content = f.read()
os.unlink(tmp_path)
os.unlink(output_path)
return ContentFile(docx_content, name=os.path.basename(output_path))
def convert_hwp_to_docx(input_file):
with NamedTemporaryFile(delete=False, suffix='.hwp') as tmp:
for chunk in input_file.chunks():
tmp.write(chunk)
tmp_path = tmp.name
output_path = tmp_path.replace('.hwp', '.docx')
subprocess.run([
'libreoffice', '--convert-to', 'docx', '--headless',
'--outdir', os.path.dirname(tmp_path), tmp_path
], check=True)
with open(output_path, 'rb') as f:
docx_content = f.read()
os.unlink(tmp_path)
os.unlink(output_path)
return ContentFile(docx_content, name=os.path.basename(output_path))
2.api로 소통
FROM python:3.12-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y wget curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -sSL https://install.python-poetry.org | python3 - && \
ln -s /root/.local/bin/poetry /usr/local/bin/poetry
WORKDIR /app
COPY poetry.lock pyproject.toml /app/
RUN poetry install --no-root
COPY . /app
EXPOSE 8503
CMD ["poetry", "run", "streamlit", "run", "streamlit/main.py", "--server.port", "8503"]
FROM python:3.12-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y wget gnupg software-properties-common default-jre libreoffice python3-pip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN wget -O /tmp/H2Orestart-0.6.6.oxt https://extensions.libreoffice.org/assets/downloads/2303/1720302570/H2Orestart-0.6.6.oxt
RUN libreoffice --headless --norestore --nofirststartwizard --accept="socket,host=0.0.0.0,port=2002;urp;" --nodefault --nologo & \
sleep 10 && \
unopkg add --shared /tmp/H2Orestart-0.6.6.oxt && \
pkill -f soffice
RUN pip install fastapi uvicorn
COPY convert_server.py /convert_server.py
EXPOSE 2002
EXPOSE 8800
CMD ["uvicorn", "convert_server:app", "--host", "0.0.0.0", "--port", "8800"]
version: '3.8'
services:
libreoffice:
build:
context: .
dockerfile: Dockerfile.libreoffice
ports:
- "2002:2002"
- "8800:8800"
volumes:
- shared_data:/shared_data
networks:
- app-network
streamlit:
build:
context: .
dockerfile: Dockerfile.streamlit
ports:
- "8503:8503"
depends_on:
- libreoffice
volumes:
- shared_data:/shared_data
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
shared_data: