Skip to content

Instantly share code, notes, and snippets.

@lmcarreiro
Created June 11, 2018 13:36
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save lmcarreiro/75186bd1d4e387c13c63d0a7087e9999 to your computer and use it in GitHub Desktop.
Save lmcarreiro/75186bd1d4e387c13c63d0a7087e9999 to your computer and use it in GitHub Desktop.
GitLab CI .gitlab-ci.yml example
stages:
- build
- test
- deploy
variables:
# from https://storage.googleapis.com/kubernetes-release/release/stable.txt
K8S_STABLE_VERSION_URL: https://storage.googleapis.com/kubernetes-release/release/v1.10.4/bin/linux/amd64/kubectl
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- export DOCKER_VERSION=$(echo "$CI_BUILD_REF" | cut -c 1-6)
- cd src/ProjectName && docker build -t registry.gitlab.com/username/project-name/webapp:$DOCKER_VERSION .
- cd ../../ && docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker push registry.gitlab.com/username/project-name/webapp:$DOCKER_VERSION
test:
stage: test
script: # TODO: write a test script
- exit 0
dependencies:
- build
deploy_dev:
stage: deploy
environment:
name: Dev
image: alpine
script:
- apk add --no-cache curl
- curl -LO $K8S_STABLE_VERSION_URL
- chmod +x ./kubectl
- mv ./kubectl /usr/local/bin/kubectl
- mkdir ~/.kube
- cp $KUBECONFIG ~/.kube/config
- cat ~/.kube/config
- kubectl cluster-info
# If no error, connection to the cluster from the pipeline script is OK
# TODO: write a deploy script
dependencies:
- test
@royzhao7
Copy link

how to set $KUBECONFIG

@visimo-jarod
Copy link

@royzhao7 KUBECONFIG is set if you configure the cluster correctly through the gitlab web gui. More info here: https://stackoverflow.com/questions/50749095/how-to-integrate-gitlab-ci-w-azure-kubernetes-kubectl-acr-for-deployments. Make sure that "production scope" for the cluster matches the same name as an environment that you create.

The external URL in the environment is pointing to where you should be able to access your app after it is deployed on the cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment