diff --git a/.codesandbox/tasks.json b/.codesandbox/tasks.json index 9a3d6bf3..56f733c4 100644 --- a/.codesandbox/tasks.json +++ b/.codesandbox/tasks.json @@ -1,45 +1,45 @@ { // These tasks will run in order when initializing your CodeSandbox project. - "setupTasks": [ - { - "name": "Install Dependencies", - "command": "npm install" - } - ], + "setupTasks": [], // These tasks can be run from CodeSandbox. Running one will open a log in the app. "tasks": { "dev": { "name": "Start Server", - "command": "npm install && npm run build && npm start", + "command": "npm start", "runAtStart": true, "preview": { "port": 3000 }, "restartOn": { - "files": ["./package-lock.json"] + "files": [ + "./package.json" + ], + "branch": false, + "resume": false } }, "build": { "name": "Build", - "command": "npm run build", - "runAtStart": false + "command": "npm run build" }, "start": { "name": "Start Server", - "command": "npm run start", - "runAtStart": false + "command": "npm start" }, "lint": { "name": "Lint", - "command": "npm run lint", - "runAtStart": false + "command": "npm run lint" }, "install": { "name": "Install Dependencies", "command": "npm install", "restartOn": { - "files": ["./package.json"] + "files": [ + "./package.json" + ], + "branch": false, + "resume": false } } } diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..018e25be --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,32 @@ +FROM weaigc/bingo as build + +FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye + +ARG DEBIAN_FRONTEND=noninteractive + +# 如果没有特别需要不要配置 +ENV BING_HEADER "" + +# Set home to the user's home directory +ENV HOME=/home/user \ + PATH=/home/user/.local/bin:$PATH + +# Set up a new user named "user" with user ID 1000 +RUN useradd -o -u 1000 user && mkdir -p $HOME/app && chown -R user $HOME + +# Switch to the "user" user +USER user + +# Set the working directory to the user's home directory +WORKDIR $HOME/app + +# Copy the current directory contents into the container at $HOME/app setting the owner to the user +COPY --chown=user . $HOME/app/ + +COPY --from=build /home/user/app $HOME/ + +ENV PORT 7860 + +EXPOSE 7860 + +# CMD npm start diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 19f7f683..00000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,22 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node -{ - "name": "Node.js & TypeScript", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye" - - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "yarn install", - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} diff --git a/.github/pull.yml b/.github/pull.yml new file mode 100644 index 00000000..270aefb0 --- /dev/null +++ b/.github/pull.yml @@ -0,0 +1,5 @@ +version: "1" +rules: + - base: main + upstream: weaigc:main # change `weaigc` to the owner of upstream repo + mergeMethod: rebase diff --git a/Dockerfile b/Dockerfile index ace0ce3d..983b70d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,13 @@ -FROM node:18 +FROM node:20 ARG DEBIAN_FRONTEND=noninteractive +# 如果没有特别需要不要配置 ENV BING_HEADER "" # Set home to the user's home directory ENV HOME=/home/user \ - PATH=/home/user/.local/bin:$PATH + PATH=/home/user/.local/bin:$PATH # Set up a new user named "user" with user ID 1000 RUN useradd -o -u 1000 user && mkdir -p $HOME/app && chown -R user $HOME @@ -22,7 +23,7 @@ COPY --chown=user . $HOME/app/ RUN if [ ! -f ".next/routes-manifest.json" ]; then \ npm install && npm run build; \ -fi + fi RUN rm -rf src diff --git a/package-lock.json b/package-lock.json index e9c94956..caac2ed0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bingo", - "version": "1.3.0", + "version": "1.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bingo", - "version": "1.3.0", + "version": "1.4.0", "dependencies": { "@headlessui/react": "^1.7.17", "@radix-ui/react-alert-dialog": "^1.0.4", diff --git a/package.json b/package.json index 18e78d09..1e4af3bb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "cross-env DEBUG=bingo* NODE_ENV=development node ./server.js", "build": "next build", "proxy": "node ./cloudflare/cli.js", - "start": "cross-env NODE_ENV=production node ./server.js", + "start": "node ./scripts/pre-check.js && cross-env NODE_ENV=production node ./server.js", "lint": "next lint" }, "dependencies": { diff --git a/scripts/pre-check.js b/scripts/pre-check.js new file mode 100644 index 00000000..44d00da9 --- /dev/null +++ b/scripts/pre-check.js @@ -0,0 +1,38 @@ +const { existsSync } = require('fs'); +const { spawn } = require('child_process'); + +function executeCommand(command) { + return new Promise((resolve, reject) => { + const child = spawn(command, { shell: true }); + + child.stdout.on('data', (data) => { + console.log(data.toString()); + }); + + child.stderr.on('data', (data) => { + console.error(data.toString()); + }); + + child.on('exit', (code) => { + console.log(`Child process exited with code ${code}`); + resolve(); + }); + + child.on('error', (err) => { + console.error(err); + reject(err); + }); + }); +} + +async function start() { + let exists = false; + try { + exists = existsSync('.next/BUILD_ID'); + } catch (e) {} + if (!exists) { + await executeCommand('npm install'); + await executeCommand('npm run build'); + } +} +start();