Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ARC-MX committed Jun 4, 2024
1 parent 7bfca5b commit f012918
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 391 deletions.
29 changes: 23 additions & 6 deletions Dockerfile-for-github-action
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
FROM python:3.8-slim-buster as build
FROM python:3.9-bullseye as build

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

ARG TARGETOS
ARG TARGETARCH

WORKDIR /app

COPY scripts/* /app/
# COPY scripts/* /app/
COPY ./requirements.txt /tmp/requirements.txt

RUN apt-get --allow-releaseinfo-change update \
&& apt-get install -y --no-install-recommends jq chromium chromium-driver tzdata\
&& apt-get install -y --no-install-recommends jq chromium chromium-driver tzdata cmake \
&& ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& dpkg-reconfigure --frontend noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

RUN cd /tmp \
&& python3 -m pip install --upgrade pip \
&& python3 -m pip install --upgrade pip

# RUN if [${TARGETARCH} == "arm"]; then \
# cd /tmp \
# && curl -O -L https://github.com/nknytk/built-onnxruntime-for-raspberrypi-linux/raw/master/wheels/buster/onnxruntime-1.8.1-cp39-cp39-linux_armv7l.whl \
# && PIP_ROOT_USER_ACTION=ignore pip3 install onnxruntime-1.8.1-cp39-cp39-linux_armv7l.whl \
# && PIP_ROOT_USER_ACTION=ignore pip3 install cmake==3.14.3; \
# fi

# RUN if [${TARGETARCH} == "arm64"]; then \
# cd /tmp \
# && PIP_ROOT_USER_ACTION=ignore pip3 install onnxruntime==1.8.1; \
# fi

RUN cd /tmp \
&& PIP_ROOT_USER_ACTION=ignore pip install \
--disable-pip-version-check \
--no-cache-dir \
Expand All @@ -25,7 +42,7 @@ RUN cd /tmp \
&& pip cache purge \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/log/*

ENV LANG C.UTF-8

CMD ["python"]
93 changes: 10 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# ⚡️国家电网电力获取

[![Docker Image CI](https://github.com/renhaiidea/sgcc_electricity/actions/workflows/docker-image.yml/badge.svg)](https://github.com/renhaiidea/sgcc_electricity/actions/workflows/docker-image.yml)
[![Image Size](https://img.shields.io/docker/image-size/renhai/sgcc_electricity)](https://hub.docker.com/r/renhai/sgcc_electricity)
[![Docker Pull](https://img.shields.io/docker/pulls/renhai/sgcc_electricity?color=%2348BB78&logo=docker&label=pulls)](https://hub.docker.com/r/renhai/sgcc_electricity)
[![Docker Image CI](https://github.com/ARC-MX/sgcc_electricity_new/actions/workflows/docker-image.yml/badge.svg)](https://github.com/ARC-MX/sgcc_electricity_new/actions/workflows/docker-image.yml)
[![Image Size](https://img.shields.io/docker/image-size/arcw/sgcc_electricity)](https://hub.docker.com/r/arcw/sgcc_electricity)
[![Docker Pull](https://img.shields.io/docker/pulls/arcw/sgcc_electricity?color=%2348BB78&logo=docker&label=pulls)](https://hub.docker.com/r/arcw/sgcc_electricity)

<p align="center">
<img src="assets/image-20230730135540291.png" alt="mini-graph-card" width="400">
Expand Down Expand Up @@ -36,7 +36,7 @@

> - `linux/amd64`:适用于 x86-64(amd64)架构的 Linux 系统,例如windows电脑。
> - `linux/arm64`:适用于 ARMv8 架构的 Linux 系统,例如树莓派,N1盒子。
> - 其他架构比如32位arm/v7,不提供docker镜像,可参考[github仓库](https://github.com/renhaiidea/sgcc_electricity.git)[Dockerfile-for-github-action-armv7](%B9%E9%B5%B5%2FDockerfile-for-github-action-armv7)自行部署。
> - 其他架构比如32位arm/v7,不提供docker镜像,可参考[github仓库](https://github.com/ARC-MX/sgcc_electricity_new.git)[Dockerfile-for-github-action-armv7](%B9%E9%B5%B5%2FDockerfile-for-github-action-armv7)自行部署。
## 二、实现流程

Expand All @@ -53,15 +53,16 @@
### 1)方法一(推荐):docker镜像部署,速度快

1. 安装docker和homeassistant,[Homeassistant极简安装法](https://github.com/renhaiidea/easy-homeassistant)
2. 创建项目文件夹
2. 克隆仓库

```bash
mkdir sgcc_electricity
cd sgcc_electricity
git clone https://github.com/ARC-MX/sgcc_electricity_new.git
cd sgcc_electricity_new
```
3. 创建环境变量文件

```bash
cp example.env .env
vim .env
```

Expand Down Expand Up @@ -101,96 +102,22 @@
# 日志级别
LOG_LEVEL="INFO" # 例如“DEBUG”可以查看出错情况
```
4. 编写docker-compose.yml文件

```bash
vim docker-compose.yml
```

填入以下内容

```yaml
version: "3"

services:
app:
env_file:
- .env
depends_on:
- mongo
image: renhai/sgcc_electricity:latest
container_name: sgcc_electricity
networks:
sgcc_network:
environment:
- SET_CONTAINER_TIMEZONE=true
- CONTAINER_TIMEZONE=Asia/Shanghai
restart: unless-stopped
command: python3 main.py

# 默认将近30天数据写入mongo数据库,方便查询
mongo:
image: mongo:4.4.18
restart: always
container_name: mongo-for-sgcc
networks:
sgcc_network:
environment:
MONGO_INITDB_ROOT_USERNAME: USERNAME # 修改为自己的用户名
MONGO_INITDB_ROOT_PASSWORD: PASSWORD # 修改为自己的密码
MONGODB_DATABASE: "homeassistant" # 修改为自己的数据库名,和.env中的数据库名一致
CONTAINER_TIMEZONE: Asia/Shanghai
volumes:
- ./db:/data/db

networks:
sgcc_network:
```
5. 运行
4. 运行

```bash
docker compose up --build
# 或者后台运行
docker compose up -d --build
```
6. 更新容器
5. 更新容器

```bash
docker compose down # 删除容器
docker compose pull # 更新镜像
docker compose up # 重新运行
```

### 2)方法二:本地自行构建容器

1. 克隆仓库

```bash
git clone https://github.com/ARC-MX/sgcc_electricity_new.git
cd sgcc_electricity_new
```
2. 参考example.env编写.env文件

```
cp example.env ./env
```
3. 查阅docker-compose文件,默认不需要修改
4. 运行

```bash
docker compose up --build
# 或者后台运行
docker compose up -d --build
```

### 3)方法三:不安装docker,安装python环境后直接运行:

克隆仓库之后,参考Dockerfile的命令,`<u>`自行配置安装chrome浏览器和selenium浏览器驱动 `</u>`,安装mongodb,将example.env文件复制为.env文件到scripts文件夹下,然后运行main.py文件。

### 4)方法四:使用可视化docker管理工具[portainer]([url](https://www.portainer.io/))部署:

方法见 [issue #26](https://github.com/renhai-lab/sgcc_electricity/issues/26#issuecomment-1752273119)

## 四、配置与使用

### 1)**第一次运行需要创建并填写.env文件,按文件说明进行填写。**
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:
- .env
depends_on:
- mongo
# image: renhai/sgcc_electricity:latest # armv7 32架构的镜像为armv7-latest
build:
context: .
dockerfile: Dockerfile
image: arcw/sgcc_electricity:latest # armv8
# build:
# context: .
# dockerfile: Dockerfile
container_name: sgcc_electricity
networks:
sgcc_network:
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# cmake==3.10.3
requests==2.31.0
selenium==4.5.0
schedule==1.1.0
Pillow==9.2.0
undetected_chromedriver==3.4.7
pymongo~=3.12.0
onnxruntime==1.17.3
python-dotenv
opencv-python
onnxruntime
opencv-python
35 changes: 0 additions & 35 deletions 归档/Dockerfile-for-github-action-armv7

This file was deleted.

Loading

0 comments on commit f012918

Please sign in to comment.