暴露heroku $ PORT与gulp任务

时间:2017-07-06 12:04:55

标签: docker heroku gulp

我正在使用以下Dockerfile

构建Docker镜像
FROM node:latest

RUN npm install -g gulp

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

EXPOSE 5000

CMD ["gulp", "serveprod"]

我知道我需要从heroku文档中公开$PORT变量。

但是,我不知道这是如何与gulp一起工作的。

这是我的gulpfile.jsserveprod任务。

gulp.task('serveprod', function() {
    connect.server({
        root: './',
        port: $PORT || process.env.PORT || 5000, // localhost:5000
        livereload: false
    });
});

以前,我使用的是节点buildpack,port:所需的全部是process.env.PORT,它可以正常工作。我尝试添加$PORT,但这仍然无效。

更新:

我刚尝试将其放入我的Dockerfile

ENV 5000 $PORT

以下是Heroku日志:

2017-07-07T15:01:27.127275+00:00 heroku[web.1]: Starting process with command `gulp serveprod`
2017-07-07T15:01:29.985824+00:00 heroku[web.1]: State changed from starting to crashed
2017-07-07T15:01:29.875500+00:00 app[web.1]: module.js:487
2017-07-07T15:01:29.875515+00:00 app[web.1]:     throw err;
2017-07-07T15:01:29.875517+00:00 app[web.1]:     ^
2017-07-07T15:01:29.875517+00:00 app[web.1]: 
2017-07-07T15:01:29.875518+00:00 app[web.1]: Error: Cannot find module './lib/_stream_readable.js'
2017-07-07T15:01:29.875519+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:485:15)
2017-07-07T15:01:29.875519+00:00 app[web.1]:     at Function.Module._load (module.js:437:25)
2017-07-07T15:01:29.875520+00:00 app[web.1]:     at Module.require (module.js:513:17)
2017-07-07T15:01:29.875521+00:00 app[web.1]:     at require (internal/module.js:11:18)
2017-07-07T15:01:29.875539+00:00 app[web.1]:     at Object.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/through2/node_modules/readable-stream/readable.js:12:30)
2017-07-07T15:01:29.875540+00:00 app[web.1]:     at Module._compile (module.js:569:30)
2017-07-07T15:01:29.875541+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:580:10)
2017-07-07T15:01:29.875541+00:00 app[web.1]:     at Module.load (module.js:503:32)
2017-07-07T15:01:29.875542+00:00 app[web.1]:     at tryModuleLoad (module.js:466:12)
2017-07-07T15:01:29.875543+00:00 app[web.1]:     at Function.Module._load (module.js:458:3)
2017-07-07T15:01:29.971237+00:00 heroku[web.1]: Process exited with status 1
2017-07-07T15:01:32.103467+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.christopherdbolton.com request_id=469ad736-103a-461f-af20-91454a8a83f1 fwd="139.72.158.28" dyno= connect= service= status=503 bytes= protocol=http
2017-07-07T15:01:32.923798+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.christopherdbolton.com request_id=a5c0b8c4-69c7-4bd7-ab00-372fe625b2f8 fwd="139.72.158.28" dyno= connect= service= status=503 bytes= protocol=http
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-07-07T15:01:29.875520+00:00 app[web.1]:     at Module.require (module.js:513:17)
2017-07-07T15:01:29.875521+00:00 app[web.1]:     at require (internal/module.js:11:18)
2017-07-07T15:01:29.875539+00:00 app[web.1]:     at Object.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/through2/node_modules/readable-stream/readable.js:12:30)
2017-07-07T15:01:29.875541+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:580:10)
2017-07-07T15:01:29.875540+00:00 app[web.1]:     at Module._compile (module.js:569:30)
2017-07-07T15:01:29.875541+00:00 app[web.1]:     at Module.load (module.js:503:32)
2017-07-07T15:01:29.875542+00:00 app[web.1]:     at tryModuleLoad (module.js:466:12)
2017-07-07T15:01:29.875543+00:00 app[web.1]:     at Function.Module._load (module.js:458:3)

1 个答案:

答案 0 :(得分:0)

不是以gulp serveprod开头,而是从npm start开始。

这是生成的Dockerfile:

FROM node:latest

RUN npm install -g gulp

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app

CMD ["npm", "start"]

以下是package.json

  "scripts": {
    "build": "gulp",
    "start": "gulp serveprod"
  }