Initial release: self-hostable APT repository server and CLI
urapt is a self-hostable APT repository server with a companion CLI for pushing and managing Debian .deb packages. Server (urapt-server): - REST API + APT endpoint, SQLite storage (pure-Go modernc driver, no CGO) - .deb files stored content-addressed on disk, reference-counted for dedup - Server-managed RSA-4096 OpenPGP signing key (ProtonMail/go-crypto) - APT indices (Release/InRelease/Packages[.gz/.xz]) generated on demand from the DB, cached in memory, signed with the server key - Full APT model: repositories -> distributions -> components -> architectures - Bearer-token auth for REST; HTTP Basic auth for private-repo APT reads - First registrant becomes admin; repo-scoped permissions (read/write/read-write/admin) plus owner and server-admin roles - Multipart package push with control-field extraction, list/show/delete, pool serving, blob ref-count cleanup - Audit log CLI (urapt): - register/login/logout/whoami, token management - repo/distro/component/arch CRUD, member management - push/pull/ls/show/rm for packages - apt-config helper that emits apt setup commands (key, sources.list, auth.conf for private repos) Packaging & docs: - Dockerfile (multi-stage distroless), docker-compose.yml, sample config - README quick start, architecture overview, config reference, security notes - PLAN.md design blueprint, CHANGELOG.md, GPL-3.0 LICENSE - GitHub Actions CI (test, lint, cross-build for linux/darwin amd64/arm64) - Makefile release target producing static binaries + tarballs + checksums Tests cover the data-access layer, auth/permission checks, APT index generation, .deb parsing, GPG signing, the REST API, and the typed API client. Verified end-to-end on a Raspberry Pi (arm64) pushing and installing a real package.
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"urapt/cli/output"
|
||||
)
|
||||
|
||||
func (r *Root) distroCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "distro",
|
||||
Short: "Manage distributions (suites) within a repository",
|
||||
}
|
||||
cmd.AddCommand(r.distroCreateCmd(), r.distroListCmd(), r.distroDeleteCmd())
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (r *Root) distroCreateCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "create <repo> <distro>",
|
||||
Short: "Add a distribution to a repository",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d, err := c.CreateDistribution(args[0], args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.flagJSON {
|
||||
output.JSON(d)
|
||||
} else {
|
||||
fmt.Printf("Created distribution %s in %s\n", d.Name, args[0])
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) distroListCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "list <repo>",
|
||||
Short: "List distributions in a repository",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dists, err := c.ListDistributions(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.flagJSON {
|
||||
output.JSON(dists)
|
||||
return nil
|
||||
}
|
||||
for _, d := range dists {
|
||||
fmt.Println(d.Name)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) distroDeleteCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "delete <repo> <distro>",
|
||||
Short: "Delete a distribution and its packages",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.DeleteDistribution(args[0], args[1]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Deleted distribution %s in %s\n", args[1], args[0])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) componentCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "component",
|
||||
Short: "Manage components within a distribution",
|
||||
}
|
||||
cmd.AddCommand(r.componentCreateCmd(), r.componentListCmd(), r.componentDeleteCmd())
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (r *Root) componentCreateCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "create <repo> <distro> <component>",
|
||||
Short: "Add a component to a distribution",
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
comp, err := c.CreateComponent(args[0], args[1], args[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.flagJSON {
|
||||
output.JSON(comp)
|
||||
} else {
|
||||
fmt.Printf("Created component %s in %s/%s\n", comp.Name, args[0], args[1])
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) componentListCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "list <repo> <distro>",
|
||||
Short: "List components in a distribution",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
comps, err := c.ListComponents(args[0], args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.flagJSON {
|
||||
output.JSON(comps)
|
||||
return nil
|
||||
}
|
||||
for _, comp := range comps {
|
||||
fmt.Println(comp.Name)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) componentDeleteCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "delete <repo> <distro> <component>",
|
||||
Short: "Delete a component",
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.DeleteComponent(args[0], args[1], args[2]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Deleted component %s in %s/%s\n", args[2], args[0], args[1])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) archCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "arch",
|
||||
Short: "Manage architectures within a distribution",
|
||||
}
|
||||
cmd.AddCommand(r.archAddCmd(), r.archListCmd(), r.archRemoveCmd())
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (r *Root) archAddCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "add <repo> <distro> <arch>",
|
||||
Short: "Add an architecture to a distribution",
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
a, err := c.CreateArchitecture(args[0], args[1], args[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.flagJSON {
|
||||
output.JSON(a)
|
||||
} else {
|
||||
fmt.Printf("Added architecture %s to %s/%s\n", a.Name, args[0], args[1])
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) archListCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "list <repo> <distro>",
|
||||
Short: "List architectures in a distribution",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
arches, err := c.ListArchitectures(args[0], args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.flagJSON {
|
||||
output.JSON(arches)
|
||||
return nil
|
||||
}
|
||||
for _, a := range arches {
|
||||
fmt.Println(a.Name)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Root) archRemoveCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "remove <repo> <distro> <arch>",
|
||||
Short: "Remove an architecture from a distribution",
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
c, err := r.client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.DeleteArchitecture(args[0], args[1], args[2]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Removed architecture %s from %s/%s\n", args[2], args[0], args[1])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user