Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: barelyhuman/goblin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.0
Choose a base ref
...
head repository: barelyhuman/goblin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dev
Choose a head ref
  • 15 commits
  • 10 files changed
  • 1 contributor

Commits on Sep 27, 2024

  1. feat: add a simple version resolver api (#25)

    * feat: add a simple version resolver api
    
    * feat: simple rate limiter addition for the same
    barelyhuman authored Sep 27, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    80c34a3 View commit details

Commits on Sep 28, 2024

  1. docs: update

    barelyhuman committed Sep 28, 2024
    Copy the full SHA
    5549e25 View commit details
  2. ci: update for release images

    barelyhuman committed Sep 28, 2024
    Copy the full SHA
    d485e77 View commit details
  3. chore: v0.4.0

    barelyhuman committed Sep 28, 2024
    Copy the full SHA
    dc5e158 View commit details
  4. ci: fix id duplication

    barelyhuman committed Sep 28, 2024
    Copy the full SHA
    291401a View commit details
  5. ci: add nightly tags

    barelyhuman committed Sep 28, 2024
    Copy the full SHA
    f1353aa View commit details
  6. ci: correct names

    barelyhuman committed Sep 28, 2024
    Copy the full SHA
    c32cecb View commit details

Commits on Oct 1, 2024

  1. refactor: update minio api version (#26)

    * refactor: update minio api version
    
    * chore: add `STORAGE_BUCKET_PREFIX` to the env example
    
    * ci: chore change build matrix
    barelyhuman authored Oct 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    abf9fd1 View commit details

Commits on Oct 2, 2024

  1. chore: v0.5.0

    barelyhuman committed Oct 2, 2024
    Copy the full SHA
    902ca4a View commit details
  2. ci: update

    barelyhuman committed Oct 2, 2024
    Copy the full SHA
    0c7189d View commit details
  3. ci: automate image metadata generation by events (#27)

    * ci: change login secret
    
    * ci: automate tag handling
    barelyhuman authored Oct 2, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7f85c96 View commit details
  4. chore: v0.5.1

    barelyhuman committed Oct 2, 2024
    Copy the full SHA
    82089ed View commit details
  5. ci: cleanup for images (#28)

    * ci: add a cleanup for the images
    
    * ci: add it as a schedule
    
    * docs: update for the current images
    barelyhuman authored Oct 2, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ee80fc5 View commit details

Commits on Dec 13, 2024

  1. chore: bump modules for sec patch

    barelyhuman committed Dec 13, 2024
    Copy the full SHA
    aecd416 View commit details
  2. chore: v0.5.2

    barelyhuman committed Dec 13, 2024
    Copy the full SHA
    b560c07 View commit details
Showing with 304 additions and 88 deletions.
  1. +1 −1 .commitlog.release
  2. +1 −0 .env.example
  3. +22 −0 .github/workflows/cleanup.yml
  4. +36 −33 .github/workflows/docker-pub.yml
  5. +1 −1 .github/workflows/go.yml
  6. +87 −3 cmd/goblin-api/main.go
  7. +22 −9 go.mod
  8. +36 −21 go.sum
  9. +29 −6 readme.md
  10. +69 −14 storage/minio.go
2 changes: 1 addition & 1 deletion .commitlog.release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.0
v0.5.2
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ STORAGE_CLIENT_ID=
STORAGE_CLIENT_SECRET=
STORAGE_ENDPOINT=
STORAGE_BUCKET=
STORAGE_BUCKET_PREFIX=
ORIGIN_URL="" # eg: "http://localhost" depending on your nginx config changes
GITHUB_TOKEN="" # required for github version resolutions

22 changes: 22 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Cleaner

on:
workflow_dispatch:
schedule:
- cron: "0 0 12,25 * *"

jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/delete-package-versions@v5
with:
package-name: goblin
package-type: container
min-versions-to-keep: 10
ignore-versions: '(v?\d+\.\d+\.\d+|latest|(nightly[-]\w+))'
69 changes: 36 additions & 33 deletions .github/workflows/docker-pub.yml
Original file line number Diff line number Diff line change
@@ -4,58 +4,61 @@ on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
pull_request:
branches:
- 'dev'
push:
tags:
- 'v*.*.*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}


jobs:
build:
name: Buid and push Docker image to GitHub Container registry
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4

- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y%m%d')"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build Meta
run: echo "::set-output name=dtag::ghcr.io/barelyhuman/goblin:nightly-${{ steps.date.outputs.date }}"
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v5
- name: Build and push Docker image
id: push
env:
REGISTRY: ghcr.io
OWNER: ${{ github.repository_owner }}
IMAGE_NAME: ${{ github.repository }}
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.dtag }}

tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/barelyhuman/goblin
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
push-to-registry: true
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["1.19.0", "1.21.5", "1.22.2"]
version: ["1.21", "1.22"]
steps:
- uses: actions/checkout@v3

90 changes: 87 additions & 3 deletions cmd/goblin-api/main.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package main

import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
@@ -19,11 +20,42 @@ import (
"github.com/barelyhuman/goblin/resolver"
"github.com/barelyhuman/goblin/storage"
"github.com/joho/godotenv"
"go.uber.org/ratelimit"
)

var shTemplates *template.Template
var serverURL string
var storageClient storage.Storage
var rateLimiter ratelimit.Limiter

type ErrorJSON struct {
Success bool `json:"success"`
Message string `json:"message"`
}

func (ej ErrorJSON) toJSONString() (string, error) {
marshaled, err := json.Marshal(ej)
if err != nil {
return "", err
}
return string(marshaled), nil
}

type VersionJSON struct {
Success bool `json:"success"`
Package string `json:"package"`
Binary string `json:"binary"`
OriginalVersion string `json:"originalVersion"`
Version string `json:"version"`
}

func (ej VersionJSON) toJSONString() (string, error) {
marshaled, err := json.Marshal(ej)
if err != nil {
return "", err
}
return string(marshaled), nil
}

func HandleRequest(rw http.ResponseWriter, req *http.Request) {
path := req.URL.Path
@@ -41,6 +73,13 @@ func HandleRequest(rw http.ResponseWriter, req *http.Request) {
return
}

if strings.HasPrefix(path, "/version") {
log.Println("Resolving version")
rateLimiter.Take()
resolveVersionJSON(rw, req)
return
}

if strings.HasPrefix(path, "/binary") {
log.Print("handle binary")
fetchBinary(rw, req)
@@ -75,6 +114,9 @@ func main() {

flag.Parse()

// starting off with 250 since there's only one operation that's being rate limited
rateLimiter = ratelimit.New(250)

if _, err := os.Stat(*envFile); !errors.Is(err, os.ErrNotExist) {
err := godotenv.Load()
if err != nil {
@@ -98,25 +140,37 @@ func main() {
}

func clearStorageBackgroundJob() {
if !isStorageEnabled() {
log.Printf("Clearer Disabled since storage is disabled")
return
}

cacheHoldEnv := env.Get("CLEAR_CACHE_TIME", "")
if len(cacheHoldEnv) == 0 {
return
}

cacheHoldDuration, _ := time.ParseDuration(cacheHoldEnv)
cacheHoldDuration, err := time.ParseDuration(cacheHoldEnv)
if err != nil {
log.Println(err)
return
}
log.Printf("Clearer Initialized for: %v\n", cacheHoldDuration)

cleaner := func(storageClient storage.Storage) {
log.Println("Cleaning Cached Storage Object")
objects := storageClient.ListObjects()
now := time.Now()
for _, obj := range objects {
objExpiry := obj.LastModified.Add(cacheHoldDuration)
if time.Now().Equal(objExpiry) || time.Now().After(objExpiry) {
if now.Equal(objExpiry) || now.After(objExpiry) {
storageClient.RemoveObject(obj.Key)
}
}
}

ticker := time.NewTicker(cacheHoldDuration)
tickerDur, _ := time.ParseDuration("2m")
ticker := time.NewTicker(tickerDur)
quit := make(chan struct{})

go func() {
@@ -225,6 +279,36 @@ func fetchInstallScript(rw http.ResponseWriter, req *http.Request) {
})
}

func resolveVersionJSON(rw http.ResponseWriter, req *http.Request) {
// only reply in JSON
rw.Header().Set("Content-Type", "application/json")

pkg := strings.TrimPrefix(req.URL.Path, "/version")
pkg, _, version, name := parsePackage(pkg)
v := &resolver.Resolver{
Pkg: pkg,
}
v.ParseVersion(version)
resolvedVersion, err := v.ResolveVersion()
if err != nil || len(resolvedVersion) == 0 {
errorJson, _ := ErrorJSON{Success: false, Message: "Failed to resolve version:" + version}.toJSONString()
rw.Write([]byte(errorJson))
return
}

responseJson, _ := VersionJSON{
Success: true,
Package: pkg,
Binary: name,
OriginalVersion: version,
Version: resolvedVersion,
}.toJSONString()

rw.Write([]byte(responseJson))
return

}

func fetchBinary(rw http.ResponseWriter, req *http.Request) {
pkg := strings.TrimPrefix(req.URL.Path, "/binary/")

31 changes: 22 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
module github.com/barelyhuman/goblin

go 1.19
go 1.21

toolchain go1.22.2

require (
github.com/Masterminds/semver v1.5.0
github.com/barelyhuman/go v0.2.2
github.com/google/go-github/v53 v53.2.0
github.com/joho/godotenv v1.5.1
github.com/minio/minio-go v6.0.14+incompatible
github.com/minio/minio-go/v7 v7.0.77
github.com/tj/go-semver v1.0.0
go.uber.org/ratelimit v0.3.1
golang.org/x/oauth2 v0.16.0
)

// Sec patches
require golang.org/x/crypto v0.31.0 // indirect

require google.golang.org/protobuf v1.33.0 // indirect

require (
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/rs/xid v1.6.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading