Skip to content

Commit

Permalink
chore: 优化docker配置
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Aug 27, 2024
1 parent ca62483 commit a6bb27f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
FROM node:20
COPY . /app
FROM node:20 as DEV

WORKDIR /app
RUN pwd && ls -la && npm install && npm run build:local
EXPOSE 8787
CMD ["npm", "run", "start:local"]
COPY package.json vite.config.ts tsconfig.json ./
COPY src ./src
CMD ["/bin/bash"]
RUN npm install && npm run build:local

FROM node:20 as PROD

WORKDIR /app
COPY --from=DEV /app/dist /app/dist
COPY --from=DEV /app/package.json /app/
RUN npm install --only=production --omit=dev
CMD ["npm", "run", "start:dist"]
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"database": {
"type": "local",
"path": "./data.json"
"path": "/app/data.json"
},
"mode": "polling"
}
15 changes: 11 additions & 4 deletions doc/en/LOCAL.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Local or Docker
# Local Deployment

## Configure

Expand All @@ -24,12 +24,19 @@
the toml is compatible with the cloudflare workers config file


### 2. Run
## Run on local

```shell
node dist/index.cjs
npm install
npm run start:local
```
or

```shell
npm install
npm run build:local
CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml npm run start:dist
```
You can run `index.cjs` anywhere without npm


## Run on docker
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"lint": "eslint --fix *.js *.ts *.json src adapter",
"build": "vite build",
"build:local": "BUILD_MODE=local vite build",
"debug:workers": "wrangler dev --local",
"debug:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx index.ts",
"deploy:dist": "wrangler deploy",
"deploy:build": "npm run build && wrangler deploy",
"start:local": "node dist/index.js"
"start:dist": "node dist/index.js",
"start:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx index.ts",
"start:debug": "wrangler dev --local"
},
"dependencies": {
"cloudflare-worker-adapter": "^1.2.3"
Expand Down
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
import cleanup from 'rollup-plugin-cleanup';
import checker from 'vite-plugin-checker';
import dts from 'vite-plugin-dts';
import { nodeExternals } from 'rollup-plugin-node-externals';
// @ts-ignore
import nodeExternals from 'rollup-plugin-node-externals'


const { BUILD_MODE } = process.env;

Expand Down

0 comments on commit a6bb27f

Please sign in to comment.