Skip to content

Commit

Permalink
pr-preview: use mirrors for Go and Node modules downloads during `doc…
Browse files Browse the repository at this point in the history
…ker build` (#667)

- Updated `Dockerfile`:
  - Introduced `ARG`s for base images and custom mirror configs.
  - Modified the `CMD` instruction to use `exec` for proper signal
    handling.
- Updated `scripts/pr-preview.sh`:
  - Refined `docker build` command to utilize the newly introduced
    `ARG`s.
  • Loading branch information
aofei authored Jul 23, 2024
1 parent 2ea61bf commit bae5459
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
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

0 comments on commit bae5459

Please sign in to comment.