diff --git a/.github/workflows/build-publish.yaml b/.github/workflows/build-publish.yaml new file mode 100644 index 0000000..ba69e3d --- /dev/null +++ b/.github/workflows/build-publish.yaml @@ -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/setup-ko@v0.6 + + - 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 diff --git a/.github/workflows/publish-web.yaml b/.github/workflows/publish-web.yaml deleted file mode 100644 index e3971ad..0000000 --- a/.github/workflows/publish-web.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Publish web -on: - push: - workflow_dispatch: -jobs: - publish: - runs-on: ubuntu-latest - name: Publish web - environment: publish - steps: - - uses: actions/checkout@v4 - - name: Push to S3 - uses: docker://docker.io/rclone/rclone:latest - env: - RCLONE_CONFIG_OBJSTORE_TYPE: s3 - RCLONE_CONFIG_OBJSTORE_PROVIDER: ${{ secrets.S3_PROVIDER }} - RCLONE_CONFIG_OBJSTORE_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - RCLONE_CONFIG_OBJSTORE_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - RCLONE_CONFIG_OBJSTORE_ENDPOINT: ${{ secrets.S3_ENDPOINT }} - RCLONE_CONFIG_OBJSTORE_REGION: ${{ secrets.S3_REGION }} - RCLONE_CONFIG_OBJSTORE_ACL: public-read - with: - args: copy --exclude .git/** --exclude .gitignore --exclude .github/** . objstore:syncthing-apt diff --git a/README.md b/README.md deleted file mode 100644 index 38d07a6..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -https://apt.syncthing.net/ -========================== - -This repo is auto deployed by simply copying all files in it. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f9c5235 --- /dev/null +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7786cdd --- /dev/null +++ b/go.sum @@ -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= diff --git a/main.go b/main.go new file mode 100644 index 0000000..0050d15 --- /dev/null +++ b/main.go @@ -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 +} diff --git a/css/bootstrap.min.css b/site/css/bootstrap.min.css similarity index 100% rename from css/bootstrap.min.css rename to site/css/bootstrap.min.css diff --git a/css/raleway.css b/site/css/raleway.css similarity index 100% rename from css/raleway.css rename to site/css/raleway.css diff --git a/css/styles.css b/site/css/styles.css similarity index 100% rename from css/styles.css rename to site/css/styles.css diff --git a/error.html b/site/error.html similarity index 100% rename from error.html rename to site/error.html diff --git a/fonts/raleway-400-webfont.eot b/site/fonts/raleway-400-webfont.eot similarity index 100% rename from fonts/raleway-400-webfont.eot rename to site/fonts/raleway-400-webfont.eot diff --git a/fonts/raleway-400-webfont.svg b/site/fonts/raleway-400-webfont.svg similarity index 100% rename from fonts/raleway-400-webfont.svg rename to site/fonts/raleway-400-webfont.svg diff --git a/fonts/raleway-400-webfont.ttf b/site/fonts/raleway-400-webfont.ttf similarity index 100% rename from fonts/raleway-400-webfont.ttf rename to site/fonts/raleway-400-webfont.ttf diff --git a/fonts/raleway-400-webfont.woff b/site/fonts/raleway-400-webfont.woff similarity index 100% rename from fonts/raleway-400-webfont.woff rename to site/fonts/raleway-400-webfont.woff diff --git a/fonts/raleway-400-webfont.woff2 b/site/fonts/raleway-400-webfont.woff2 similarity index 100% rename from fonts/raleway-400-webfont.woff2 rename to site/fonts/raleway-400-webfont.woff2 diff --git a/fonts/raleway-400.ttf b/site/fonts/raleway-400.ttf similarity index 100% rename from fonts/raleway-400.ttf rename to site/fonts/raleway-400.ttf diff --git a/fonts/raleway-700-webfont.eot b/site/fonts/raleway-700-webfont.eot similarity index 100% rename from fonts/raleway-700-webfont.eot rename to site/fonts/raleway-700-webfont.eot diff --git a/fonts/raleway-700-webfont.svg b/site/fonts/raleway-700-webfont.svg similarity index 100% rename from fonts/raleway-700-webfont.svg rename to site/fonts/raleway-700-webfont.svg diff --git a/fonts/raleway-700-webfont.ttf b/site/fonts/raleway-700-webfont.ttf similarity index 100% rename from fonts/raleway-700-webfont.ttf rename to site/fonts/raleway-700-webfont.ttf diff --git a/fonts/raleway-700-webfont.woff b/site/fonts/raleway-700-webfont.woff similarity index 100% rename from fonts/raleway-700-webfont.woff rename to site/fonts/raleway-700-webfont.woff diff --git a/fonts/raleway-700-webfont.woff2 b/site/fonts/raleway-700-webfont.woff2 similarity index 100% rename from fonts/raleway-700-webfont.woff2 rename to site/fonts/raleway-700-webfont.woff2 diff --git a/fonts/raleway-700.ttf b/site/fonts/raleway-700.ttf similarity index 100% rename from fonts/raleway-700.ttf rename to site/fonts/raleway-700.ttf diff --git a/images/favicon.png b/site/images/favicon.png similarity index 100% rename from images/favicon.png rename to site/images/favicon.png diff --git a/images/favicons/apple-touch-icon-114x114.png b/site/images/favicons/apple-touch-icon-114x114.png similarity index 100% rename from images/favicons/apple-touch-icon-114x114.png rename to site/images/favicons/apple-touch-icon-114x114.png diff --git a/images/favicons/apple-touch-icon-120x120.png b/site/images/favicons/apple-touch-icon-120x120.png similarity index 100% rename from images/favicons/apple-touch-icon-120x120.png rename to site/images/favicons/apple-touch-icon-120x120.png diff --git a/images/favicons/apple-touch-icon-144x144.png b/site/images/favicons/apple-touch-icon-144x144.png similarity index 100% rename from images/favicons/apple-touch-icon-144x144.png rename to site/images/favicons/apple-touch-icon-144x144.png diff --git a/images/favicons/apple-touch-icon-152x152.png b/site/images/favicons/apple-touch-icon-152x152.png similarity index 100% rename from images/favicons/apple-touch-icon-152x152.png rename to site/images/favicons/apple-touch-icon-152x152.png diff --git a/images/favicons/apple-touch-icon-57x57.png b/site/images/favicons/apple-touch-icon-57x57.png similarity index 100% rename from images/favicons/apple-touch-icon-57x57.png rename to site/images/favicons/apple-touch-icon-57x57.png diff --git a/images/favicons/apple-touch-icon-72x72.png b/site/images/favicons/apple-touch-icon-72x72.png similarity index 100% rename from images/favicons/apple-touch-icon-72x72.png rename to site/images/favicons/apple-touch-icon-72x72.png diff --git a/images/favicons/code.txt b/site/images/favicons/code.txt similarity index 100% rename from images/favicons/code.txt rename to site/images/favicons/code.txt diff --git a/images/favicons/favicon-16x16.png b/site/images/favicons/favicon-16x16.png similarity index 100% rename from images/favicons/favicon-16x16.png rename to site/images/favicons/favicon-16x16.png diff --git a/images/favicons/favicon-32x32.png b/site/images/favicons/favicon-32x32.png similarity index 100% rename from images/favicons/favicon-32x32.png rename to site/images/favicons/favicon-32x32.png diff --git a/images/favicons/favicon.ico b/site/images/favicons/favicon.ico similarity index 100% rename from images/favicons/favicon.ico rename to site/images/favicons/favicon.ico diff --git a/images/favicons/mstile-144x144.png b/site/images/favicons/mstile-144x144.png similarity index 100% rename from images/favicons/mstile-144x144.png rename to site/images/favicons/mstile-144x144.png diff --git a/images/logo-horizontal.svg b/site/images/logo-horizontal.svg similarity index 100% rename from images/logo-horizontal.svg rename to site/images/logo-horizontal.svg diff --git a/index.html b/site/index.html similarity index 100% rename from index.html rename to site/index.html