From 9c8922a26d9f264fe0bee890bd7cb2d4a878919e Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Mon, 24 Oct 2022 00:31:24 +0800 Subject: [PATCH] feat: docker optimizing (#948) * chore: feat/docker-optimizing * feat: docker nginx gzip config --- Dockerfile | 67 ++++++++++++++++++++++------------- docker/nocobase/nocobase.conf | 6 ++++ 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28bbf8203..667391818 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,48 @@ +FROM node:16 as builder +ARG VERDACCIO_URL + +RUN apt-get update && apt-get install -y jq +WORKDIR /tmp +COPY . /tmp +RUN npx npm-cli-adduser --username test --password test -e test@nocobase.com -r $VERDACCIO_URL +RUN cd /tmp && \ + NEWVERSION="$(cat lerna.json | jq '.version' | tr -d '"').$(date +%s)" \ + && tmp=$(mktemp) \ + && jq ".version = \"${NEWVERSION}\"" lerna.json > "$tmp" && mv "$tmp" lerna.json +RUN yarn install && yarn build + +RUN git checkout -b release \ + && yarn version:alpha -y \ + && git config user.email "test@mail.com" \ + && git config user.name "test" && git add . \ + && git commit -m "chore(versions): test publish packages xxx" \ + && yarn release:force --registry $VERDACCIO_URL + +RUN yarn config set registry $VERDACCIO_URL +WORKDIR /app +RUN cd /app \ + && yarn create nocobase-app my-nocobase-app -a -e APP_ENV=production \ + && cd /app/my-nocobase-app \ + && yarn install --production + +RUN cd /app \ + && rm -rf my-nocobase-app/packages/app/client/src/.umi \ + && rm -rf nocobase.tar.gz \ + && find ./my-nocobase-app/node_modules/china-division/dist -name '*.csv' -delete \ + && find ./my-nocobase-app/node_modules/china-division/dist -name '*.sqlite' -delete \ + && tar -zcf ./nocobase.tar.gz -C /app/my-nocobase-app . + + FROM node:16-stretch-slim +RUN apt-get update && apt-get install -y nginx + +RUN rm -rf /etc/nginx/sites-enabled/default +COPY ./docker/nocobase/nocobase.conf /etc/nginx/sites-enabled/nocobase.conf +COPY --from=builder /app/nocobase.tar.gz /app/nocobase.tar.gz WORKDIR /app/nocobase -# COPY ./docker/nocobase/sources.list /etc/apt/sources.list - -RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \ - && case "${dpkgArch##*-}" in \ - amd64) ARCH='x64';; \ - ppc64el) ARCH='ppc64le';; \ - s390x) ARCH='s390x';; \ - arm64) ARCH='arm64';; \ - armhf) ARCH='armv7l';; \ - i386) ARCH='x86';; \ - *) echo "unsupported architecture"; exit 1 ;; \ - esac \ - && set -ex \ - # libatomic1 for arm - && apt-get update && apt-get install -y nginx - -RUN rm -rf /etc/nginx/sites-enabled/default -COPY ./docker/nocobase-full/nocobase.conf /etc/nginx/sites-enabled/nocobase.conf -COPY . /app/nocobase -RUN cd /app/nocobase & yarn install -RUN cd /app/nocobase & yarn build - -COPY ./docker/nocobase-full/docker-entrypoint.sh /app/ -# COPY docker-entrypoint.sh /usr/local/bin/ -# ENTRYPOINT ["docker-entrypoint.sh"] +COPY ./docker/nocobase/docker-entrypoint.sh /app/ CMD ["/app/docker-entrypoint.sh"] + diff --git a/docker/nocobase/nocobase.conf b/docker/nocobase/nocobase.conf index 57d5ae427..9a7fe50f4 100644 --- a/docker/nocobase/nocobase.conf +++ b/docker/nocobase/nocobase.conf @@ -5,6 +5,12 @@ server { index index.html; client_max_body_size 20M; + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; + location /storage/uploads/ { alias /app/nocobase/storage/uploads/; autoindex off;