gitlab-templates/jobs/helm-chart-generate-and-push-to-local-repository.gitlab-ci.yml

41 lines
1.3 KiB
YAML

Generate and Push Kubernetes Manifests:
image: rbvtopudding/devops:latest
stage: deploy
before_script:
- |
if test ${CI_COMMIT_REF_NAME} = "main"; then
export ENVIRONMENT="prd";
elif test ${CI_COMMIT_REF_NAME} = "staging"; then
export ENVIRONMENT="stg";
else
export ENVIRONMENT="dev";
fi
script:
- helm dependency update ${HELM_CHART_PATH}
- rm -rf ${HELM_BASE_PATH}/${ENVIRONMENT}/manifests
- mkdir -p ${HELM_BASE_PATH}/${ENVIRONMENT}/manifests
- |
helm template \
--values ${HELM_CHART_VALUES_PATH} \
${HELM_CHART_EXTRA_OPTS} \
${HELM_CHART_NAME} \
${HELM_CHART_PATH} \
--output-dir /tmp/manifests
- mv /tmp/manifests/${HELM_CHART_NAME}/templates/*.yaml ${HELM_BASE_PATH}/${ENVIRONMENT}/manifests/
- rm -rf /tmp/manifests/${HELM_CHART_NAME}
- git config --global user.name "$CI_PROJECT_NAME"
- git config --global user.email "${CI_COMMIT_AUTHOR_EMAIL}"
- |
echo ${CI_PROJECT_URL} | \
sed 's/https:\/\///' | \
xargs -I## git remote add remote_origin "https://oauth2:${COMMIT_TOKEN}@##.git"
- git add --all
- git commit -m "[${ENVIRONMENT}] manifests updated, [ci skip]"
- git push -o ci.skip remote_origin HEAD:${CI_COMMIT_REF_NAME}
only:
- main
- staging
- develop