gpt4 book ai didi

javascript - Gulp 构建任务在 docker 中失败

转载 作者:搜寻专家 更新时间:2023-11-01 00:35:47 27 4
gpt4 key购买 nike

我有一个简单的 Hapi.js Node API .由于我使用 TypeScript 编写 API,因此我编写了 Gulp 任务来转译代码。如果我直接在我的主机上运行我的 API,我的 API 工作正常,但是当我尝试在 Docker 中运行它时出现以下错误:

错误: enter image description here

Docker 组合命令:

docker-compose -f docker-compose.dev.yml up -d --build

这是我的代码:./gulpfile:

'use strict';

const gulp = require('gulp');
const rimraf = require('gulp-rimraf');
const tslint = require('gulp-tslint');
const mocha = require('gulp-mocha');
const shell = require('gulp-shell');
const env = require('gulp-env');

/**
* Remove build directory.
*/
gulp.task('clean', function () {
return gulp.src(outDir, { read: false })
.pipe(rimraf());
});

/**
* Lint all custom TypeScript files.
*/
gulp.task('tslint', () => {
return gulp.src('src/**/*.ts')
.pipe(tslint({
formatter: 'prose'
}))
.pipe(tslint.report());
});

/**
* Compile TypeScript.
*/

function compileTS(args, cb) {
return exec(tscCmd + args, (err, stdout, stderr) => {
console.log(stdout);

if (stderr) {
console.log(stderr);
}
cb(err);
});
}

gulp.task('compile', shell.task([
'npm run tsc',
]))

/**
* Watch for changes in TypeScript
*/
gulp.task('watch', shell.task([
'npm run tsc-watch',
]))
/**
* Copy config files
*/
gulp.task('configs', (cb) => {
return gulp.src("src/configurations/*.json")
.pipe(gulp.dest('./build/src/configurations'));
});

/**
* Build the project.
*/
gulp.task('build', ['tslint', 'compile', 'configs'], () => {
console.log('Building the project ...');
});

/**
* Run tests.
*/
gulp.task('test', ['build'], (cb) => {
const envs = env.set({
NODE_ENV: 'test'
});

gulp.src(['build/test/**/*.js'])
.pipe(envs)
.pipe(mocha({ exit: true }))
.once('error', (error) => {
console.log(error);
process.exit(1);
});
});

gulp.task('default', ['build']);

./.docker/dev.dockerfile:

FROM node:latest

LABEL author="Saurabh Palatkar"

# create a specific user to run this container
# RUN adduser -S -D user-app

# add files to container
ADD . /app

# specify the working directory
WORKDIR app
RUN chmod -R 777 .
RUN npm i gulp --g
# build process
RUN npm install
# RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm run build
# RUN npm prune --production
EXPOSE 8080
# run application
CMD ["npm", "start"]

./docker-compose.dev.yml:

version: "3.4"

services:
api:
image: node-api
build:
context: .
dockerfile: .docker/dev.dockerfile
environment:
PORT: 8080
MONGO_URL: mongodb:27017
NODE_ENV: development
ports:
- "8080:8080"
links:
- database

database:
image: mongo:latest
ports:
- "27017:27017"

我在这里缺少什么?

最佳答案

编辑:问题不是我最初想的那样。 Dockerfile 中的操作顺序完全错误:必须先安装依赖项,然后将所有文件复制到容器中(因此安装的依赖项也会被复制),然后才能使用应用程序及其依赖项。我用这些修复程序对你的 repo 提出了拉取请求:)

关于javascript - Gulp 构建任务在 docker 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52577049/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com