在Heroku上为docker dyno运行一次性命令

时间:2019-09-04 18:49:34

标签: docker heroku

当我通过clischeduler附加组件运行工人动态发电机时,什么都没有发生。

我尝试启用或禁用dyno,但它对一次性和调度程序没有任何作用。
启用dyno时,heroku可以启动它(而不是一次性或调度程序),而来自worker的命令(在Dockerfile中指定为CMD)运行得很好。 使用命令运行run也无济于事。
此类运行的日志输出如下:

2019-09-04T18:30:34.176982+00:00 heroku[scheduler.8210]: State changed from starting to complete

2019-09-04T18:30:34.153189+00:00 app[api]: Starting process with command `/opt/app/run.sh` by user scheduler@addons.heroku.com

2019-09-04T18:41:15.398424+00:00 heroku[scheduler.4565]: State changed from starting to complete

2019-09-04T18:41:15.354628+00:00 app[api]: Starting process with command `/opt/app/run.sh` by user scheduler@addons.heroku.com

启用dyno后运行的日志输出如下:

2019-09-04T18:45:39.694515+00:00 app[api]: Scaled to worker@1:Free by user kjiec4@gmail.com

2019-09-04T18:45:44.856180+00:00 heroku[worker.1]: Starting process with command `/opt/app/run.sh`

2019-09-04T18:45:45.474477+00:00 heroku[worker.1]: State changed from starting to up

2019-09-04T18:45:47.252345+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.license.VersionPrinter - Flyway Community Edition 6.0.1 by Boxfuse

2019-09-04T18:45:48.221494+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.database.DatabaseFactory - Database: jdbc:postgresql://ec2-176-34-184-174.eu-west-1.compute.amazonaws.com:5432/dc9jgd0q28f9sd (PostgreSQL 11.5)

2019-09-04T18:45:48.298740+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.command.DbValidate - Successfully validated 1 migration (execution time 00:00.037s)

2019-09-04T18:45:48.321407+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory - Creating Schema History table "public"."flyway_schema_history" ...

2019-09-04T18:45:48.383992+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.command.DbMigrate - Current version of schema "public": << Empty Schema >>

2019-09-04T18:45:48.392490+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.command.DbMigrate - Migrating schema "public" to version 1 - Create news table

2019-09-04T18:45:48.422169+00:00 app[worker.1]: [main] INFO org.flywaydb.core.internal.command.DbMigrate - Successfully applied 1 migration to schema "public" (execution time 00:00.052s)

2019-09-04T18:46:08.425628+00:00 heroku[worker.1]: State changed from up to crashed

2019-09-04T18:46:08.509950+00:00 heroku[worker.1]: State changed from crashed to starting

2019-09-04T18:46:08.401741+00:00 heroku[worker.1]: Process exited with status 0

2019-09-04T18:46:12.919303+00:00 heroku[worker.1]: Starting process with command `/opt/app/run.sh`

2019-09-04T18:46:13.527541+00:00 heroku[worker.1]: State changed from starting to up

最后一个是预期的行为。

我正在尝试像这样运行它:

heroku run worker

像这样:

heroku run worker /opt/app/run.sh

scheduler命令仅指定为:worker

我应该怎么做才能在heroku中一次性运行docker容器?

1 个答案:

答案 0 :(得分:0)

好吧,据我发现,我做错了所有事情。 要一次性使用cli,需要将进程类型指定为参数:

heroku run worker --type=worker

对于scheduler插件,它仅适用于web dynos,如文档所述:

  

如果使用Heroku Scheduler和Container Registry作为部署方法,则必须可以从Web映像访问任务。无法为任务执行指定非Web图像。

https://devcenter.heroku.com/articles/scheduler