Skip to content

Instantly share code, notes, and snippets.

@devfelipereis
Last active October 25, 2018 14:08
Show Gist options
  • Save devfelipereis/067f1d834682b6c9a92e9acaf45d584f to your computer and use it in GitHub Desktop.
Save devfelipereis/067f1d834682b6c9a92e9acaf45d584f to your computer and use it in GitHub Desktop.
gitlab ci deploy rancher k8s example (commit sha)
image: docker:latest
services:
- docker:dind
stages:
- build
- deploy
variables:
DOCKER_DRIVER: overlay
IMAGE_TAG: $CI_REGISTRY_IMAGE
build:
stage: build
only:
- master
script:
- docker build -f Dockerfile.prod -t $IMAGE_TAG:${CI_COMMIT_SHA:0:8} .
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $IMAGE_TAG:${CI_COMMIT_SHA:0:8}
deploy_production:
stage: deploy
image: devfelipereis/rancher-cli-k8s:latest
environment:
name: production
url: https://your-app.com
when: on_success
only:
- master
script:
- rancher login $RANCHER_SERVER_URL --token $RANCHER_API_TOKEN --context $RANCHER_PROJECT_ID
- rancher kubectl --namespace=$RANCHER_PROJECT_NAMESPACE set image deployment/$DEPLOYMENT_NAME $DEPLOYMENT_NAME=$IMAGE_TAG:${CI_COMMIT_SHA:0:8}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment