Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pr-preview: use mirrors for Go and Node modules downloads during docker build #667

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# All-in-one Dockerfile for building the SPX GUI

ARG image_address
FROM ghcr.io/goplus/gop:1.2 AS go-builder
ARG GOP_BASE_IMAGE=ghcr.io/goplus/gop:1.2
ARG NODE_BASE_IMAGE=node:20.11.1
ARG NGINX_BASE_IMAGE=nginx:1.27

FROM ${GOP_BASE_IMAGE} AS go-builder

WORKDIR /app

COPY tools ./tools
COPY spx-backend ./spx-backend

ARG GOPROXY

# Build WASM
WORKDIR /app/tools/fmt
RUN ./build.sh
Expand All @@ -18,12 +23,14 @@ RUN ./build.sh
WORKDIR /app/spx-backend
RUN gop build -o spx-backend ./cmd/spx-backend

FROM ${image_address}node:20.11.1 AS frontend-builder
FROM ${NODE_BASE_IMAGE} AS frontend-builder

WORKDIR /app/spx-gui

COPY spx-gui/package.json spx-gui/package-lock.json ./

ARG NPM_CONFIG_REGISTRY

RUN npm install

COPY spx-gui .
Expand All @@ -34,7 +41,7 @@ COPY --from=go-builder /app/tools/ispx/main.wasm /app/spx-gui/src/assets/ispx/ma

RUN npm run build

FROM ${image_address}nginx:1.27
FROM ${NGINX_BASE_IMAGE}

COPY --from=go-builder /app/spx-backend/spx-backend /app/spx-backend/spx-backend
COPY --from=frontend-builder /app/spx-gui/dist /usr/share/nginx/html
Expand All @@ -47,4 +54,4 @@ EXPOSE 80

WORKDIR /app

CMD ["sh", "-c", "nginx && ./spx-backend/spx-backend"]
CMD ["sh", "-c", "nginx && exec ./spx-backend/spx-backend"]
20 changes: 16 additions & 4 deletions scripts/pr-preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ set -ex

echo "WORKSPACE: ${PWD}"

PREVIEW_URL=http://goplus-builder-pr-${PULL_NUMBER}.goplus-pr-review.svc.jfcs-qa1.local
PREVIEW_URL="http://goplus-builder-pr-${PULL_NUMBER}.goplus-pr-review.svc.jfcs-qa1.local"

echo VITE_PUBLISH_BASE_URL="${PREVIEW_URL}"/ > spx-gui/.env.local
CONTAINER_IMAGE=aslan-spock-register.qiniu.io/goplus/goplus-builder-pr:${PULL_NUMBER}-${PULL_PULL_SHA:0:8}
docker build -t "${CONTAINER_IMAGE}" --build-arg image_address=aslan-spock-register.qiniu.io/goplus/ -f ./Dockerfile . --builder="kube" --push
echo "VITE_PUBLISH_BASE_URL=${PREVIEW_URL}/" > spx-gui/.env.local

GOPLUS_REGISTRY_REPO=aslan-spock-register.qiniu.io/goplus
CONTAINER_IMAGE="${GOPLUS_REGISTRY_REPO}/goplus-builder-pr:${PULL_NUMBER}-${PULL_PULL_SHA:0:8}"
docker build \
--builder kube \
--push \
-f ./Dockerfile \
-t "${CONTAINER_IMAGE}" \
--build-arg GOP_BASE_IMAGE="${GOPLUS_REGISTRY_REPO}/gop:1.2" \
--build-arg NODE_BASE_IMAGE="${GOPLUS_REGISTRY_REPO}/node:20.11.1" \
--build-arg NGINX_BASE_IMAGE="${GOPLUS_REGISTRY_REPO}/nginx:1.27" \
--build-arg GOPROXY=https://goproxy.cn,direct \
--build-arg NPM_CONFIG_REGISTRY=https://registry.npmmirror.com \
.

CURRENT_TIME="$(date "--iso-8601=seconds")"
# generate kubernetes yaml with unique flag for PR
Expand Down
Loading