goa

GitOps Agent - continuously monitors a remote git repository against local/any change, and performs actions (e.g. executes a provided command) - given a periodicity that is defined as a time intervals.

Usage

Download a binary from the releases for your OS and CPU architecture. Be sure to make the binary executable on the UNIX-based OSes (e.g. chmod +x goa).

Top-level

Help (–help)

A command-line GitOps utility agent

USAGE:
    goa <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help    Prints this message or the help of the given subcommand(s)
    spy     Spy a remote git repo for changes, will continuously execute defined script/command on a diff

Version (–version)

This does exactly what you’d expect.

Subcommand-level

Spy

Spy a remote git repo for changes, will continuously execute defined script/command on a diff

USAGE:
    goa spy [FLAGS] [OPTIONS] <url>

FLAGS:
    -e, --exec-on-start         Execute the command, or .goa file, on start
    -x, --exit-on-first-diff    Exit immediately after first diff spied
    -h, --help                  Prints help information
    -V, --version               Prints version information

OPTIONS:
    -b, --branch <branch>              The branch of the remote git repo to watch for changes [default: main]
    -c, --command <command>            The command to run when a change is detected [default: ]
    -d, --delay <delay>                The time between checks in seconds, max 65535 [default: 120]
    -T, --target-path <target-path>    The target path for the clone
    -t, --token <token>                The access token for cloning and fetching of the remote repo
    -u, --username <username>          Username, owner of the token - required for private repos
    -v, --verbosity <verbosity>        Adjust level of stdout, 0 no goa output , max 2 (debug) [default: 1]

ARGS:
    <url>    The remote git repo to watch for changes

Examples

This will echo out to the command line on startup, and then on any change to the main branch, looking for changes every 20 seconds.

This will execute the contents of the .goa file in the repo on any diffs found in the develop branch, looking for changes every 120 seconds. It will also log out debug-level details, which occur inside the processing loop (may get noisy).

This will output the author of the last commit made to the main branch, looking for changes every 120 seconds.

This will output “changed!” on stdout then exit after the first diff is identified on the “main” branch of the provided remote repo.

Will do the same as above, but create the local clone at /tmp/goa.

Using a .goa File

If no -c/--command is provided when starting goa - it will automatically look for a .goa file in the remote git repository, and execute the command within it.

The .goa file can only run a single command (right now, maybe multilines in the future)

An example repo with a .goa file can be seen here: https://github.com/kitplummer/goa_tester

Environment Variables

When goa executes it provides details on the latest commit through environment variables:

If there is something specific you’re looking for here, let me know via an issue.

Windows

Underneath, goa is providing the cmd /C so you don’t need to pass that in - just the command.

spy -c 'echo hello' -d 20 -v 3 https://github.com/kitplummer/goa_tester

And if you are using a .goa file, reference the command calling a batch like

.\hello.bat

Running as a container

Note: public release of the container to the GitHub registry is a work-in-progress - we’ll update the doc here when the container is pushed within the release process. For now you can build the container then run it.

docker run -it --rm kitplummer/goa spy --help

Running from a container, depending on the permissions of the underlying container system may cause issues with the abilty to execute commands from goa itself. Also, it might make more sense for goa to be integrated into a container that includes to the commands to be executed.

Builds

For each release we’re currently building binaries for:

Need something else, let me know and i’ll add the cross-compile to the GitHub Actions pipeline.

Contributing

Nothing formal, but PRs are the means. Create an issue if you have a question, comment, or just because. :D

License

MIT License

Copyright (c) 2021 Kit Plummer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.