Sign inSign up

lebokus/rancher-deploy

By lebokus

•Updated over 8 years ago

Simplifies rancher deployment, keeps your rancher-compose.yml simple

Image
0

1.0K

lebokus/rancher-deploy repository overview

⁠rancher-deploy

Simplifies rancher deployment, keeps your rancher-compose.yml simple

Build Status codecov Docker Build Status

⁠Features

  • Automatic creation or upgrade of Global-Loadbalancers
  • Automatic scaling of Global-Loadbalancer (Loadbalancer on every host)
  • Automatic creation or upgrade of your application-stack
  • Automatic upload of dotenv Files to host via ssh (credentials)
  • Variable generation for server-side only credentials
  • Configurable domain per environment
  • Configurable host-affinity (service to host)

⁠Prerequisites

⁠Manual

Install rancher-cli⁠

⁠Gitlab-CI

Use the docker-image⁠

gitlab-ci.yml

...
deploy:
  stage: deploy
  image: lebokus/rancher-deploy:latest
  script:
    - rancher-deploy $CI_COMMIT_REF_NAME $CI_PROJECT_PATH
...

⁠Usage

  1. Create a rancher-deploy.yml in your project
connections:
  - 80/http
  - 443/https

domains:
  unmatched: <environment>.rancher-deploy.demo
  environments:
    master: rancher-deploy.demo

affinities:
  unmatched: development
  environments:
    master: production

dotenv:
  ssh-user: demouser
  ssh-private-key-variable: RANCHER_DEPLOY_HOST_SSH_KEY_<matched-affinity>
  include-existing-dotenv: true
  source-dotenv: .env.dist
  target-dotenv: /tmp/rancher-deploy/<environment>/.env
  variable-override:
   - APPLICATION_PASSWORD=@gen
   - APPLICATION_USER=${APPLICATION_USER}
  1. Create a rancher-compose.yml in your project
version: '2'

services:
  application:
    scale: 1
    image: <your-docker-image>
    labels:
      io.rancher.container.pull_image: always
      io.rancher.scheduler.affinity:host_label: environment=${RANCHER_DEPLOY_HOST_AFFINITY}
      global-loadbalancer-80-http: true
      global-loadbalancer-443-https: true 
    lb_config:
      port_rules:
      - target_port: 80
        hostname: ${RANCHER_DEPLOY_DOMAIN}
      - target_port: 443
        hostname: ${RANCHER_DEPLOY_DOMAIN}
    volumes:
     - ${RANCHER_DEPLOY_DOTENV_PATH}:/.env
  1. Export the required environment variables which can be configured in the rancher-web-interface:
  • RANCHER_URL
  • RANCHER_ACCESS_KEY
  • RANCHER_SECRET_KEY
  1. Export the ssh-private-key into the following variable:
  • RANCHER_DEPLOY_HOST_SSH_KEY_
  1. Execute rancher-deploy
rancher-deploy <your-environment-name> <stackname>

⁠Configuration

⁠service.label.global-loadbalancer

The global-loadbalancer can use a selector to identify corresponding services. rancher-deploy uses following pattern:

global-loadbalancer-<port>-<protocol>: true (the connections configured in rancher-deploy.yml)

If you want your service to listen at port 80 with the protocol http you need to add global-loadbalancer-80-http: true to your service labels

⁠service.lb_config

In this section you define the hostname and the target_port (service) which should be routed to this service.


⁠Exported Environment Variables

rancher-deploy exports following environment variables for usage in your rancher-compose.yml.

⁠RANCHER_DEPLOY_DOMAIN

The value for this variable is fetched from rancher-deploy.yml -> domains.environments.{your-environment-name}.

If no match is found the value from domains.unmatched is used and gets replaced with {your-environment-name}.

Use this variable in your services lb_config.port_rules configuration.

...
    lb_config:
      port_rules:
      - target_port: 80
        hostname: ${RANCHER_DEPLOY_DOMAIN}

This way you can deploy e.g. your review branches.

⁠RANCHER_DEPLOY_HOST_AFFINITY

The value for this variable is fetched from rancher-deploy.yml -> affinities.environments.{your-environment-name}.

If no match is found the value from affinities.unmatched is used and prefixed with {your-environment-name}.

Use this variable in your services labels configuration.

...
    labels:
        io.rancher.scheduler.affinity:host_label: environment=${RANCHER_DEPLOY_HOST_AFFINITY}

Then add a label e.g. environment=production at a host via the rancher-web-interface

In this way, you can control which service is deployed on which host.

⁠RANCHER_DEPLOY_DOTENV_PATH

Use this variable in your services volume configuration.

...
    volumes:
     - ${RANCHER_DEPLOY_DOTENV_PATH}:/.env

⁠Known Issues

  • Listen to the same port with different protocols is not possible

⁠License

This project is licensed under the MIT License

Tag summary

Content type

Image

Digest

Size

28.4 MB

Last updated

over 8 years ago

docker pull lebokus/rancher-deploy