Can a Procfile have comments?
Asked Answered
R

3

46

Is it possible to put comments in a Procfile? If so, what is the syntax?

Not sure if this matters, but I am hosting on Heroku.

Rowdy answered 6/5, 2016 at 20:22 Comment(0)
U
67

Yes, you can put comments in a Procfile. I know of two programs which parse Procfiles, foreman and forego.

In foreman, which originated the Procfile format, a Procfile can contain comments, blank lines, and in fact any line that doesn't look like a meaningful Procfile line.

From the class that parses a Procfile:

# A valid Procfile entry is captured by this regex:
#
#   /^([A-Za-z0-9_]+):\s*(.+)$/
#
# All other lines are ignored.

forego, which Heroku uses, follows the same scheme.

Unwished answered 7/5, 2016 at 2:32 Comment(2)
Can you be explicit about the comment syntax? Your answer implies leading hash characters, but I'm not sureChavarria
There isn't a comment syntax as such, only the syntax I showed, which identifies processes to start. Any line that doesn't match is ignored and is effectively a comment. Of course reasonable people will prefix comments with something like # to make them obvious and avoid accidental matches with the process syntax.Unwished
E
8

As a 2020 update to this question, Heroku has switched from using Forego within Heroku Local to node-foreman (a port of the original foreman). That being said, not much has changed regarding how Procfiles are read and wrote by foreman since 2017. However around the end of June 2016 (after the May 2016 update to this question), it seems users have found processes will still be launched from lines starting with #. The following will still launch a process:

# foo: cd foo && bundle exec rails s -p 3000

On the other hand, it seems // does prevent a process from being launched on that line. Preventing the following from running:

// foo: cd foo && bundle exec rails s -p 3000

You may be able to use either one to create comments since, as the above suggests, lines starting with # will be not be read unless they have a valid process declared on it. On the other hand, if you're attempting to comment out a line with a valid process declared on it, it seems // is the comment style to use.

Evelunn answered 6/6, 2020 at 6:58 Comment(1)
I think that every line in a procfile is a process besides comments.Algonkian
I
3

It seems Heroku does not actually accept // as comments (it breaks), whereas # seems to work. Anyway, to test your Procfile you can use the heroku local command

Importunity answered 8/7, 2021 at 0:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.