Skip to content

Commit d16a270

Browse files
committed
add docs and update readme
1 parent e7ac97c commit d16a270

File tree

2 files changed

+132
-6
lines changed

2 files changed

+132
-6
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# dcspkg
22

3-
`dcspkg` is a simple package manager. It fetches tarballs containing precompiled binaries from a server, and then puts them in your home directory.
3+
`dcspkg` is a simple package manager, designed for used on DCS systems, or any system where packages cannot be installed as root. It fetches packages containing precompiled binaries from a server, and then installs them under your home directory.
4+
5+
## Documentation
6+
7+
This repo is a cargo workspace containing three crates:
8+
9+
- `dcspkg`, the CLI package manager
10+
- `dcspkg_server`, the package server
11+
- `dcspkg_create`, a helper tool for creating `.dcspkg` archives
12+
13+
See docs.md for full documentation
14+
15+
## Contributing
16+
17+
Contributions are welcome and encouraged. Check out the issues for things that we've noted need working on. Submit a PR and someone will get back to you with review.

docs.md

+117-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,60 @@ This document describes the codebase of this repo, and how to deploy and develop
44

55
## Overview
66

7-
This repo is organised as a [Cargo Workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html). It's one cargo project, but contains a 5 crates:
7+
This repo is organised as a [cargo workspace](https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html). It's one cargo project, but contains 3 crates:
88

99
- `dcspkg` is the command line client for downloading packages
1010
- `dcspkg_server` is the server for serving packages
1111
- `dcspkg_create` is a command line utility for adding a package to the server
12-
- `dcspkg_client` is a client libray, providing a wrapper around the server's API
13-
- `dcspkg_common` contains common types used within the system.
1412

15-
## Server
13+
## CLI (`dcspkg`)
14+
15+
This is the tool that is used to interact with the server.
16+
17+
- [`clap`](https://github.com/clap-rs/clap) is used to provide a nice cli
18+
- [`reqwest`](https://github.com/seanmonstar/reqwest) is used for http requests
19+
- [`config-rs`](https://github.com/mehcode/config-rs) is used to provide a configuration system
20+
21+
### Subcommands
22+
23+
- `list`
24+
- Fetch all packages and list them to stdout
25+
- Optionally dump json instead
26+
- `install <pkgname>`
27+
- Install a package, specified by it's pkgname
28+
- `installed`
29+
- Show all installed packages
30+
- Optionall dump json instead
31+
- `run <pkgname>`
32+
- Run the executable within a package
33+
34+
### Code Organisation
35+
36+
- `main.rs`
37+
- Entry point
38+
- `lib.rs`
39+
- Contains types that are to be exposed as a library for use by other crates
40+
- Current just the `Package` struct
41+
- `config.rs`
42+
- Contains types and functions for defining the configuration, and loading it from a file/environment variables
43+
- `util.rs`
44+
- Misc utility and helper functions
45+
- `cli.rs`
46+
- Contains the definition of the command line interface using clap
47+
- Contains the entry point for each subcommand
48+
- `commands`
49+
- Contains code associated with various subcommands
50+
- `install.rs`
51+
- Code to handle installing a package
52+
- `list.rs`
53+
- Code to fetch a package list
54+
55+
## Server (`dcspkg_server`)
1656

1757
The server provides a REST API for downloading packages. A database contains a registry of packages on disk, which are all just tarballs sat in a directory the server provides a file server into. [Rocket](https://rocket.rs/) is used as an async web framework, and [sqlx](https://github.com/launchbadge/sqlx) is used to provide async database interaction.
1858

59+
It uses the lib exposed by `dcspkg` to provide the definition of the `Package` struct.
60+
1961
### API Endpoints
2062

2163
- `/list` - returns a list of all the packages in the database
@@ -31,6 +73,76 @@ The server provides a REST API for downloading packages. A database contains a r
3173
- `handlers.rs`
3274
- The function handlers for the API endpoints
3375

34-
## Releasing
76+
## Create (`dcspkg_create`)
77+
78+
This tool takes a directory and packages it up, writing the metadata you give it to the database. See `dcspkg-create --help` for usage info. The tool will prompt you with various options that you may configure.
79+
80+
### Code Organisation
81+
82+
- `main.rs`
83+
- Entry point
84+
- Contains most of the driver code for prompting
85+
- Contains CLI definition using `clap`
86+
- `db.rs`
87+
- Helpers for interacting with the database
88+
- We use `sqlx` here too, but use the `smol` async runtime to wrap the async calls into synchronous functions
89+
- `archive.rs`
90+
- Stuff for interacting with archive files
91+
- `opts.rs`
92+
- Functions for prompting for each option
93+
- We use [dialoguer](https://github.com/mitsuhiko/dialoguer) for fancy stdin prompts
3594

3695
## Deployment
96+
97+
All three crates in this repo serve different purposes, and have different deployment methods
98+
99+
### CLI
100+
101+
The CLI is published to [crates.io](https://crates.io/crates/dcspkg). CI is set up such that whenever a version tag is pushed, it will automatically create a release on Github, and then publish the current version to crates.io.
102+
103+
To trigger this, create a tag that starts with the letter v and contains a valid semver version, ie `v0.2.1` (`git tag v0.2.1` will tag the current commit), and then push the tag to Github (`git push --tags`).
104+
105+
It would be nice if this CI job also built a binary and attached it to the release on Github for download.
106+
107+
### Server
108+
109+
The server is designed to run within a docker container. Every push to master will build a new container image for `dcspkg-server` and publish it to `ghcr.io/uwcs/dcspkg-server:latest`. Note that the server does not use the version of the library exposed by `dcspkg` from crates.io, but from the main branch on `Github`.
110+
111+
Re-deployment on the host will need to be done manually. This is done easiest using portainer, see the tech team wiki for more.
112+
113+
### Create
114+
115+
This doesn't really need deploying. If you need this tool, just pull the repo and build a binary.
116+
117+
## Package Format
118+
119+
A `.dcspkg` file is just a `.tar.gz`.
120+
121+
- The name of the package should be the same as `pkgname` in the database
122+
- The database contains the relative path of the executable within the package
123+
- This file is run when doing `dcspkg run`
124+
- Packages may contain an `install.sh` script, which will be run by `dcspkg install` if the database says that there is one
125+
126+
## Server Repo Layout
127+
128+
The package repo is on beryllium at `/home/uwucs/packages`.
129+
130+
- `packages/packagedb.sqlite` is the package database
131+
- The `packages/packages` directory contains all the package archives
132+
133+
Docker uses a bind mount to mount this directory in the container. A bind mount is used over a volume to make it easier to add to/edit the package repos on the host system.
134+
135+
## Local Repo Layout
136+
137+
The CLI creates `$HOME/.dcspkg` when you first use it.
138+
139+
- `.dcspkg/config.toml` contains the config for the cli
140+
- The three paths below, as well as server url, can be configured here
141+
- `.dcspkg/registry.json` contains the metadata for all packages you have installed
142+
- `.dcspkg/bin` contains symlinks to executables for packages that requested to be added to path
143+
- `.dcspkg/package` contains all the packages
144+
145+
## Development Notes
146+
147+
- Do not change the database schema or package format without good reason. Changing it will mean having to manually rebuild all the packages, which takes a lot of time.
148+
- Feel free to expose more API endpoints

0 commit comments

Comments
 (0)