Simplifies rancher deployment, keeps your rancher-compose.yml simple
1.0K
Simplifies rancher deployment, keeps your rancher-compose.yml simple
Install rancher-cli
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
...
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}
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
rancher-deploy <your-environment-name> <stackname>
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
In this section you define the hostname and the target_port (service) which should be routed to this service.
rancher-deploy exports following environment variables for usage in your rancher-compose.yml.
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.
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.
Use this variable in your services volume configuration.
...
volumes:
- ${RANCHER_DEPLOY_DOTENV_PATH}:/.env
This project is licensed under the MIT License
Content type
Image
Digest
Size
28.4 MB
Last updated
over 8 years ago
docker pull lebokus/rancher-deploy