Skip to content

Commit

Permalink
Replace Docker Hub with Aliyun repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
ARC-MX committed Jun 7, 2024
1 parent 11c4bac commit 999591b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 26 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,24 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log into registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Log into docker hub registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Build and push Docker image
run: |
PLATFORMS=linux/arm64,linux/amd64,linux/arm/v7
PLATFORMS=linux/arm64,linux/amd64
DOCKER_IMAGE=arcw/sgcc_electricity
docker buildx build --platform $PLATFORMS -t $DOCKER_IMAGE:latest -t $DOCKER_IMAGE:1.4.0 --file Dockerfile-for-github-action --push .
docker buildx build --platform $PLATFORMS -t $DOCKER_IMAGE:latest -t $DOCKER_IMAGE:1.4.0 --file Dockerfile-for-github-action --push .
- name: pull Docker image
run: |
docker pull mongo:4.4.18
docker tag mongo:4.4.18 registry.cn-hangzhou.aliyuncs.com/arcw/mongo:4.4.18
- name: Log into Aliyun hub registry and push Docker image
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.ALIYUN_USERNAME }} --password-stdin registry.cn-hangzhou.aliyuncs.com
PLATFORMS=linux/arm64,linux/amd64
DOCKER_IMAGE=registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity
docker buildx build --platform $PLATFORMS -t $DOCKER_IMAGE:latest -t $DOCKER_IMAGE:1.4.0 --file Dockerfile-for-github-action --push .
docker push registry.cn-hangzhou.aliyuncs.com/arcw/mongo:4.4.18
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-buster as build
FROM python:3.9-bullseye as build

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
Expand Down
34 changes: 20 additions & 14 deletions Dockerfile-for-github-action
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ ARG TARGETARCH
WORKDIR /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 \
Expand All @@ -18,22 +17,29 @@ RUN apt-get --allow-releaseinfo-change update \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

RUN cd /tmp \
&& 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/blob/master/wheels/bullseye/onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl \
&& PIP_ROOT_USER_ACTION=ignore pip3 install onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl \
&& PIP_ROOT_USER_ACTION=ignore pip3 install cmake==3.14.3; \
fi
# RUN cd /tmp \
# && python3 -m pip install --upgrade pip \
# && echo '#!/bin/bash\n \
# if [ "$TARGETARCH" = "arm" ]; then\n \
# cd /tmp\n \
# curl -O -L https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/numpy-1.23.5-cp39-cp39-linux_armv7l.whl\n \
# curl -v -o onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl https://github.com/nknytk/built-onnxruntime-for-raspberrypi-linux/blob/master/wheels/bullseye/onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl\n \
# PIP_ROOT_USER_ACTION=ignore pip3 install numpy-1.23.5-cp39-cp39-linux_armv7l.whl\n \
# PIP_ROOT_USER_ACTION=ignore pip3 install onnxruntime-1.16.0-cp39-cp39-linux_armv7l.whl\n \
# else\n \
# cd /tmp\n \
# PIP_ROOT_USER_ACTION=ignore pip3 install numpy==1.23.5 onnxruntime==1.17.3 \n \
# fi \n' > ./targetArch.sh \
# && bash ./targetArch.sh \
# && rm -rf /tmp/* \
# && pip cache purge \
# && rm -rf /var/lib/apt/lists/* \
# && rm -rf /var/log/*

RUN if [${TARGETARCH} == "arm64"]; then \
cd /tmp \
&& PIP_ROOT_USER_ACTION=ignore pip3 install onnxruntime==1.17.3; \
fi
COPY ./requirements.txt /tmp/requirements.txt

RUN cd /tmp \
&& python3 -m pip install --upgrade pip \
&& PIP_ROOT_USER_ACTION=ignore pip install \
--disable-pip-version-check \
--no-cache-dir \
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

> - `linux/amd64`:适用于 x86-64(amd64)架构的 Linux 系统,例如windows电脑。
> - `linux/arm64`:适用于 ARMv8 架构的 Linux 系统,例如树莓派3+,N1盒子等。
> - `linux/armv7`适用于 ARMv8 架构的 Linux 系统,例如树莓派2,玩客云等。
> - `linux/armv7`暂不提供 ARMv7 架构的 Linux 系统,例如树莓派2,玩客云等,主要原因是onnx-runtime没有armv7版本的库,用户可以参考 [https://github.com/nknytk/built-onnxruntime-for-raspberrypi-linux.git](https://github.com/nknytk/built-onnxruntime-for-raspberrypi-linux.git)自行安装库然后编译docker镜像
## 二、实现流程

Expand All @@ -63,6 +63,8 @@

```bash
git clone https://github.com/ARC-MX/sgcc_electricity_new.git
# 如果github网络环境不好的话可以使用国内镜像,完全同步的,个人推荐使用国内镜像
# git clone https://gitee.com/ARC-MX/sgcc_electricity_new.git
cd sgcc_electricity_new
```
3. 创建环境变量文件
Expand Down Expand Up @@ -110,6 +112,10 @@
```
4. 运行

我已经优化了镜像环境,将镜像的地址配置为阿里云,如果要使用docker hub的源可以将docker-compose.yml中
image: registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity:latest 改为 arcw/sgcc_electricity:latest
image: registry.cn-hangzhou.aliyuncs.com/arcw/mongo:4.4.18 改为 mongo:4.4.18

```bash
docker compose up --build
# 或者后台运行
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- .env
depends_on:
- mongo
image: arcw/sgcc_electricity:latest # armv8
image: registry.cn-hangzhou.aliyuncs.com/arcw/sgcc_electricity:latest # for use docker.io: arcw/sgcc_electricity:latest
# build:
# context: .
# dockerfile: Dockerfile
Expand All @@ -22,7 +22,7 @@ services:
command: python3 main.py
# 默认将近30天数据写入mongo数据库,方便查询
mongo:
image: mongo:4.4.18
image: registry.cn-hangzhou.aliyuncs.com/arcw/mongo:4.4.18 # for use docker.io: mongo:4.4.18
restart: always
container_name: mongo-for-sgcc
networks:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ schedule==1.1.0
Pillow==9.2.0
undetected_chromedriver==3.4.7
pymongo~=3.12.0
# onnxruntime==1.17.3
onnxruntime==1.17.3
# numpy==1.24.3
python-dotenv
6 changes: 3 additions & 3 deletions scripts/data_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _get_webdriver(self):
def _login(self, driver):

driver.get(LOGIN_URL)
logging.info("Open LOGIN_URL:{LOGIN_URL}.\r")
logging.info(f"Open LOGIN_URL:{LOGIN_URL}\r")
time.sleep(self.RETRY_WAIT_TIME_OFFSET_UNIT)
# swtich to username-password login page
driver.find_element(By.CLASS_NAME, "user").click()
Expand All @@ -319,9 +319,9 @@ def _login(self, driver):
# input username and password
input_elements = driver.find_elements(By.CLASS_NAME, "el-input__inner")
input_elements[0].send_keys(self._username)
logging.info(f"input_elements username : {self._username}.\r")
logging.info(f"input_elements username : {self._username}\r")
input_elements[1].send_keys(self._password)
logging.info(f"input_elements password : {self._password}.\r")
logging.info(f"input_elements password : {self._password}\r")
# click agree button
self._click_button(driver, By.XPATH, '//*[@id="login_box"]/div[2]/div[1]/form/div[1]/div[3]/div/span[2]')
logging.info("Click the Agree option.\r")
Expand Down

0 comments on commit 999591b

Please sign in to comment.