gitlab-ci.yml 1.95 KiB
---
stages:
  - upload

upload:
  stage: upload
  image:
    name: alpine/helm
  before_script:
    - apk add --no-cache ca-certificates git curl yq
    - helm plugin install https://github.com/chartmuseum/helm-push.git
    - helm repo add --username ${CI_REGISTRY_USER} --password ${CI_REGISTRY_PASSWORD} my-repo "${CI_API_V4_URL}/projects/6/packages/helm/stable"
    - helm repo update
  script:
    - export VERSION=$(git describe --tags)
    - sed -i "s/__VERSION__/$VERSION/" chart/Chart.yaml
    - helm lint chart
    - helm cm-push chart my-repo

.deploy-to-git:
  image: alpine
  before_script:
    - apk add --no-cache ca-certificates git curl yq openssh-client-default
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$GITLAB_SSH_KEY")
    - git config --global user.name "${GITLAB_USER_NAME}"
    - git config --global user.email "${GITLAB_USER_EMAIL}"
    - mkdir -p ~/.ssh
    - ssh-keyscan -t rsa gitlab.exphost.pl >> ~/.ssh/known_hosts
    - curl -L "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl
    - chmod +x /usr/local/bin/kubectl
  script:
    - export VERSION=$(git describe --tags)
    - git clone $repo repo
    - cd repo
    - echo ${patch_cmd}
    - eval ${patch_cmd}
    - |
      if [[ -n "$(git status --porcelain)" ]]; then
        git add . &&
        git commit -m "update by gitlab-ci" &&
        git push
      fi
    - for try in {1..60} do
        state==$(kubectl -n argocd get applications "$waitapp" -o template='{{.status.health.status}},{{.status.sync.status}},{{.spec.source.targetRevision}}');
        echo $state;
        [ "$state" == "Healthy,Synced,$$VERSION"] && break;
        sleep 5;
      done
    - [ $$try -lt 60 ]

.deploy-to-git-subapp:
  extends: .deploy-to-git
  variables:
    patch_cmd: |
      values=$(yq e '.spec.source.helm.values' $yamlfile| yq e '.'"$app"'.version="'$$VERSION'"' -)
      yq e -i '.spec.source.helm.values=strenv(values)' $yamlfile