Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy docker images to caprover? #360

Closed
m0xx opened this issue Feb 3, 2019 · 9 comments
Closed

Deploy docker images to caprover? #360

m0xx opened this issue Feb 3, 2019 · 9 comments
Labels

Comments

@m0xx
Copy link

m0xx commented Feb 3, 2019

Hi,

I don't know if it could be possible in the future, but I would like to deploy directly the images I build via CI servers. The integration with Caprover for CD part of the process would be a perfect fit.

Maybe it could work by setting hooks in the registry?

Here is some of the advantage I can see:

  • More control over wich files are deployed (especially in monorepo)
  • The image is exactly the same as the one where tests have run on the CI server
  • Caprover doesn't need to rebuild image
  • Simple push to registry/app-name from anywhere would trigger a deploy

Thanks for your time, I plan to move most of my apps to Caprover.

@githubsaturn
Copy link
Collaborator

githubsaturn commented Feb 3, 2019

It's already possible! Here are two methods that you can use:

1) Use git webhooks:

  • Setup your repo in github or bitbucket or etc
  • Setup webhook in CapRover dashboard, however, use a particular branch like caprover-releases
  • In your CI when your tests are done, switch to caprover-releases branch and simply create a captain-definition file (edit existing file) with this content:
{
  "schemaVersion": 2,
   "imageName" : "docker.registry.url.com/username/yourimage:yournewtag"
}
  • Commit and push the latest commit to your github/gitlab/bitbucket repo.
  • At this point, CapRover automatically gets notified by the webhook and pulls caprover-releases branch of your repo, which only has one file, captain-definition, and starts updating your image! Done!

2) Use CapRover API

This is more complex, and unless you have solid reasons that you cannot use method 1, you shouldn't use this method.

  • After CI work is done, you fetch an auth token via login end point
  • Then you can send captain-definition content that was described in method 1, as a JSON payload to build end point to trigger a build
  • Login is /api/v2/login and the body is: {"password":"yourCapRoverPassword"}
  • Build endpoint is /api/v2/user/apps/appData/your-app-name-here and the body is {"captainDefinitionContent":"{\"schemaVersion\":2,\"imageName\":\"docker.registry.url.com/username/yourimage:yournewtag\"}","gitHash":""}
  • All endpoints require x-namespace: captain as header

PRIVATE REGISTRIES?

If docker.registry.url.com that you're using is a private registry, you first need to add that registry to CapRover. Go to cluster and click on "Add Remote Registry". IMPORTANT: After adding the first registry, it automatically gets set as default registry. If you are using a single node, make sure to disable default push registry.


I meant to write a step by step tutorial blog for this using CircleCI or Travis, but I'd rather spend my time adding new features.I really appreciate it if you could write a blog post if you get around doing this. I can link it (or add it) to the docs and add your name as the original author. I am sure it helps a lot of people.

@m0xx
Copy link
Author

m0xx commented Feb 3, 2019

Thanks for your in depth explanation. I’ll try to put something together this week.

Maybe we could add the ‘build’ command to caprover-cli? It could be easier for the end user and easier to maintain in the case of a change in the API.

So by pushing to the repository I assume the app will redeploy with the ‘latest’ tag right? And I suppose when rolling back a version it use directly the image id?

@githubsaturn
Copy link
Collaborator

Maybe we could add the ‘build’ command to caprover-cli? It could be easier for the end user and easier to maintain in the case of a change in the API.

Can you please clarify in details what you expect the "build" command to do?

So by pushing to the repository I assume the app will redeploy with the ‘latest’ tag right? And I suppose when rolling back a version it use directly the image id?

Try avoid using the "latest" tag. This was an oversight from Docker engineers in the beginning and can cause many hard to debug problems. Tag your image with explicit strings, either version such as 1.1.0 or git hash, or even date. Try your best to avoid latest tag.

Captain uses specific tag that you define in your image name, for example yournewtag in here:

{
  "schemaVersion": 2,
   "imageName" : "docker.registry.url.com/username/yourimage:yournewtag"
}

@m0xx
Copy link
Author

m0xx commented Feb 3, 2019

After some thought it doesn’t fit well with the build command.

I would like a command to upgrade directly the image( under the hood it call the enpoint with the correct payload) but as a end user I could see something like:

´caprover login -h https://captain.root.domain.com -p password’
‘caprover upgrade —image private.registry.com/username/new-image:version -a app-name ´

Yeah I thought latest was more like an internal tag that means the latest build image.

@githubsaturn
Copy link
Collaborator

I like this!

I'll make some changes to syntax to match the convention of the current CLI format. Since stateless deploys (no login required) are already implemented, instead of LOGIN and UPGRADE, I'll create this:

caprover deploy -h https://captain.root.domain.com -p password  -a app-name --image private.registry.com/username/new-image:version

But other than that it is a great suggestion.

Can you please create an issue for this suggestion here:
https://github.com/caprover/caprover-cli

@m0xx
Copy link
Author

m0xx commented Feb 4, 2019

Yeah that's perfect! Thank you I'll create the issue

@mehmetaydogduu
Copy link

mehmetaydogduu commented Mar 18, 2020

An additional comment. I think a section will be useful for copy paste public docker images.

Example. I copy this
docker pull brotandgames/ciao
Caprover deploys in captain-definition file.
docker.io/brotandgames/ciao:latest

Because commonly dockerfiles stuck but docker images are stable.
Also this issue need to be in documents.

@ghost
Copy link

ghost commented Aug 20, 2021

does anyone know the docker hub URL to pull the image using caprover, I want to pull my private repository using caprover cluster?

@githubsaturn
Copy link
Collaborator

you can use registry-1.docker.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants