Skip to content

Commit

Permalink
[docs/examples] update gitlab ci example based on 11.6 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Dec 23, 2018
1 parent 65ef4b7 commit 93f4a4d
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions docs/examples/gitlab/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ image: nuvo/orca
stages:
- build
- update_chart
- commit_chart
- upload_chart
- deploy
- delete
Expand All @@ -20,11 +21,12 @@ variables:

# Source code pipeline
#
# Triggered by changes in the src/ directory (GitLab 11.4+)
# Triggered by changes in the src/ directory (GitLab 11.4+) on all branches and on merge requests (Gitlab 11.6+)

build:
stage: build
only:
refs: [branches,merge_requests]
changes: [src/**/*]
image: docker:stable
services:
Expand All @@ -36,23 +38,37 @@ build:
docker login -u $CI_USER_NAME -p $CI_USER_TOKEN $CI_REGISTRY
docker push $IMAGE_NAME:$IMAGE_TAG
# Triggered by changes in the src/ directory on branch master
# Triggered by changes in the src/ directory on branch master and on merge requests

update_chart:
stage: update_chart
only:
refs: [master]
refs: [master,merge_requests]
changes: [src/**/*]
image: nuvo/build-utils
artifacts:
paths: [kubernetes]
expire_in: 1 hrs
script: |
yawn set kubernetes/$SERVICE_NAME/values.yaml image.tag $IMAGE_TAG
git remote set-url origin $(git remote get-url origin | sed 's|.*@|https://'$CI_USER_NAME:$CI_USER_TOKEN'@|') # set these variables at project level (Settings -> CI\CD)
# Triggered by changes in the src/ directory on branch master

commit_chart:
stage: commit_chart
only:
refs: [master]
changes: [src/**/*]
image: nuvo/build-utils
dependencies: [update_chart]
script: |
git remote set-url origin $(git remote get-url origin | sed 's|.*@|https://'$CI_USER_NAME:$CI_USER_TOKEN'@|')
git config --global user.email "$GITLAB_USER_EMAIL"
git config --global user.name "$GITLAB_USER_NAME"
git checkout $CI_COMMIT_REF_NAME
git add kubernetes/$SERVICE_NAME/values.yaml
git checkout $CI_BUILD_REF_NAME
git add kubernetes/service-a/values.yaml
git commit -m "Update chart with new image tag (during pipeline $CI_PIPELINE_ID)"
git push -u origin $CI_COMMIT_REF_NAME
git push -u origin $CI_BUILD_REF_NAME
# Helm chart pipeline
#
Expand Down Expand Up @@ -98,23 +114,12 @@ deploy_mainline:
# Merge request pipeline
#
# Assuming you are triggering a pipeline on merge request events,
# by either using a plugin or an external service (usually a web server)

update_chart_mr:
stage: update_chart
only: [trigger]
image: nuvo/build-utils
artifacts:
paths: [kubernetes]
expire_in: 1 hrs
script: |
yawn set kubernetes/$SERVICE_NAME/values.yaml image.tag $CI_PIPELINE_ID
# Continuing some jobs from previous steps

upload_chart_mr:
stage: upload_chart
only: [trigger]
dependencies: [update_chart_mr]
only: [merge_requests]
dependencies: [update_chart]
artifacts:
paths: [.chartversion]
expire_in: 1 hrs
Expand All @@ -126,7 +131,7 @@ upload_chart_mr:
deploy_dynamic_mr:
stage: deploy
only: [trigger]
only: [merge_requests]
environment:
name: $CI_COMMIT_REF_SLUG # assuming branch names are identical across related services, change as you see fit
script: |
Expand All @@ -142,7 +147,7 @@ deploy_dynamic_mr:
delete_dynamic_mr:
stage: delete
when: manual
only: [trigger]
only: [merge_requests]
script: |
orca delete env --name $CI_COMMIT_REF_SLUG \ # change according to deploy_dynamic_mr
--force

0 comments on commit 93f4a4d

Please sign in to comment.