-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
129 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Build and Publish | ||
|
||
on: | ||
push: | ||
|
||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
jobs: | ||
build-and-push-docker-image: | ||
name: Build Docker image and push | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 'stable' | ||
|
||
- name: Setup ko | ||
uses: ko-build/[email protected] | ||
|
||
- name: Login to Github Packages | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build containers | ||
run: | | ||
ko build --bare --sbom=none -t latest . | ||
env: | ||
KO_DOCKER_REPO: ghcr.io/syncthing/apt-web |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
module github.com/syncthing/apt-web | ||
|
||
go 1.23.2 | ||
|
||
require github.com/meerkat-dashboard/meerkat v0.0.0-20240605084813-bc196007bb0c |
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,2 @@ | ||
github.com/meerkat-dashboard/meerkat v0.0.0-20240605084813-bc196007bb0c h1:jwuFa8OpeTeXT3EOq5IsiTiYKlaOU4isntQlDbZkBp8= | ||
github.com/meerkat-dashboard/meerkat v0.0.0-20240605084813-bc196007bb0c/go.mod h1:2qaHfLheTyaCMPpcjl/hUmRPdByJrZWQAAEn1ClllTA= |
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,82 @@ | ||
package main | ||
|
||
import ( | ||
"cmp" | ||
"embed" | ||
"io/fs" | ||
"log/slog" | ||
"net/http" | ||
"net/http/httputil" | ||
"net/url" | ||
"os" | ||
"path" | ||
"time" | ||
|
||
cacheProxy "github.com/meerkat-dashboard/meerkat/proxy" | ||
) | ||
|
||
//go:embed site | ||
var siteFS embed.FS | ||
|
||
var ( | ||
listenAddr = cmp.Or(os.Getenv("LISTEN_ADDRESS"), ":8080") | ||
distsHost = cmp.Or(os.Getenv("DISTS_HOST"), "https://syncthing-apt.s3.fr-par.scw.cloud") | ||
) | ||
|
||
func main() { | ||
subFS, _ := fs.Sub(fs.FS(siteFS), "site") | ||
site := http.FS(subFS) | ||
http.Handle("/", http.FileServer(site)) | ||
|
||
proxy, err := newCachingProxy(distsHost, 5*time.Minute) | ||
if err != nil { | ||
slog.Error("failed to construct proxy", "error", err) | ||
os.Exit(2) | ||
} | ||
filtered := validateFilename(proxy, []string{ | ||
"InRelease", | ||
"InRelease.gz", | ||
"Release", | ||
"Release.gz", | ||
"Release.gpg", | ||
"Release.gpg.gz", | ||
"Packages", | ||
"Packages.gz", | ||
"*.deb", | ||
}) | ||
http.Handle("/dists/", filtered) | ||
|
||
if err := http.ListenAndServe(listenAddr, nil); err != nil { | ||
slog.Error("failed to listen", "error", err) | ||
} | ||
} | ||
|
||
func validateFilename(next http.Handler, names []string) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
name := path.Base(req.URL.Path) | ||
for _, valid := range names { | ||
if ok, _ := path.Match(valid, name); ok { | ||
next.ServeHTTP(w, req) | ||
return | ||
} | ||
} | ||
http.NotFound(w, req) | ||
}) | ||
} | ||
|
||
func newCachingProxy(next string, cacheTime time.Duration) (http.Handler, error) { | ||
remote, err := url.Parse(next) | ||
if err != nil { | ||
return nil, err | ||
} | ||
rev := &httputil.ReverseProxy{ | ||
Rewrite: func(r *httputil.ProxyRequest) { | ||
r.SetURL(remote) | ||
}, | ||
} | ||
cp := &cacheProxy.Proxy{} | ||
cp.Next = rev | ||
rev.ModifyResponse = cp.StoreOKResponse(cacheTime) | ||
|
||
return cp, nil | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.