Skip to content

barelyhuman/goblin

Repository files navigation

goblin

gobinaries alternative

Simply put it's a lot of code that's been picked up from the original gobinaries and the majority of the reason is that most of the research for the work has been already done there.

The reason for another repo is that the development on gobinaries has been slow for the past few months / years at this point and go has moved up 2 version and people are still waiting for gobinaries to update itself.

All credits to tj for the idea and the initial implementation.

Why not fork?

To keep it short, it's fun to build the arch from scratch, helps you learn. Also the mentality of both the authors differ.

(was easier to start from scratch then remove each blocking thing from the original one)

Highlights

  • Easy to use - Users don't need go to install your CLI
  • Works with most common package ( Raise an issue if you find it not working with something)
  • Persistence ( can be made into a temporary cache to minimize storage costs)
  • Self Hostable

Roadmap

  • Cache a previously built version binary
    • Builds are cache for 6 hours due reduce storage costs, since it's run by a solo developer
  • Add support for download binaries from existing Github Release artifacts

Authors

Reaper, Mvllow

Usage

You can read about it on https://goblin.run

Exposed API

from v0.4.0 The server exposes a the following public routes usable for information

GET /version/<path>/<to>/<pkg>

  • A GET /version request on a package path for example github.com/barelyhuman/commitlog/v3 would give you the latest version resolved for it by comparing it on the goproxy and github's repo tags. This is the same algo used internally by Goblin and is available to you.

Deploy your own

Since the entire reason for doing this was that delay on the original implementation added a lot more handling and addition of scripts to my website deployments than I liked.

I wouldn't want that to happen again, so I really recommend people to spin up their own instances if they can afford to do so. If not, you can always use the hosted version from me at goblin.run

Note:the original code for gobinaries is equally simple to use and deploy but you'll have to make a few tweaks to the original code to make it work in a simpler fashion

Existing Image

The repository builds and publishes a latest and a semver tagged version on each release. You can use that if you do not wish to tweak or change anything in the original source code and build structure

$ docker run -p "3000:3000" ghcr.io/barelyhuman/goblin:latest
# change the domain to whatever you are using for it
$ docker run -e "GOBLIN_ORIGIN_URL=example.com" -p "3000:3000" ghcr.io/barelyhuman/goblin:latest

Using Docker

  1. Setup docker or any other platform that would allow you to build and run docker images, if using services like Digital Ocean or AWS, you can use their container and docker image specific environments
  2. Build the image
cd goblin
docker build -t goblin:latest .
  1. And finally push the image to either of the environments as mentioned in point 1. If doing it on a personal compute instance, you can just install docker, do step 3 and then run the below command.
docker run -p "3000:3000" goblin:latest

Using Traditional Servers

Let's face it, docker can be heavy and sometimes it's easier to run these apps separately as a simple service.

Much like most go lang projects, goblin can be built into a single binary and run on any open port.

The repo comes with helper scripts to setup an ubuntu server with the required stuff

  1. Caddy for server
  2. Go and Node for language support
  3. PM2 as a process manager and start the process in the background

You can run it like so

./scripts/prepare-ubuntu.sh

If you already have all the above setup separately, you can modify the build script and run that instead.

./scripts/build.sh

You'll have to create 2 .env files, one inside www and one at the root .env

# .env

# token from github that allows authentication for resolving versions from go modules as github repositories
GITHUB_TOKEN=
#  the url that you want the server to use for creating scripts
ORIGIN_URL=
# www/.env

# the same url as ORIGIN_URL but added again because the static build needs it in the repo
GOBLIN_ORIGIN_URL=

running the build.sh should handle building with the needed env files and restarting the server for you.

Configuration

The server can be configured easily using environment variables

KEY default description options
STORAGE_ENABLED false Enable persistence true
STORAGE_CLIENT_ID CLIENT_ID of a S3 compatible storage
STORAGE_CLIENT_SECRET CLIENT_SECRET of a S3 compatible storage
STORAGE_ENDPOINT Endpoint value of an S3 compatible storage
STORAGE_BUCKET Bucket name of the S3 compatible storage
STORAGE_BUCKET_PREFIX folder/namespace to store the files inside the bucket
PORT 3000 Default port for running the application
ORIGIN_URL http://localhost:${PORT} Default URL of the application
GITHUB_TOKEN Github authentication token for accessing github repositories and resolving versions
CLEAR_CACHE_TIME Duration used to clear and set expiry for stored binaries 1m,30s, etc

License

MIT