Captain Definition File
Basics
One of the key components of CapRover is the captain-definition
file that sits at the root of your project. In case of NodeJS app, it sits next to package.json, or next to index.php in case of PHP, or requirements.txt for Python app. It's a simple JSON like this:
{
"schemaVersion": 2,
"templateId": "node/8.7.0"
}
schemaVersion
is always 2. And templateId
is the piece which defines the foundation you need in order to run your app. It is in LANGUAGE/VERSION
format. LANGUAGE can be one of these: node
, php
, python-django
, ruby-rack
. And VERSION is the version of the language you want to use - see below.
Note that although the templateId
can be one of the 4 most popular web app languages: NodeJS, PHP and Python/Django, Ruby/Rack, you are NOT LIMITED to these predefined languages! With CapRover, you have the ability to define your own Dockerfile. With a customized Dockerfile, you can deploy any laguage, Go, Java, .NET, you name it! Dockerfiles are quite easy to write. For example, the two captain-definition files below generate the exact same result.
Simple version
{
"schemaVersion": 2,
"templateId": "node/8.7.0"
}
Advanced Version
{
"schemaVersion": 2,
"dockerfileLines": [
"FROM node:8.7.0-alpine",
"RUN mkdir -p /usr/src/app",
"WORKDIR /usr/src/app",
"COPY ./package.json /usr/src/app/",
"RUN npm install && npm cache clean --force",
"COPY ./ /usr/src/app",
"ENV NODE_ENV production",
"ENV PORT 80",
"EXPOSE 80",
"CMD [ \"npm\", \"start\" ]"
]
}
Use Dockerfile in captain-definition:
Note that the simple version of captain-definition
with templateId
is good as a starting point. But as your project gets more complex you may want to perform more complicated tasks with your base image, such as installing PHP extensions, installing uWSGI
, installing particular version of curl
and etc. In these cases, you can leverage the Dockerfile. Using custom Dockerfile allows you to build a very customized base image. If you're not familiar with Docker, you can simply use google to find something that's similar to your requirement and tweak it. Finally, if you're stuck, don't be shy to ask a question on our Slack channel, or StackOverflow.
To use a Dockerfile that's in your repository, you can simply reference it in the captain-definition file:
{
"schemaVersion": 2,
"dockerfilePath": "./Dockerfile"
}
Dockerfiles are so simple and easy to read. Even if you don't know anything about Docker, you can get an idea what this does. Some examples of advanced methods: PHP Composer and Meteor
Using this approach (pure Dockerfile) you can deploy Ruby, Java, Scala, literally anything! If you need more details on dockerfile, please see Dockerfile Help and Best Practices.
Use Image Name
If you are an advanced Docker user, you may know that there are plenty of pre-built applications sitting on DockerHub. You can deploy these images using captain-definition. For example to deploy https://hub.docker.com/r/nginxdemos/hello/, you use:
{
"schemaVersion": 2,
"imageName": "nginxdemos/hello"
}
Tip: You can simply copy and paste the captain-definition file above on CapRover web dashboard under the deploy tab.
Monorepo:
You can use one git repo to deploy multiple different apps. For example, you may have a frontend and backend app in one repository. In this case, you can define multiple captain-definition
files and have them deploying separate apps, for example, a directory structure, like this:
/project
/frontend
/src/index.js
package.json
/backend
/src/index.js
package.json
captain-definition-backend
captain-definition-frontend
With this content:
captain-definition-backend
{
"schemaVersion": 2,
"dockerfileLines": [
"FROM node:12-alpine",
"RUN mkdir -p /usr/src/app",
"COPY ./backend /usr/src/app",
"RUN npm install && npm cache clean --force",
"CMD [ \"npm\", \"start\" ]"
]
}
You can alternatively point to a Dockerfile. Note that the build context will be always the root of your project, so in the Dockerfile, you'll have to point to that specific directory, for example, COPY ./backend /usr/src/app
Next, you need to instruct your CapRover to use the correct captain-definition
for each app. Navigate to your app, go to DEPLOYMENT tab, and edit your captain-definition path to ./captain-definition-backend
Versions for templateId:
NOTE: Versions get pulled from official repositories at runtime, therefore you do not need to update your Captain in order to use a new version of NodeJS. For example, see here.
IMPORTANT: Versions mentioned below are for reference only. For example, at the time that this document was generated Node 10 was not available, but it is available now. Therefore, you can use node/10
or node/10.15
or node/10.15.0
as your templateId despite the fact that it is not mentioned below.
node/
carbon, 8, 8.9, 8.9.4, boron, 6, 6.12, 6.12.3, 9, 9.3, 9.3.0, 8.9.3, 9.2, 9.2.1, argon, 4, 4.8, 4.8.7, 6.12.2, 8.9.2, 6.12.1, 4.8.6, 6.12.0, 8.9.1, 9.2.0, 9.1, 9.1.0, 8.9.0, 9.0, 9.0.0, 4.8.5, 6.11, 6.11.5, 8.8, 8.8.1, 8.8.0, 8.7, 8.7.0, 6.11.4, 8.6, 8.6.0, 8.5, 8.5.0, 4.8.4,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