-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up the bot to user kubernetes deployment
With kubernetes deployment, a restart script is in place. So, the twilio client is no longer needs to notify the maintainer when the bot fails Bug: T221331 Change-Id: I4dd15462efb0548e7d59e08d10494e8ab445a9c4
- Loading branch information
Showing
5 changed files
with
126 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Management script for gerrit-newcomer-bot kubernetes processes | ||
# | ||
# This file should be placed in the tool directory: | ||
# `/data/project/gerrit-newcomer-bot/bin` | ||
|
||
set -e | ||
|
||
DEPLOYMENT=gerrit-newcomer-bot.bot | ||
POD_NAME=gerrit-newcomer-bot.bot | ||
|
||
TOOL_DIR=$(cd $(dirname $0)/.. && pwd -P) | ||
VENV=${TOOL_DIR}/www/python/venv/ | ||
if [[ -f ${VENV}/bin/activate ]]; then | ||
# Enable virtualenv | ||
echo "Setting up virtualenv..." | ||
source ${VENV}/bin/activate | ||
else | ||
echo "Virtualenv not found!" | ||
echo "Expected it to be in ${VENV}" | ||
echo "I'm going to stop and let you fix that." | ||
exit 1 | ||
fi | ||
# Uncomment to debug packages installed in the venv | ||
# which python3 | ||
# pip3 list | ||
# exit | ||
|
||
_get_pod() { | ||
kubectl get pods \ | ||
--output=jsonpath={.items..metadata.name} \ | ||
--selector=name=${POD_NAME} | ||
} | ||
|
||
case "$1" in | ||
start) | ||
echo "Starting gerrit-newcomer-bot k8s deployment..." | ||
kubectl create -f ${TOOL_DIR}/etc/gerrit-newcomer-bot.yaml | ||
;; | ||
run) | ||
echo "Running gerrit-newcomer-bot..." | ||
cd ${TOOL_DIR}/www/python/src/ | ||
exec ${VENV}/bin/python3 watch_newcomers.py | ||
;; | ||
stop) | ||
echo "Stopping gerrit-newcomer-bot k8s deployment..." | ||
kubectl delete deployment ${DEPLOYMENT} | ||
;; | ||
restart) | ||
echo "Restarting gerrit-newcomer-bot k8s deployment..." | ||
$0 stop && | ||
$0 start | ||
;; | ||
status) | ||
echo "Active pods:" | ||
kubectl get pods -l name=${POD_NAME} | ||
;; | ||
tail) | ||
exec kubectl logs -f $(_get_pod) | ||
;; | ||
update) | ||
echo "Updating git clone..." | ||
cd ${TOOL_DIR}/www/python/src/ | ||
git fetch && | ||
git --no-pager log --stat HEAD..@{upstream} && | ||
git rebase @{upstream} | ||
;; | ||
attach) | ||
echo "Attaching to pod..." | ||
exec kubectl exec -i -t $(_get_pod) /bin/bash | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status|tail|update|attach}" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
exit 0 | ||
# vim:ft=sh:sw=4:ts=4:sts=4:et: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
# Run gerrit-newcomer-bot on kubernetes | ||
# | ||
# This file should be placed in the tool directory: | ||
# `/data/project/gerrit-newcomer-bot/etc` | ||
# | ||
kind: Deployment | ||
apiVersion: extensions/v1beta1 | ||
metadata: | ||
name: gerrit-newcomer-bot.bot | ||
namespace: gerrit-newcomer-bot | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
name: gerrit-newcomer-bot.bot | ||
spec: | ||
containers: | ||
- name: bot | ||
image: docker-registry.tools.wmflabs.org/toollabs-python35-base:latest | ||
command: [ "/data/project/gerrit-newcomer-bot/bin/gerrit-newcomer-bot.sh", "run" ] | ||
workingDir: /data/project/gerrit-newcomer-bot | ||
env: | ||
- name: HOME | ||
value: /data/project/gerrit-newcomer-bot | ||
imagePullPolicy: Always | ||
volumeMounts: | ||
- name: home | ||
mountPath: /data/project/gerrit-newcomer-bot/ | ||
volumes: | ||
- name: home | ||
hostPath: | ||
path: /data/project/gerrit-newcomer-bot/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters