Created
June 11, 2018 13:36
-
-
Save lmcarreiro/75186bd1d4e387c13c63d0a7087e9999 to your computer and use it in GitHub Desktop.
GitLab CI .gitlab-ci.yml example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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
how to set $KUBECONFIG