Skip to content

Commit

Permalink
Merge pull request lindsey98#51 from Areedd/main
Browse files Browse the repository at this point in the history
创建浏览器插件后端的Docker部署方式
  • Loading branch information
lindsey98 authored Dec 30, 2024
2 parents c461e2d + 41df37f commit 12a2412
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Plugin_for_Chrome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ Plugin_for_Chrome/
```sh
python app.py
```
**或者**
使用Docker进行部署
```sh
docker build -t phishpedia-app .
docker run -p 5000:5000 phishpedia-app
```
### 使用插件
Expand Down
36 changes: 36 additions & 0 deletions Plugin_for_Chrome/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use Ubuntu 20.04 as the base image
FROM ubuntu:20.04
# Prevent interactive prompts during installation
ARG DEBIAN_FRONTEND=noninteractive
# Install Miniconda
RUN apt-get update && apt-get install -y wget && \
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda && \
rm Miniconda3-latest-Linux-x86_64.sh
# Add Miniconda to PATH
ENV PATH="/opt/miniconda/bin:${PATH}"
# Set working directory
WORKDIR /workspace
# Install git, unzip and other dependencies
RUN apt-get install -y git unzip libgl1-mesa-glx libglib2.0-0
# Clone the Phishpedia project from GitHub into the container
RUN git clone https://github.com/lindsey98/Phishpedia.git /workspace/Phishpedia
# Change to the project directory and run setup.sh to configure the environment
WORKDIR /workspace/Phishpedia
# Install dos2unix
RUN apt-get install -y dos2unix
# Convert setup.sh to Unix format and RUN it
RUN dos2unix setup.sh
RUN chmod +x setup.sh
RUN bash setup.sh || true
# Install Flask and Flask-CORS
RUN /opt/miniconda/envs/phishpedia/bin/pip install "werkzeug>=2.3.7" "flask>=2.3.3" "flask-cors>=4.0.0"
# Ensure Conda is initialized and phishpedia environment is activated by default
RUN echo "source /opt/miniconda/etc/profile.d/conda.sh && conda activate phishpedia" >> ~/.bashrc
# Set the default command to execute when the container starts
CMD ["bash", "-c", "source /opt/miniconda/etc/profile.d/conda.sh && conda activate phishpedia && cd /workspace/Phishpedia && python app.py"]
# Expose the port that the application may use (assuming app.py uses port 5000)
EXPOSE 5000
# Add health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:5000/ || exit 1
17 changes: 16 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,20 @@ def analyze():
return jsonify("ERROR"), 500


def is_running_in_docker():
"""检查是否在 Docker 环境中运行"""
# 方法1:检查 /.dockerenv 文件是否存在
docker_env = os.path.exists('/.dockerenv')
# 方法2:检查 cgroup 中是否包含 docker 字符串
try:
with open('/proc/1/cgroup', 'r') as f:
return docker_env or 'docker' in f.read()
except (IOError, OSError): # 明确指定可能的异常类型
return docker_env


if __name__ == '__main__':
app.run(debug=False)
if is_running_in_docker():
app.run(host='0.0.0.0', port=5000, debug=False)
else:
app.run(debug=False)

0 comments on commit 12a2412

Please sign in to comment.