-
Notifications
You must be signed in to change notification settings - Fork 15
161 lines (157 loc) · 7.74 KB
/
ckan_auto.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
name: 4 - Automated CKAN Jobs
on:
schedule:
- cron: '30 7 * * *' # Tracking Update -- every day at 2:30am EST
- cron: '0 2 * * *' # S3 Sitemap Update -- every day at 10pm EST
- cron: '4/15 * * * *' # Harvester Check -- every 15 mins
- cron: '0 3 * * *' # DB-Solr-Sync -- every day at 10pm EST
- cron: '30 6 * * *' # Check Stuck Jobs -- every day at 1:30am EST
- cron: '0 13 * * *' # Generate Reports -- every day @9:00am EST
env:
ERROR: false
# Make sure 'schedule-cron' matches these varaibles.
SCHEDULE_TRACKING: '30 7 * * *'
SCHEDULE_SITEMAP: '0 2 * * *'
SCHEDULE_HARVESTING: '4/15 * * * *'
SCHEDULE_DBSOLR_SYNC: '0 3 * * *'
SCHEDULE_STUCK_JOBS: '30 6 * * *'
SCHEDULE_GEN_REPORT: '0 13 * * *'
jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Generate Matrix
id: generate-matrix
run: |
# Matrix Configuration Settings
# - Default App to run tasks on: cataog-admin
# - Default timeout for task to raise issue: 6 hours
# - Default Create an Information Issue for jobs we want to inspect: false
# - Default monitor state: true
# schedule: tracking update
# - Only run on [development, staging, prod]
# - Create Error issue: if runtime longer than 210 mins
# - Create Informational issue: tracking-update-info.md
# schedule: sitemap update
# - Only run on [prod]
# - Run on [catalog-gather] app
# schedule: harvesting update
# - Only run on [development, staging, prod]
# schedule: stuck jobs check
# - Only run on [staging, prod]
# - Create Error issue: if >0 stuck jobs, automated_ckan_error.md
# schedule: db-solr-sync
# - Only run on [staging, prod]
# - Create Error issue: if runtime longer than 30 mins
# - Create Informational issue: db-solr-sync-info.md
# schedule: report generation
# - Only run on [development, staging, prod]
# - Create Error issue: if ckan command errors
MATRIX=$(cat << MAT
{
"schedule": ["${{env.SCHEDULE_TRACKING}}", "${{env.SCHEDULE_SITEMAP}}",
"${{env.SCHEDULE_HARVESTING}}", "${{env.SCHEDULE_STUCK_JOBS}}",
"${{env.SCHEDULE_DBSOLR_SYNC}}", "${{ env.SCHEDULE_GEN_REPORT}}"],
"environ": ["development", "staging", "prod"],
"include": [ {"app": "catalog-admin"},
{"error_seconds": 22000},
{"info_issue": false},
{"issue_template": ".github/automated_ckan_error.md"},
{"monitor": true},
{"schedule": "${{env.SCHEDULE_HARVESTING}}", "command": "ckan harvester run"},
{"schedule": "${{env.SCHEDULE_TRACKING}}", "command": "ckan geodatagov tracking-update"},
{"schedule": "${{env.SCHEDULE_TRACKING}}", "error_seconds": 12600},
{"schedule": "${{env.SCHEDULE_TRACKING}}", "info_issue": true},
{"schedule": "${{env.SCHEDULE_TRACKING}}", "issue_template": ".github/tracking-update-info.md"},
{"schedule": "${{env.SCHEDULE_SITEMAP}}", "command": "ckan geodatagov sitemap-to-s3"},
{"schedule": "${{env.SCHEDULE_SITEMAP}}", "app": "catalog-gather"},
{"schedule": "${{env.SCHEDULE_DBSOLR_SYNC}}", "command": "ckan geodatagov db-solr-sync"},
{"schedule": "${{env.SCHEDULE_DBSOLR_SYNC}}", "error_seconds": 1800},
{"schedule": "${{env.SCHEDULE_DBSOLR_SYNC}}", "info_issue": true},
{"schedule": "${{env.SCHEDULE_DBSOLR_SYNC}}", "issue_template": ".github/db-solr-sync-info.md"},
{"schedule": "${{env.SCHEDULE_STUCK_JOBS}}", "command": "ckan geodatagov check-stuck-jobs"},
{"schedule": "${{env.SCHEDULE_GEN_REPORT}}", "command": "ckan report generate"},
{"schedule": "${{env.SCHEDULE_GEN_REPORT}}", "issue_template": ".github/report-generation-failure.md"},
{"environ": "development", "ram": "1G"},
{"environ": "staging", "ram": "2500M"},
{"environ": "prod", "ram": "3G"}
],
"exclude": [ {"schedule": "${{env.SCHEDULE_SITEMAP}}", "environ": "development"},
{"schedule": "${{env.SCHEDULE_SITEMAP}}", "environ": "staging"},
{"schedule": "${{env.SCHEDULE_DBSOLR_SYNC}}", "environ": "development"},
{"schedule": "${{env.SCHEDULE_STUCK_JOBS}}", "environ": "development"}
],
}
MAT
)
echo "matrix<<EOF" >> $GITHUB_OUTPUT
echo "$MATRIX" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
ckan-auto-command:
needs:
- setup-matrix
strategy:
max-parallel: 1
fail-fast: false
matrix: ${{ fromJSON(needs.setup-matrix.outputs.matrix) }}
name: ${{ matrix.command }} - ${{matrix.environ}}
runs-on: ubuntu-latest
environment: ${{matrix.environ}}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set Unique Command Name
run: |
INSTANCE_NAME="$(echo ${{ matrix.command }}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT} | tr -d ' ')"
echo "INSTANCE_NAME=${INSTANCE_NAME}" | tee -a $GITHUB_ENV
echo "START=`date +%s`" | tee -a $GITHUB_ENV
- name: ${{ matrix.command }}
if: ${{ github.event.schedule == matrix.schedule }}
uses: cloud-gov/cg-cli-tools@main
with:
command: >
cf run-task ${{ matrix.app }}
--command "${{ matrix.command }}"
--name "$INSTANCE_NAME"
-m ${{ matrix.ram }} -k 2G
cf_org: gsa-datagov
cf_space: ${{ matrix.environ }}
cf_username: ${{secrets.CF_SERVICE_USER}}
cf_password: ${{secrets.CF_SERVICE_AUTH}}
- name: monitor task output
if: ${{ matrix.monitor && github.event.schedule == matrix.schedule }}
uses: cloud-gov/cg-cli-tools@main
with:
command: >
tools/monitor_cf_logs.sh ${{ matrix.app }} $INSTANCE_NAME
cf_org: gsa-datagov
cf_space: ${{ matrix.environ }}
cf_username: ${{secrets.CF_SERVICE_USER}}
cf_password: ${{secrets.CF_SERVICE_AUTH}}
- name: check runtime
run: |
END=`date +%s`
ELAPSED=$(( END - START))
echo "$START, $END, $ELAPSED"
if [[ $ELAPSED > ${{ matrix.error_seconds }} ]]; then echo ERROR=true | tee -a $GITHUB_ENV; fi;
if [[ $ELAPSED > ${{ matrix.error_seconds }} ]]; then echo "ELAPSED=${ELAPSED}" | tee -a $GITHUB_ENV; fi;
- name: Create Issue for auditing 📑 or failure 😢
if: ${{ failure() || (env.ERROR == true) || (matrix.info_issue && github.event.schedule == matrix.schedule) }}
uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
GITHUB_JOB: ${{ toJson(github)['job'] }}
GITHUB_ATTEMPTS: ${{ github.run_attempt }}
LAST_COMMIT: ${{ github.sha }}
LAST_RUN_BY: ${{ github.actor }}
RUN_ID: ${{ github.run_id }}
COMMAND: ${{ matrix.command }}
SCHEDULE: ${{ matrix.schedule }}
ENVIRONMENT: ${{ matrix.environ }}
EXEC_TIME: ${{ env.ELAPSED }}
with:
filename: ${{ matrix.issue_template }}
update_existing: true