From 3458955883edb76f3178a3a06249c01f33f4e25a Mon Sep 17 00:00:00 2001 From: aki Date: Sat, 11 Jan 2025 21:35:12 +0800 Subject: [PATCH] add proxy for china base host --- Makefile | 20 +++++++++++++++----- api/Dockerfile | 22 ++++++++++++++++++++++ web/Dockerfile | 21 +++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ff61a00313..7f22959ad2 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,28 @@ # Variables -DOCKER_REGISTRY=langgenius -WEB_IMAGE=$(DOCKER_REGISTRY)/dify-web -API_IMAGE=$(DOCKER_REGISTRY)/dify-api +DOCKER_REGISTRY=akiyu303 +WEB_IMAGE=$(DOCKER_REGISTRY)/lefeng-web +API_IMAGE=$(DOCKER_REGISTRY)/lefeng-api VERSION=latest # Build Docker images build-web: @echo "Building web Docker image: $(WEB_IMAGE):$(VERSION)..." - docker build -t $(WEB_IMAGE):$(VERSION) ./web + docker build \ + --build-arg HTTP_PROXY=http://host.docker.internal:1081 \ + --build-arg HTTPS_PROXY=http://host.docker.internal:1081 \ + --build-arg NO_PROXY=localhost,127.0.0.1 \ + --add-host=host.docker.internal:host-gateway \ + -t $(WEB_IMAGE):$(VERSION) ./web @echo "Web Docker image built successfully: $(WEB_IMAGE):$(VERSION)" build-api: @echo "Building API Docker image: $(API_IMAGE):$(VERSION)..." - docker build -t $(API_IMAGE):$(VERSION) ./api + docker build \ + --build-arg HTTP_PROXY=http://host.docker.internal:1081 \ + --build-arg HTTPS_PROXY=http://host.docker.internal:1081 \ + --build-arg NO_PROXY=localhost,127.0.0.1 \ + --add-host=host.docker.internal:host-gateway \ + -t $(API_IMAGE):$(VERSION) ./api @echo "API Docker image built successfully: $(API_IMAGE):$(VERSION)" # Push Docker images diff --git a/api/Dockerfile b/api/Dockerfile index df676f1926..fb9224b00f 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,6 +1,14 @@ # base image FROM python:3.12-slim-bookworm AS base +# Add proxy configuration +ARG HTTP_PROXY +ARG HTTPS_PROXY +ARG NO_PROXY +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} + WORKDIR /app/api # Install Poetry @@ -19,6 +27,10 @@ ENV POETRY_VIRTUALENVS_CREATE=true ENV POETRY_REQUESTS_TIMEOUT=15 FROM base AS packages +# Inherit proxy settings from base +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} # if you located in China, you can use aliyun mirror to speed up # RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources @@ -30,8 +42,18 @@ RUN apt-get update \ COPY pyproject.toml poetry.lock ./ RUN poetry install --sync --no-cache --no-root +FROM base AS builder +# Inherit proxy settings from base +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} + # production stage FROM base AS production +# Inherit proxy settings from base +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} ENV FLASK_APP=app.py ENV EDITION=SELF_HOSTED diff --git a/web/Dockerfile b/web/Dockerfile index 6118adbca4..01ef3c09e2 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -2,6 +2,14 @@ FROM node:20-alpine3.20 AS base LABEL maintainer="takatost@gmail.com" +# Add proxy configuration +ARG HTTP_PROXY +ARG HTTPS_PROXY +ARG NO_PROXY +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} + # if you located in China, you can use aliyun mirror to speed up # RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories @@ -10,6 +18,10 @@ RUN apk add --no-cache tzdata # install packages FROM base AS packages +# Inherit proxy settings from base +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} WORKDIR /app/web @@ -23,6 +35,11 @@ RUN yarn install --frozen-lockfile # build resources FROM base AS builder +# Inherit proxy settings from base +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} + WORKDIR /app/web COPY --from=packages /app/web/ . COPY . . @@ -32,6 +49,10 @@ RUN yarn build # production stage FROM base AS production +# Inherit proxy settings from base +ENV HTTP_PROXY=${HTTP_PROXY} +ENV HTTPS_PROXY=${HTTPS_PROXY} +ENV NO_PROXY=${NO_PROXY} ENV NODE_ENV=production ENV EDITION=SELF_HOSTED