You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2018/07/30 20:38:15 UTC

[geode] branch develop updated: GEODE-5496 create reaper pipeline (#2224)

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 153fda2  GEODE-5496 create reaper pipeline (#2224)
153fda2 is described below

commit 153fda255ff839a94a94ac7a91109f431638ad39
Author: FSOUTHERLAND <39...@users.noreply.github.com>
AuthorDate: Mon Jul 30 13:38:10 2018 -0700

    GEODE-5496 create reaper pipeline (#2224)
    
    concourse instances now have ttl
    and are stopped and eventually
    deleted by a reaper pipline
    
    Co-authored-by: Jacob Barrett <jb...@pivotal.io>
---
 ci/pipelines/meta.yml        | 20 +++++++++++
 ci/pipelines/reaper.yml      | 83 ++++++++++++++++++++++++++++++++++++++++++++
 ci/scripts/start_instance.sh |  4 +++
 3 files changed, 107 insertions(+)

diff --git a/ci/pipelines/meta.yml b/ci/pipelines/meta.yml
index a592a17..4b7e301 100644
--- a/ci/pipelines/meta.yml
+++ b/ci/pipelines/meta.yml
@@ -61,6 +61,13 @@ resources:
     branch: ((!geode-build-branch))
     paths:
     - ci/pipelines/metrics.yml
+- name: geode-reaper-pipeline
+  type: git
+  source:
+    uri: https://github.com/((!geode-fork))/geode.git
+    branch: ((!geode-build-branch))
+    paths:
+    - ci/pipelines/reaper.yml
 - name: apachegeode-build-concourse-docker-image
   type: docker-image
   source:
@@ -157,3 +164,16 @@ jobs:
       - name: ((!geode-build-branch))-metrics
         team: ((!concourse-team))
         config_file: geode-metrics-pipeline/ci/pipelines/metrics.yml
+
+- name: set-reaper-pipeline
+  serial: true
+  public: ((!public-pipelines))
+  plan:
+  - get: geode-reaper-pipeline
+    trigger: true
+  - put: apachegeode-concourse
+    params:
+      pipelines:
+      - name: ((!geode-build-branch))-reaper
+        team: ((!concourse-team))
+        config_file: geode-reaper-pipeline/ci/pipelines/reaper.yml
\ No newline at end of file
diff --git a/ci/pipelines/reaper.yml b/ci/pipelines/reaper.yml
new file mode 100644
index 0000000..275149b
--- /dev/null
+++ b/ci/pipelines/reaper.yml
@@ -0,0 +1,83 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+---
+groups: []
+resources:
+- name: 1m
+  type: time
+  source:
+    interval: 1m
+resource_types: []
+jobs:
+- name: reaper
+  serial: true
+  plan:
+  - get: 1m
+    trigger: true
+  - task: reap
+    config:
+      platform: linux
+      image_resource:
+        type: docker-image
+        source:
+          password: ((!docker-password))
+          repository: gcr.io/apachegeode-ci/alpine-tools
+          tag: latest
+          username: ((!docker-username))
+      run:
+        path: bash
+        args:
+        - -exc
+        - |
+          set -x
+          set -e
+
+          now=$(date +%s)
+
+          # Stop running instances that are expired
+
+          instances=$(gcloud compute instances list \
+              --filter="labels.time-to-live:* AND labels.time-to-live<${now} AND status:RUNNING" \
+              --format='json(name, zone)')
+
+          zone_names=$(echo "${instances}" | jq -r 'unique_by(.zone) | .[].zone')
+
+          for zone in ${zone_names}; do
+            zoneInstances=$(echo "${instances}" | jq -r --arg ZONE "${zone}" '.[] | select(.zone == $ZONE) | .name')
+            gcloud compute instances stop ${zoneInstances} --zone=${zone} &
+          done
+
+          wait
+
+          # Delete stopped instances over 24h expired
+
+          oneDay=$((60 * 60 * 24))
+          yesterday=$((${now} - ${oneDay}))
+
+          instances=$(gcloud compute instances list \
+              --filter="labels.time-to-live:* AND labels.time-to-live<${yesterday} AND status:TERMINATED" \
+              --format='json(name, zone:sort=1)')
+
+          zone_names=$(echo "${instances}" | jq -r 'unique_by(.zone) | .[].zone')
+
+          for zone in ${zone_names}; do
+            zoneInstances=$(echo "${instances}" | jq -r --arg ZONE "${zone}" '.[] | select(.zone == $ZONE) | .name')
+            gcloud compute instances delete ${zoneInstances} --zone=${zone} --quiet &
+          done
+
+          wait
+
diff --git a/ci/scripts/start_instance.sh b/ci/scripts/start_instance.sh
index 9e72c8b..aa1e1b7 100755
--- a/ci/scripts/start_instance.sh
+++ b/ci/scripts/start_instance.sh
@@ -63,6 +63,9 @@ echo 'StrictHostKeyChecking no' >> /etc/ssh/ssh_config
 echo "RAM is ${RAM}"
 RAM_MEGABYTES=$( expr ${RAM} \* 1024 )
 echo "RAM_MEGABYTES is ${RAM_MEGABYTES}"
+
+TTL=$(($(date +%s) + 60 * 60 * 2))
+
 INSTANCE_INFORMATION=$(gcloud compute --project=${PROJECT} instances create ${INSTANCE_NAME} \
   --zone=${ZONE} \
   --machine-type=custom-${CPUS}-${RAM_MEGABYTES} \
@@ -71,6 +74,7 @@ INSTANCE_INFORMATION=$(gcloud compute --project=${PROJECT} instances create ${IN
   --image-project=${PROJECT} \
   --boot-disk-size=100GB \
   --boot-disk-type=pd-ssd \
+  --labels=time-to-live=${TTL} \
   --format=json)
 CREATE_EXIT_STATUS=$?