Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Docker Image with Jenkins on Heroku Container Registry

I'm trying to deploy jenkinsci/docker on Heroku, and have a problem with composing my Dockerfile.

When I'm pushing the Docker Image on Heroku Container Registry by heroku container:push web, I'm getting an error Your Docker image must specify a 'CMD' instruction.

But what command I have to write to run Jenkins inside the container on Heroku?

Thanks in advance!

like image 939
S.Raman Avatar asked Oct 27 '17 11:10

S.Raman


2 Answers

The error is referring to the missing CMD stanza in your Dockerfile.

But you don't need to create your own docker image and Dockerfile if you are not planning to modify anything from the upstream version of the jenkins image (as reflected by the link you provided to the Dockerfile).

You can just docker pull jenkins/jenkins:lts locally then tag it using docker tag jenkins/jenkins:lts registry.heroku.com/<app>/<process-type> and then push it to Heroku using the new tag docker push registry.heroku.com/<app>/<process-type>

You can read more on Heroku's official documentation about this topic.

EDIT:

If you do need a custom jenkins docker image for example to install additional jenkins plugins (like the OP needs) you will end up creating your own Dockerfile and you will have to do something like this:

FROM jenkins/jenkins:lts
RUN /usr/local/bin/install-plugins.sh gitlab-plugin publish-over-dropbox
CMD ["--debug=5"]

Although we don't need it in a normal environment, we are adding a CMD stanza just to pass the heroku container:push check that requires a CMD stanza in the Dockerfile, the --debug=5 is detected by the jenkins.sh ENTRYPOINT script and sent to the jenkins.war program, in turn this sets the debug level to 5 (the default level if not specified) which in turn does not affect us in any way.

EDIT #2:

Because heroku does not accept more than one instruction for ENTRYPOINT you must deviate further from a normal Dockerfile scenario and cancel the ENTRYPOINT upstream stanza by setting it to [] because it is not compatible with heroku and then place everything in the CMD stanza:

FROM jenkins/jenkins:lts
RUN /usr/local/bin/install-plugins.sh gitlab-plugin publish-over-dropbox
ENV JAVA_OPTS -Xms256m -Xmx512m
ENTRYPOINT []
CMD /bin/tini -s -- /usr/local/bin/jenkins.sh --httpPort=$PORT

I added JAVA_OPTS to coupe with a free tier dyno since jenkins and java are memory hungry applications, adjust as needed.

I added the -s flag to tini because it does no longer have PID 1, more on that here.

I added --httpPort=$PORT flag sent to jenkins.war so that heroku can populate the proper $PORT for the app.

Note from heroku docs:

ENTRYPOINT is optional. If not set, /bin/sh -c will be used

like image 136
Nicolae Avatar answered Oct 21 '22 20:10

Nicolae


Now I have another problem when I'm trying to deploy jenkinsci/docker on Heroku:

2017-10-27T15:53:37.569477+00:00 heroku[web.1]: State changed from crashed to starting

2017-10-27T15:53:35.856897+00:00 app[api]: Deployed web (dce6a8335a9a) by user [email protected]

2017-10-27T15:53:35.856897+00:00 app[api]: Release v7 created by user [email protected]

2017-10-27T15:53:53.949433+00:00 heroku[web.1]: Starting process with command '--debug\=5'

2017-10-27T15:53:56.142034+00:00 app[web.1]: Error: No such file or directory

2017-10-27T15:53:56.243216+00:00 heroku[web.1]: State changed from starting to crashed

2017-10-27T15:53:56.228817+00:00 heroku[web.1]: Process exited with status 126

like image 41
S.Raman Avatar answered Oct 21 '22 20:10

S.Raman