Skip to content

Commit

Permalink
fix: 修复codesandbox启动时间过长的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Nov 28, 2023
1 parent 055e0b8 commit 946991b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
11 changes: 3 additions & 8 deletions .codesandbox/tasks.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
{
// 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"]
}
},
"build": {
Expand Down
34 changes: 34 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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/

RUN if [ ! -f ".next/routes-manifest.json" ]; then \
npm install && npm run build; \
fi

RUN rm -rf src

ENV PORT 7860

EXPOSE 7860

CMD npm start
29 changes: 16 additions & 13 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
// 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"
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
// Path is relative to the devcontainer.json file.
"dockerfile": "Dockerfile"
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// 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 '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",
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Configure tool-specific properties.
// "customizations": {},
// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down

0 comments on commit 946991b

Please sign in to comment.