Adonis ace migration on Docker语言 - 语法错误:意外的标识符



当我尝试运行node ace migration:run --force时,我收到此错误"语法错误:意外标识符"

/app/startup.sh:3
. node ace migration:run --force
^^^
SyntaxError: Unexpected identifier
at wrapSafe (internal/modules/cjs/loader.js:1054:16)
at Module._compile (internal/modules/cjs/loader.js:1102:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47

Dockerfile

FROM node:12 AS bizi
COPY . /app
WORKDIR /app
RUN ["npm", "i"]

我使用startup.shshell 脚本启动容器,这是发生错误的地方:

#!/bin/sh
cd /app
node ace migration:run --force
adonis serve

生成并启动容器:

docker build -t myapp .
docker run -p 8080:80 myapp startup.sh

以下是我对package.json文件的所有依赖项:

"dependencies": {
"@adonisjs/ace": "^5.0.8",
"@adonisjs/ally": "^2.1.3",
"@adonisjs/auth": "^3.0.7",
"@adonisjs/bodyparser": "^2.0.5",
"@adonisjs/cors": "^1.0.7",
"@adonisjs/fold": "^4.0.9",
"@adonisjs/framework": "^5.0.13",
"@adonisjs/generic-exceptions": "^3.0.1",
"@adonisjs/ignitor": "^2.0.8",
"@adonisjs/lucid": "^6.1.3",
"@adonisjs/mail": "^3.0.9",
"@adonisjs/validator": "^5.0.6",
"@azure/service-bus": "^1.1.7",
"axios": "^0.19.0",
"cpf-check": "^3.0.0",
"firebase-admin": "^8.3.0",
"moment": "^2.24.0",
"order-id": "^1.1.0",
"pg": "^7.12.0",
"require-dir": "^1.2.0",
"uuid": "^3.3.2"
}

如果我将 ace 命令放在 Dockerfile 中,它们似乎没问题。

也许是我缺少的 linux 配置?

FROM node:12 AS bizi
COPY . /app
WORKDIR /app
RUN ["npm", "i"]
# Added ace commands
RUN node ace
RUN node ace migration:run --force

这是包含 ace 命令的 docker 构建输出,问题似乎仅在我运行 shell 时才发生。

Step 5/6 : RUN node ace --help
---> Running in f9bd319e8031
Usage:
command [arguments] [options]
Global Options:
--env                  Set NODE_ENV before running the commands
--no-ansi              Disable colored output
--version              output the version number
Available Commands:
seed                   Seed database using seed files
connect
connect:fridge-queue   Tell something helpful about this command
make
make:validator         Make route validator
migration
migration:refresh      Refresh migrations by performing rollback and then running from start
migration:reset        Rollback migration to the first batch
migration:rollback     Rollback migration to latest batch or to a specific batch number
migration:run          Run all pending migrations
migration:status       Check migrations current status

尝试运行迁移时,我遇到了类似的错误@adonisjs/cli

我从node映像切换到ubuntu,并自己配置节点安装以解决问题。

FROM ubuntu:latest
USER root
RUN apt-get update
RUN apt -y upgrade
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_12.x  | bash -
RUN apt-get -y install nodejs
COPY . /app
WORKDIR /app
RUN npm i -g @adonisjs/cli
RUN npm i
`` 

一个好的解决方案可能是在package.json上添加命令,并在docker环境中调用它。有些像:

Package.json:

...
"scripts": {
"start": "node server.js",
"test": "node ace test",
"serve": "adonis serve"
"migrate:force": "ace migration:run --force"
},
...

在.sh文件上:

...
npm run migrate:force
npm run serve
...

最新更新