From 8b9acde16a1ffce00b240f157f91e3b5f5dd1de4 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Wed, 9 Oct 2024 19:06:42 +0800 Subject: [PATCH] chore: start up scripts in docker (#5361) * chore: start up scripts * fix: build image * fix: commit hash * chore: dockerfile * chore: dockerfile * chore: dockerfile --- .github/workflows/build-docker-image.yml | 2 +- Dockerfile | 9 +++++---- docker/nocobase/docker-entrypoint.sh | 10 ++++++++++ storage/.gitignore | 4 +++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 80eced7754..d542bda1df 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -92,7 +92,7 @@ jobs: file: Dockerfile build-args: | VERDACCIO_URL=http://localhost:4873/ - COMMIT_HASH=${GITHUB_SHA} + COMMIT_HASH=${{ github.sha }} push: true tags: ${{ steps.set-tags.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 7b1bc2a943..6272a59d24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG BEFORE_PACK_NOCOBASE="ls -l" ARG PLUGINS_DIRS ENV PLUGINS_DIRS=${PLUGINS_DIRS} - +ENV COMMIT_HASH=${COMMIT_HASH} RUN npx npm-cli-adduser --username test --password test -e test@nocobase.com -r $VERDACCIO_URL @@ -40,17 +40,18 @@ RUN cd /app \ && rm -rf nocobase.tar.gz \ && tar -zcf ./nocobase.tar.gz -C /app/my-nocobase-app . +RUN echo "${COMMIT_HASH}" > /tmp/commit_hash.txt + FROM node:20.13-bullseye-slim -RUN apt-get update && apt-get install -y nginx +RUN apt-get update && apt-get install -y nginx libaio1 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 +COPY --from=builder /tmp/commit_hash.txt /app/commit_hash.txt WORKDIR /app/nocobase -RUN mkdir -p /app/nocobase/storage/uploads/ && echo "$COMMIT_HASH" >> /app/nocobase/storage/uploads/COMMIT_HASH - COPY ./docker/nocobase/docker-entrypoint.sh /app/ CMD ["/app/docker-entrypoint.sh"] diff --git a/docker/nocobase/docker-entrypoint.sh b/docker/nocobase/docker-entrypoint.sh index 62c7918c62..7effef05c7 100755 --- a/docker/nocobase/docker-entrypoint.sh +++ b/docker/nocobase/docker-entrypoint.sh @@ -1,6 +1,8 @@ #!/bin/sh set -e +echo "COMMIT_HASH: $(cat /app/commit_hash.txt)" + if [ ! -d "/app/nocobase" ]; then mkdir nocobase fi @@ -18,6 +20,14 @@ ln -s /app/nocobase/storage/nocobase.conf /etc/nginx/sites-enabled/nocobase.conf nginx echo 'nginx started'; +# run scripts in storage/scripts +if [ -d "/app/nocobase/storage/scripts" ]; then + for f in /app/nocobase/storage/scripts/*.sh; do + echo "Running $f" + sh "$f" + done +fi + cd /app/nocobase && yarn start --quickstart # Run command with node if the first argument contains a "-" or is not a system command. The last diff --git a/storage/.gitignore b/storage/.gitignore index 5206e47082..62d0d471f9 100644 --- a/storage/.gitignore +++ b/storage/.gitignore @@ -4,4 +4,6 @@ app.watch.ts /e2e nocobase.conf app-upgrading -/verdaccio/storage \ No newline at end of file +/verdaccio/storage +libs +scripts