Przeglądaj źródła

Merge pull request #555 from lihuaiyu0131/master

1.Docker支持部署最新版本; 2.优化构建速度,无须再次下载包;
master
zhayujie GitHub 1 rok temu
rodzic
commit
4a5e3e433b
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 48 dodań i 3 usunięć
  1. +5
    -3
      common/expired_dict.py
  2. +35
    -0
      docker/Dockerfile.latest
  3. +8
    -0
      docker/build.latest.sh

+ 5
- 3
common/expired_dict.py Wyświetl plik

@@ -1,4 +1,5 @@
from datetime import datetime, timedelta
import time


class ExpiredDict(dict):
def __init__(self, expires_in_seconds):
@@ -7,7 +8,8 @@ class ExpiredDict(dict):

def __getitem__(self, key):
value, expiry_time = super().__getitem__(key)
if datetime.now() > expiry_time:
# 如果元素已过期,则从字典中删除该元素并抛出 KeyError 异常
if time.monotonic() > expiry_time:
del self[key]
raise KeyError("expired {}".format(key))
self.__setitem__(key, value)
@@ -38,4 +40,4 @@ class ExpiredDict(dict):
return [(key, self[key]) for key in self.keys()]
def __iter__(self):
return self.keys().__iter__()
return self.keys().__iter__()

+ 35
- 0
docker/Dockerfile.latest Wyświetl plik

@@ -0,0 +1,35 @@
FROM python:3.7.9-alpine

LABEL maintainer="foo@bar.com"
ARG TZ='Asia/Shanghai'

ARG CHATGPT_ON_WECHAT_VER

ENV BUILD_PREFIX=/app \
BUILD_OPEN_AI_API_KEY='YOUR OPEN AI KEY HERE'

COPY chatgpt-on-wechat.tar.gz ./chatgpt-on-wechat.tar.gz

RUN apk add --no-cache \
bash \
&& tar -xf chatgpt-on-wechat.tar.gz \
&& mv chatgpt-on-wechat ${BUILD_PREFIX} \
&& cd ${BUILD_PREFIX} \
&& cp config-template.json ${BUILD_PREFIX}/config.json \
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json \
&& /usr/local/bin/python -m pip install --no-cache --upgrade pip \
&& pip install --no-cache \
itchat-uos==1.5.0.dev0 \
openai

WORKDIR ${BUILD_PREFIX}

ADD ./entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh \
&& adduser -D -h /home/noroot -u 1000 -s /bin/bash noroot \
&& chown noroot:noroot ${BUILD_PREFIX}

USER noroot

ENTRYPOINT ["/entrypoint.sh"]

+ 8
- 0
docker/build.latest.sh Wyświetl plik

@@ -0,0 +1,8 @@
#!/bin/bash

# move chatgpt-on-wechat
tar -zcf chatgpt-on-wechat.tar.gz --exclude=../../chatgpt-on-wechat/docker ../../chatgpt-on-wechat

# build image
docker build -f Dockerfile.alpine \
-t zhayujie/chatgpt-on-wechat .

Ładowanie…
Anuluj
Zapisz