# t3.micro gitlab runner(s)
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitlab-runner-t3.micro
  namespace: spack
  labels:
    app: gitlab
    svc: runner
    size: t3.micro
spec:
  selector:
    matchLabels:
      app: gitlab
      svc: runner
      size: t3.micro
  replicas: 5 # Five at a time
  template:
    metadata:
      labels:
        app: gitlab
        svc: runner
        size: t3.micro
    spec:
      serviceAccountName: gitlab-runner
      containers:
      - name: runner
        image: "gitlab/gitlab-runner:latest"
        imagePullPolicy: Always
        lifecycle:
          postStart:
            exec:
              command:
              - "/bin/bash"
              - "-c"
              - >
                export RUNNER_NAME="$( hostname )" ;
                gitlab-runner unregister --name "$( hostname )" ;
                pushd /runner-scripts ;
                RUNNER_PRE_BUILD_SCRIPT="$( bash generate-pre-build )" ;
                RUNNER_POST_BUILD_SCRIPT="$( bash generate-post-build )" ;
                popd ;
                export RUNNER_PRE_BUILD_SCRIPT ;
                export RUNNER_POST_BUILD_SCRIPT ;
                gitlab-runner register \
                  --kubernetes-pod-annotations \
                    "cluster-autoscaler.kubernetes.io/safe-to-evict:false" \
                  --kubernetes-node-selector "type:gitlab-runner" \
                  --kubernetes-node-selector \
                    "beta.kubernetes.io/instance-type:t3.micro" \
          preStop:
            exec:
              command:
              - "/bin/bash"
              - "-c"
              - >
                gitlab-runner unregister --name "$( hostname )"

        env:
        - name: KUBERNETES_IMAGE
          value: "ghcr.io/scottwittenburg/ubuntu:18.04"

        - name: KUBERNETES_HELPER_IMAGE
          value: "ghcr.io/scottwittenburg/gitlab-gitlab-runner-helper:x86_64-ece86343"

        - name: CI_SERVER_URL
          value: "http://gitlab"

        - name: REGISTRATION_TOKEN
          valueFrom:
            secretKeyRef:
              name: gitlab-secrets
              key: gitlab-runner-token

        - name: ELASTIC_SEARCH_URL
          value: "http://elastic-search-es-http.spack.svc:9200"

        - name: ELASTIC_SEARCH_USER
          value: elastic

        - name: ELASTIC_SEARCH_PASS
          valueFrom:
            secretKeyRef:
              name: elastic-search-es-elastic-user
              key: elastic

        - name: RUNNER_EXECUTOR
          value: kubernetes

        - name: KUBERNETES_CPU_REQUEST
          value: "1.7" # prevent more than one job from running on a t3.micro

        - name: KUBERNETES_PULL_POLICY
          value: "if-not-present"

        - name: KUBERNETES_POLL_TIMEOUT
          value: "3600" # one hour

        - name: KUBERNETES_SERVICE_ACCOUNT
          value: "gitlab-runner"

        - name: KUBERNETES_NAMESPACE
          value: "spack"

        - name: REGISTER_NON_INTERACTIVE
          value: "true"

        - name: RUNNER_REQUEST_CONCURRENCY
          value: "32"

        - name: RUNNER_LIMIT
          value: "32"

        - name: RUNNER_TAG_LIST
          value: "spack-kube,t3.micro"
        resources:
          requests:
            memory: 20Mi
            cpu: 1m
          limits:
            memory: 100Mi
            cpu: 100m
        volumeMounts:
        - name: runner-scripts
          mountPath: /runner-scripts
      volumes:
        - name: runner-scripts
          configMap:
            name: gitlab-runner-scripts
            defaultMode: 0700
      nodeSelector:
        "beta.kubernetes.io/instance-type": "t2.medium"
