rancher-gitlab-deploy icon indicating copy to clipboard operation
rancher-gitlab-deploy copied to clipboard

Rancher 2.0

Open cdrx opened this issue 8 years ago • 12 comments

With Rancher 2.0 not far away, its time to start thinking about supporting the new API version.

I'm considering rewriting this tool in Go, to make it faster / smaller and take advantage of the Rancher API bindings.

Does anyone have any thoughts on that? Will it break your workflow?

cdrx avatar Dec 04 '17 10:12 cdrx

Since using the docker's so easy in the gitlab-ci.yml, that's all I've ever used. And since that's completely language agnostic, I'm down for a rewrite 100%. :)

Morgul avatar Feb 08 '18 15:02 Morgul

Maybe not quite an answer to your questions, but I would like to be able to use this to deploy after builds from Codefresh.io instead of Gitlab.

Haven't tested it yet - but I think it may work as it is now.

asthomasdk avatar Feb 09 '18 18:02 asthomasdk

FYI - tested on Codefresh and this works perfectly. Very cool.

asthomasdk avatar Feb 10 '18 15:02 asthomasdk

I concur with @Morgul : the container packaging makes it easy to use.

marcovn avatar Feb 14 '18 11:02 marcovn

Considering rancher 2 runs on kubernetes and gitlab now has support for kubernetes (havent tested it), could it be possible that a rewrite for 2.0 is not needed and gitlab could take over this task? Feedback welcome on my comment, i'm just thinking out loud without actually checking facts ;)

samvdb avatar Mar 12 '18 11:03 samvdb

@cdrx Has there been any movement on this? Or am I better off rolling my own?

Inumedia avatar Jun 01 '18 07:06 Inumedia

Try ranchers cli tool, there is a docker image for it. It works great in gitlab.

samvdb avatar Jun 01 '18 07:06 samvdb

@samvdb Hi! Currently I use in my .gitlab-ci.yml

docker run --rm -e RANCHER_URL=$RANCHER_URL -e RANCHER_ACCESS_KEY=$RANCHER_ACCESS_KEY -e RANCHER_SECRET_KEY=$RANCHER_SECRET_KEY cdrx/rancher-gitlab-deploy:latest upgrade --finish-upgrade --wait-for-upgrade-to-finish --stack STACK --service SERVICE --new-image NEWIMAGE:NEWTAG

But I have always the error:

Status: Downloaded newer image for cdrx/rancher-gitlab-deploy:latest
Error: The Rancher URL doesn't look right
ERROR: Job failed: exit code 1

Do you have an idea ? You said you use the rancher cli, can you help me about the equivalent comand ?

Thank

SkYNewZ avatar Jun 03 '18 00:06 SkYNewZ

@samvdb do you have any working example maybe? I'd like to see it in action still I couldn't find any good API documentation to make it work. So far I've been using my own fork of this repository, customized to use rancher2: https://github.com/kpolszewski/rancher-gitlab-deploy

kpolszewski avatar Jul 10 '18 08:07 kpolszewski

@kpolszewski

This currently runs on rancher 1.6, i have not tested 2.0 due to lack of time. I switched over to rancher cli tool because v2 uses this. Should make my upgrade smoother in the future.

This is my gitlab config:

deploy-develop:
  stage: deploy
  dependencies: []
  image: tagip/rancher-cli:latest
  environment:
        name: staging
        url: xxx
  only:
    - develop
  services:
    - docker:dind
  before_script: []
  script:
    - cd docker
    - sh compose.sh

This is my compose.sh file in the docker folder.

#!/bin/bash
export CMD="--env <INSERT ENV HERE> up  -d -u --stack <INSERT STACK HERE> --env-file develop.env -f docker-compose-dev.yml --rancher-file rancher-compose.yml"
rancher $CMD --confirm-upgrade  --force-upgrade --batch-size 1

I have seperate files to inject environment variables and compose files. I currently dont deploy tags, i guess it could be done by passing arguments to the bash script and then replacing the variables in the compose file to use the newly build tag.

Rancher cli is powered by ENV variables which contain the url, access and secret key. I configured them in the gitlab runner, you could also just configure project variables.

samvdb avatar Jul 10 '18 09:07 samvdb

@cdrx thanks for this tool, works like a charm with Gitlab for Rancher 1.x!

I'm wondering if this also works now already with Rancher2 as well?

phlegx avatar Aug 14 '18 15:08 phlegx

Here is the simplest solution I could find for re-deploying rancher 2 from gitlab. Perhaps it can be integrated into this project:

deploy_foo:
  image: jonaskello/rancher-cli-k8s:v2.0.4
  script:
    - rancher login $RANCHER2_SERVER_URL --token $RANCHER2_BEARER_TOKEN --context c-xxxxx:p-xxxxx
    - rancher kubectl --namespace=foo-ns patch deployment foo -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"

To make it fully generic, the --context c-xxxxx:p-xxxxx, --namespace=foo-ns and deployment foo parts should have variables so it becomes --context $CONTEXT, --namespace=$NAMESPACE and deployment $DEPLOYMENT. The image jonaskello/rancher-cli-k8s:v2.0.4 is just the regular rancher 2 cli command with kubectl added.

jonaskello avatar Jan 02 '19 12:01 jonaskello