Commit 6279c986 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

rename: rename from `kwrobot` to `ghostflow-director`

parent e871144f
[package]
name = "kwrobot"
name = "ghostflow-director"
version = "0.1.0"
authors = ["Ben Boeckel <ben.boeckel@kitware.com>"]
license = "MIT/Apache-2.0"
description = """
A robot which watches git repositories and performs actions to enforce a
A robot which watches git repositories and performs actions to coordinate a
workflow on them.
"""
repository = "https://gitlab.kitware.com/utils/kwrobot.git"
homepage = "https://gitlab.kitware.com/utils/kwrobot"
repository = "https://gitlab.kitware.com/utils/ghostflow-director.git"
homepage = "https://gitlab.kitware.com/utils/ghostflow-director"
readme = "README.md"
build = "build.rs"
......@@ -53,4 +53,4 @@ git = "https://gitlab.kitware.com/utils/rust-kitware-workflow.git"
features = ["gitlab"]
[[bin]]
name = "kwrobot"
name = "ghostflow-director"
kwrobot
=======
ghostflow-director
==================
The Kitware workflow uses a robot to manage various actions required for them.
This includes things such as running checks on topic branches, merging topic
branches, synchronizing mirrors of repositories, and handling test actions for
projects.
This tool is that robot, called "ghostflow-director" because it directs a
git-hosted workflow.
Projects are configured to be managed by various parts of the workflow which
are then handled by listening to JSON job files placed in a directory watched
by the robot. The job files are sorted out based on whether they were accepted
......
......@@ -67,7 +67,7 @@ fn handle_result<F>(notes: Vec<String>, defer: bool, post_comment: F) -> Handler
let txt_comment = notes.join("\n");
if defer {
info!(target: "kwrobot/handler",
info!(target: "ghostflow-director/handler",
"Deferring a job: {}",
txt_comment);
......@@ -78,7 +78,7 @@ fn handle_result<F>(notes: Vec<String>, defer: bool, post_comment: F) -> Handler
let md_comment = notes.join(" \n");
if let Err(err) = post_comment(&md_comment) {
error!(target: "kwrobot/handler",
error!(target: "ghostflow-director/handler",
"Failed to post comment:\n'{}'\n'{}'.",
md_comment, err);
}
......@@ -349,7 +349,7 @@ pub fn handle_merge_request_note<M: MergeRequestNoteInfo>(_: &Value, host: &Host
.is_some()
},
Err(err) => {
error!(target: "kwrobot/handler",
error!(target: "ghostflow-director/handler",
"failed to get the awards for a note at {}: {:?}",
mr.url(),
err);
......
......@@ -63,7 +63,7 @@ fn run_director(config_path: &Path) -> Result<RunResult, Box<Error>> {
}
fn try_main() -> Result<(), Box<Error>> {
let matches = App::new("kwrobot")
let matches = App::new("ghostflow-director")
.version(crate_version!())
.author("Ben Boeckel <ben.boeckel@kitware.com>")
.about("Watch a directory for project events and perform workflow actions on them")
......
/kwrobot-test-tmp/
/ghostflow-director-test-tmp/
# End-to-end tests
This is where testing of `kwrobot` from start to finish happens. It starts by
setting up a pristine Gitlab and registering an administrator user. It then
sets up a local git repository as well as users and repositories on Gitlab.
This is where testing of `ghostflow-director` from start to finish happens. It
starts by setting up a pristine Gitlab and registering an administrator user.
It then sets up a local git repository as well as users and repositories on
Gitlab.
The main bits of the test occurs at the bottom of the script where merge
requests are opened, comments made and checked, etc.
......@@ -68,45 +69,47 @@ use.
* docker: used to run Gitlab and must be usable by the user running the test;
* jq: used to process JSON in shell;
* curl: used to communicate with Gitlab for the script's purposes; and
* git: used to create the repository and check the results of kwrobot.
* git: used to create the repository and check the results of the director.
## Environment
* `HOSTNAME`: This needs to be a routable hostname the container can use to
contact the `webhook-listen` binary.
* `PATH`: Must be set so that `webhook-listen` and `kwrobot` are available.
* `PATH`: Must be set so that `webhook-listen` and `ghostflow-director` are
available.
# Logs
Everything from the tests should go into the `kwrobot-test-tmp` directory.
Files of note:
Everything from the tests should go into the `ghostflow-director-test-tmp`
directory. Files of note:
* `kwrobot-test-$USER` and `kwrobot-test-$USER.pub`: SSH keys for the users;
* `kwrobot.json`: the configuration file for kwrobot;
* `kwrobot.log`: log file from `kwrobot`;
* `secrets.json`: secrets file for kwrobot;
* `director-test-$USER` and `director-test-$USER.pub`: SSH keys for the users;
* `ghostflow-director.json`: the configuration file for ghostflow-director;
* `ghostflow-director.log`: log file from `ghostflow-director`;
* `secrets.json`: secrets file for ghostflow-director;
* `ssh_config`: SSH configuration file used by the tests;
* `webhook-listen.log`: log file from `webhook-listen`;
* `webhook.json`: the configuration file for `webhook-listen`;
* `queue/`: the queue of events dropped from `webhook-listen` for `kwrobot`;
* `queue/`: the queue of events dropped from `webhook-listen` for
`ghostflow-director`;
* `repo/`: local working repository for the tests; and
* `work/`: working directory for `kwrobot`
* `work/`: working directory for `ghostflow-director`
# Debugging
The following commands are useful for debugging the tests:
* `journalctl --user SYSLOG_IDENTIFIER={kwrobot,webhook-listen} --since=$TIME`:
* `journalctl --user SYSLOG_IDENTIFIER={ghostflow-director,webhook-listen} --since=$TIME`:
View the explicit logging of the tools.
* `docker exec -it kwrobot-gitlab-test cat $LOGFILE`: View the logs of gitlab
* `docker exec -it ghostflow-director-gitlab-test cat $LOGFILE`: View the logs of gitlab
itself
- `/var/log/gitlab/gitlab-rails/production.log`: HTTP queries
- `/var/log/gitlab/gitlab-rails/sidekiq.log`: event/webhook logs
* Logging into the Gitlab instance inside of the container may be done with
the `root` user, password `kwrobot-test`. If a non-administrator login is
wanted, all users share the same password. The IP is printed at the
beginning, but may also be discovered by running
`docker inspect kwrobot-gitlab-test | jq '.[0].NetworkSettings.IPAddress' | tr -d \"`.
the `root` user, password `ghostflow-director-test`. If a
non-administrator login is wanted, all users share the same password. The
IP is printed at the beginning, but may also be discovered by running
`docker inspect ghostflow-director-gitlab-test | jq '.[0].NetworkSettings.IPAddress' | tr -d \"`.
* The docker instance is torn down unless the `keep_docker` environment
variable is non-empty.
......@@ -116,10 +119,10 @@ The script cleans up after itself upon success, but leaves the container
running when things fail so that debugging may occur. The following will clean up the tests:
```sh
docker stop kwrobot-gitlab-test
docker rm kwrobot-gitlab-test
docker stop ghostflow-director-gitlab-test
docker rm ghostflow-director-gitlab-test
killall webhook-listen
killall kwrobot
killall ghostflow-director
```
The script takes care of cleaning up the temporary directory before running.
......
......@@ -3,8 +3,8 @@
# Error out if a command fails.
set -e
readonly docker_name="kwrobot-gitlab-test"
readonly admin_password="kwrobot-test"
readonly docker_name="ghostflow-director-gitlab-test"
readonly admin_password="ghostflow-director-test"
readonly webhook_port="50000"
__log_state="print_date"
......@@ -59,7 +59,7 @@ require_binary () {
require_binary "docker"
require_binary "jq"
require_binary "kwrobot"
require_binary "ghostflow-director"
require_binary "webhook-listen"
# Check that two strings are the same and error out with a useful message if
......@@ -148,7 +148,7 @@ loop_fetch () {
}
# Set up and clear out the temporary directory.
readonly tmpdir="$PWD/kwrobot-test-tmp"
readonly tmpdir="$PWD/ghostflow-director-test-tmp"
rm -rf "$tmpdir"
mkdir -p "$tmpdir"
......@@ -287,15 +287,15 @@ Host *
UserKnownHostsFile /dev/null
Host $docker_name
HostName $gitlab_addr
IdentityFile "$tmpdir/kwrobot-test-root"
IdentityFile "$tmpdir/ghostflow-director-test-root"
EOF
# Use the configuration file.
GIT_SSH_COMMAND="ssh -F $tmpdir/ssh_config"
export GIT_SSH_COMMAND
# Set up kwrobot.
info "Starting kwrobot..."
# Set up ghostflow-director.
info "Starting ghostflow-director..."
readonly workdir="$tmpdir/work"
mkdir -p "$workdir"
......@@ -309,9 +309,9 @@ sed -e "s,WORKDIR,$workdir," \
-e "s,GITLAB_HOST,$gitlab_addr," \
-e "s,SECRETS,$tmpdir/secrets.json," \
-e "s,HOSTNAME,$HOSTNAME," \
< "kwrobot-boot.json.in" \
> "$tmpdir/kwrobot.json"
RUST_BACKTRACE=1 kwrobot -dd --config "$tmpdir/kwrobot.json" > "$tmpdir/kwrobot.log" 2>&1 &
< "ghostflow-director-boot.json.in" \
> "$tmpdir/ghostflow-director.json"
RUST_BACKTRACE=1 ghostflow-director -dd --config "$tmpdir/ghostflow-director.json" > "$tmpdir/ghostflow-director.log" 2>&1 &
# Call the gitlab API.
#
......@@ -351,7 +351,7 @@ gitlab_add_user () {
#
# The users have the following powers:
#
# maintainer: has powers in `kwrobot`.
# maintainer: unused for now.
# origin: user to hold all target repositories.
# fork: a user with Developer access to the target repository.
# other: a user with no special access to the target repository.
......@@ -388,13 +388,13 @@ gitlab_add_ssh_key () {
# Create an SSH key for the user.
info "Creating the SSH key for $user..."
SSH_ASKPASS=false ssh-keygen -f "$tmpdir/kwrobot-test-$user" \
SSH_ASKPASS=false ssh-keygen -f "$tmpdir/ghostflow-director-test-$user" \
> /dev/null \
< /dev/null
# Encode the SSH key.
local pubkey="$( sed -e 's/+/%2B/g;s/ /+/g' \
< "$tmpdir/kwrobot-test-$user.pub" )"
< "$tmpdir/ghostflow-director-test-$user.pub" )"
readonly pubkey
info "Setting the SSH key for $user..."
......@@ -417,7 +417,7 @@ for user in $users; do
Host gitlab_$user
User git
HostName $gitlab_addr
IdentityFile "$tmpdir/kwrobot-test-$user"
IdentityFile "$tmpdir/ghostflow-director-test-$user"
IdentitiesOnly yes
EOF
done
......@@ -563,24 +563,25 @@ for user in origin; do
"(using $HOSTNAME)"
done
# Now use the real kwrobot.json.
info "Restarting kwrobot..."
# Now use the real ghostflow-director.json.
info "Restarting ghostflow-director..."
sed -e "s,WORKDIR,$workdir," \
-e "s,QUEUE,$queuedir," \
-e "s,GITLAB_HOST,$gitlab_addr," \
-e "s,SECRETS,$tmpdir/secrets.json," \
-e "s,HOSTNAME,$HOSTNAME," \
< "kwrobot.json.in" \
> "$tmpdir/kwrobot.json"
< "ghostflow-director.json.in" \
> "$tmpdir/ghostflow-director.json"
cat > "$queuedir/restart.json" <<EOF
{"kind": "watchdog:restart", "data": {}}
EOF
# Wait for `kwrobot` to get through all the job files present.
# Wait for `ghostflow-director` to get through all the job files present.
#
# This blocks until it appears that `kwrobot` has processed all of its data.
# This blocks until it appears that `ghostflow-director` has processed all of
# its data.
#
# Gitlab is intermittent when tossing out webhooks and timestamps show that our
# tools are behaving well and sidekiq is delaying things. Hopefully all of the
......@@ -599,12 +600,12 @@ wait_for_empty_queue () {
if ls "$queuedir/"*.json > /dev/null 2> /dev/null; then
info -n "Job queue is not empty..."
else
info -n "Waiting for kwrobot to receive a job..."
info -n "Waiting for ghostflow-director to receive a job..."
local waited
# XXX(gitlab): Seems that there can be a delay in Gitlab getting
# kwrobot the event. The logs point to sidekiq delaying the webhook
# firing for up to 20 seconds in testing. No root cause found yet;
# could be related to Gitlab being "cold" when initially started?
# ghostflow-director the event. The logs point to sidekiq delaying the
# webhook firing for up to 20 seconds in testing. No root cause found
# yet; could be related to Gitlab being "cold" when initially started?
local max_wait=30
readonly max_wait
for waited in $( seq 1 "$max_wait" ); do
......@@ -623,10 +624,10 @@ wait_for_empty_queue () {
info -n "waiting for a clean queue..."
while ls "$queuedir/"*.json > /dev/null 2> /dev/null; do
info -n "."
# Wait for what kwrobot did to appear in gitlab's database.
# Wait for what ghostflow-director did to appear in gitlab's database.
sleep 1
done
# kwrobot has been seen to take up to 4 seconds.
# ghostflow-director has been seen to take up to 4 seconds.
sleep 4
info "done."
......@@ -732,7 +733,7 @@ check_for_award () {
readonly note_id
shift
info "Making sure that kwrobot has marked the comment..."
info "Making sure that ghostflow-director has marked the comment..."
local award_name="$( gitlab_api "/projects/$project_id/merge_requests/$mr_id/notes/$note_id/award_emoji" | \
jq '.[0].name' )"
......@@ -1152,8 +1153,8 @@ last_mr_comment () {
# Check the latest comment on a merge request.
#
# The `<quiet>` parameter is an expression which if evaluates to `true` implies
# that the comment should not appear if the policy is for `kwrobot` to be
# silent about that response.
# that the comment should not appear if the policy is for `ghostflow-director`
# to be silent about that response.
#
# check_mr_comment <quiet> <merge request id> <expected content>
check_mr_comment () {
......@@ -1812,7 +1813,7 @@ for branch in $policy_branches; do
done
done
# Stop kwrobot.
# Stop ghostflow-director.
cat > "$queuedir/exit.json" <<EOF
{"kind": "watchdog:exit", "data": {}}
EOF
......@@ -1832,7 +1833,7 @@ if [ -z "$DOCKER_RUNNING" ]; then
info " docker rm $docker_name"
fi
info "Shutting down the webhook listener and kwrobot..."
info "Shutting down the webhook listener and ghostflow-director..."
# Kill tools
kill %1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment