Skip to content

Commit

Permalink
Optimization: optimize docker images size from over 2.2GB to about 760MB
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzhi committed Dec 26, 2019
1 parent e907e96 commit 93c6db4
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 75 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
*.md
UnitTest/
uml/
*.h5
74 changes: 38 additions & 36 deletions Dockerfile37
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
FROM python:3.7
FROM python:3.7-slim-buster

ARG CDV=77.0.3865.40

RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo 'deb http://mirrors.163.com/debian/ jessie main non-free contrib' > /etc/apt/sources.list && \
echo 'deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib' >> /etc/apt/sources.list
RUN sed -i 's/deb.debian.org/ftp.cn.debian.org/g' /etc/apt/sources.list

RUN apt-get -y update && apt-get install -y \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libcups2 \
libdbus-1-3 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxss1 \
libxtst6 \
lsb-release \
unzip \
wget \
xdg-utils \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apt-get -y update
ENV TZ Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

WORKDIR /usr/src/app

RUN wget -c https://dl.lancdn.com/landian/soft/chrome/m/77.0.3865.120_amd64.deb && \
apt-get install -y adwaita-icon-theme at-spi2-core dbus dconf-gsettings-backend dconf-service fonts-liberation glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas libappindicator3-1 libasound2 libasound2-data libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data libavahi-common3 libcolord2 libcups2 libdbus-1-3 libdbusmenu-glib4 libdbusmenu-gtk3-4 libdconf1 libdrm2 libfile-basedir-perl libfile-desktopentry-perl libfile-mimeinfo-perl libfontenc1 libgl1-mesa-glx libglapi-mesa libgnutls-deb0-28 libgtk-3-0 libgtk-3-bin libgtk-3-common libhogweed2 libindicator3-7 libjson-glib-1.0-0 libjson-glib-1.0-common libnettle4 libnspr4 libnss3 libproxy1 librest-0.7-0 libsoup-gnome2.4-1 libsoup2.4-1 libwayland-client0 libwayland-cursor0 libx11-protocol-perl libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-shape0 libxcb-sync1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxkbcommon0 libxmu6 libxmuu1 libxpm4 libxrandr2 libxshmfence1 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 multiarch-support x11-utils x11-xserver-utils xdg-utils xkb-data libgconf2-4 lsb-release && \
dpkg -i 77.0.3865.120_amd64.deb && \
wget -c http://npm.taobao.org/mirrors/chromedriver/LATEST_RELEASE


RUN wget -c https://npm.taobao.org/mirrors/chromedriver/$CDV/chromedriver_linux64.zip && \
apt-get install -y unzip && \
unzip chromedriver_linux64.zip
RUN wget -q https://dl.lancdn.com/landian/soft/chrome/m/77.0.3865.120_amd64.deb && \
dpkg -i 77.0.3865.120_amd64.deb && rm -f 77.0.3865.120_amd64.deb




ENV DEBIAN_FRONTEND noninteractive
ENV TZ Asia/Shanghai

COPY requirements.txt /usr/src/app/
RUN wget -q https://npm.taobao.org/mirrors/chromedriver/$CDV/chromedriver_linux64.zip && \
unzip chromedriver_linux64.zip && rm -f chromedriver_linux64.zip

## install python requirements
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider --no-cache-dir -r requirements.txt
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

COPY . /usr/src/app

## install ntpdate, not accept but saving code
#RUN echo 'deb http://mirrors.163.com/debian/ jessie main non-free contrib \
# deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib \
# deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib' > /etc/apt/sources.list \
# && apt-get update\
# && apt-get install ntpdate -y \

COPY requirements-docker37.txt ./
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements-docker37.txt

#EXPOSE 5010
COPY . .

CMD [ "sh", "-c", "python run.py c && python run.py r" ]
#ENTRYPOINT [ "python", "run.py" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
positional arguments:
operate r: 运行抢票程序, c: 过滤cdn, t: 测试邮箱和server酱,server酱
```
- 如果你的服务器安装了docker与docker-compose, 那么你可以忽略上面的所有步骤,直接按以下步骤操作,即可开始抢票:
- 如果你的服务器安装了docker与docker-compose, 那么你可以忽略上面的**所有**步骤,直接按以下步骤操作,即可开始抢票:
- 前提条件:
- 请确认你安装的docker版本为18.09及以上: `docker -v`
- 请确认你安装的docker-compose版本为1.23.2及以上: `docker-compose -v`
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
image: ticket:v1.2.004
environment:
- PYTHONUNBUFFERED=1
- CAPTCHALOCAL=1
container_name: ticket
depends_on:
- captcha
Expand All @@ -20,6 +21,7 @@ services:
image: yinaoxiong/12306_code_server:amd64 #请根据需要修改image
environment:
- WORKERS=1 #gunicorn works 默认为1可以根据服务器配置自行调整
- PYTHONUNBUFFERED=1
container_name: captcha
networks:
- 12306network
Expand Down
37 changes: 0 additions & 37 deletions docker.sh

This file was deleted.

3 changes: 2 additions & 1 deletion inter/GetRandCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from myUrllib.httpUtils import HTTPClient
from verify.localVerifyCode import Verify
import TickerConfig
import os


if TickerConfig.AUTO_CODE_TYPE == 2:
Expand All @@ -25,7 +26,7 @@ def getRandCode(is_auto_code, auto_code_type, result):
Result = v.verify(result)
return codexy(Ofset=Result, is_raw_input=False)
elif auto_code_type == 3:
print("您已设置使用云打码,但是服务器资源有限,请尽快改为本地打码")
'CAPTCHALOCAL' not in os.environ and print("您已设置使用云打码,但是服务器资源有限,请尽快改为本地打码")
http = HTTPClient(0)
Result = http.send(urls.get("autoVerifyImage"), {"imageFile": result})
if Result and Result.get("code") is 0:
Expand Down
7 changes: 7 additions & 0 deletions requirements-docker37.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bs4==0.0.1
requests==2.18.4
Pillow
wrapcache==1.0.8
ntplib==0.3.3
selenium==3.11.0
fake-useragent==0.1.11

0 comments on commit 93c6db4

Please sign in to comment.