Commit a8c3f73d authored by Ruben ten Hove's avatar Ruben ten Hove
Browse files

feat: helm deploy

parent a262b9bf
Loading
Loading
Loading
Loading

k8s/generic.yml

0 → 100644
+11 −0
Original line number Diff line number Diff line
---
.kube-context:
  image: registry.gitlab.com/gitlab-org/cluster-integration/cluster-applications:latest
  stage: deploy
  environment:
    name: production
    action: prepare
  before_script:
    - gl-use-kube-context
    - chmod 400 $KUBECONFIG
  needs: []

k8s/helm/deploy.yml

0 → 100644
+43 −0
Original line number Diff line number Diff line
---
include:
  - local: k8s/generic.yml

.helm:
  extends: .kube-context
  variables:
    DEFAULT_ARGS: >
      --install
      --create-namespace
      --dependency-update
      --atomic
      --wait-for-jobs
      --render-subchart-notes
    EXTRA_ARGS: ""
  script:
    - |
      if test -f "${CI_JOB_NAME}/values.yaml"; then
        VALUES_ARG="-f ${CI_JOB_NAME}/values.yaml"
      fi
    - |
      echo "[*] Will helm with the following variables:
      REPO_NAME=${REPO_NAME}
      REPO_URL=${REPO_URL}
      CHART=${CHART}
      RELEASE=${RELEASE}
      CI_JOB_NAME=${CI_JOB_NAME}
      DEFAULT_ARGS=${DEFAULT_ARGS}
      VALUES_ARG=${VALUES_ARG}
      EXTRA_ARGS=${EXTRA_ARGS}
      NAMESPACE=${NAMESPACE:=default}"
    - helm repo add ${REPO_NAME} ${REPO_URL}
    - helm template ${REPO_NAME} ${CHART} ${VALUES_ARG} --namespace ${NAMESPACE:=default} --output-dir rendered
    - |
      if [ "${CI_COMMIT_BRANCH}" = "${CI_DEFAULT_BRANCH}" ]; then
        helm upgrade ${DEFAULT_ARGS} --namespace ${NAMESPACE:=default} ${RELEASE} ${CHART} ${VALUES_ARG} ${EXTRA_ARGS}
      else
        echo "[-] Not running on the default branch. Not deploying."
      fi
  artifacts:
    paths:
      - rendered
    when: always

k8s/helm/readme.md

0 → 100644
+41 −0
Original line number Diff line number Diff line
## Deploying a helm release

Create a folder named as your deployment. The following example deploys `cert-manager`.

```shell
repo-root
├── .gitlab-ci.yml
└── cert-manager
    ├── values.yml
    └── job.yml
```

In that `job.yml` add the following content. Ensure the name of the job equals the name of the subfolder.

```yaml
deployment-name:
  extends: .helm
  variables:
    REPO_NAME: jetstack
    REPO_URL: https://charts.jetstack.io
    NAMESPACE: cert-manager
    RELEASE: cert-manager
    CHART: jetstack/cert-manager
    EXTRA_ARGS: --set installCRDs=true
```

> Adjust values according to your helm release.

Optionally add a `values.yml` in that directory.

When you've added all your releases to the cluster management repository, add the following
to your `.gitlab-ci.yml`:

```yaml
---
include:
  - project: just-ci/templates
    file: k8s/helm/deploy.yml
    ref: v6.0.0
  - local: "**/job.yml"
```
+2 −0
Original line number Diff line number Diff line
@@ -13,3 +13,5 @@ tag_template = "v{new_version}"
src = "README.md"
[[file]]
src = "pipelines/container.md"
[[file]]
src = "k8s/helm/readme.md"