Last active
October 31, 2019 09:55
-
-
Save brunomacf/308af32a6717b60ebab7904c4610b224 to your computer and use it in GitHub Desktop.
kube-test gitlab-ci
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
image: docker:latest | |
services: | |
- docker:dind | |
stages: | |
- build | |
- deploy | |
variables: | |
CONTAINER_DEV_IMAGE: registry.gitlab.com/brunomacf/kube-test:$CI_COMMIT_SHA | |
build_dev: | |
stage: build | |
script: | |
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com | |
- docker build --pull -t $CONTAINER_DEV_IMAGE . | |
- docker push $CONTAINER_DEV_IMAGE | |
only: | |
- develop | |
deploy_dev: | |
stage: deploy | |
image: alpine | |
environment: | |
name: develop | |
script: | |
- apk add --no-cache curl | |
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl | |
- chmod +x ./kubectl | |
- mv ./kubectl /usr/local/bin/kubectl | |
- kubectl config set-cluster nosebit --server="$KUBE_URL" --insecure-skip-tls-verify=true | |
- kubectl config set-credentials admin --username="$KUBE_USER" --password="$KUBE_PASSWORD" | |
- kubectl config set-context default --cluster=nosebit --user=admin | |
- kubectl config use-context default | |
- 'printf "apiVersion: v1\nkind: Secret\n$(kubectl create secret docker-registry gitlab-registry --docker-server=$CI_REGISTRY --docker-username=$CI_REGISTRY_USER --docker-password=$CI_REGISTRY_PASSWORD --docker-email=$GITLAB_USER_EMAIL -o yaml --dry-run)" | kubectl apply -f -' | |
- sed 's/_APP_NAME_/'"$CI_PROJECT_NAME"'/g; s/_VERSION_/'"$CI_COMMIT_SHA"'/g' kubernetes.tpl.yml > kubernetes.yml; | |
- kubectl apply -f kubernetes.yml | |
only: | |
- develop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks