190 lines
4.4 KiB
Markdown
190 lines
4.4 KiB
Markdown
# Unpub
|
||
|
||
> 🧪 This is a small adaption of [unpub](https://pub.dev/packages/unpub) to docker.
|
||
|
||
---
|
||
|
||
## 📦 About
|
||
|
||
Unpub is a self-hosted private Dart Pub server, designed for enterprise use.
|
||
It includes a simple web interface for browsing and searching package information.
|
||
|
||
---
|
||
|
||
## ⚠️ MongoDB Compatibility
|
||
|
||
> The latest version of Unpub is **v2.1.0**, which was released over 2 years ago.
|
||
> Using MongoDB version 4.4 in conjunction provides the most stable experience.
|
||
|
||
---
|
||
|
||
## 🚀 Publishing a Package
|
||
|
||
Make sure your `pubspec.yaml` contains the following:
|
||
|
||
```yaml
|
||
name: <package_name>
|
||
description: <short description>
|
||
version: <semantic_version>
|
||
repository: <unpub_server_url>/packages/<package_name>
|
||
publish_to: <unpub_server_url>
|
||
```
|
||
|
||
### 1. Publish using Dart:
|
||
|
||
```bash
|
||
dart pub publish
|
||
```
|
||
|
||
---
|
||
|
||
### 2. Authentication issues?
|
||
|
||
If you encounter problems during publishing, set a fake auth token:
|
||
|
||
Install and use [`unpub_auth`](https://pub.dev/documentation/unpub_auth/latest/):
|
||
|
||
```bash
|
||
dart pub global activate unpub_auth # install the auth tool
|
||
unpub_auth login # log in via provided URL
|
||
unpub_auth get | dart pub token add <unpub_server_url>
|
||
# add token to pub client
|
||
dart pub publish # then try again
|
||
```
|
||
|
||
> The email address used for login will be displayed on the package’s webpage under the uploader section.
|
||
|
||
---
|
||
|
||
## 📥 Retrieving Packages
|
||
|
||
To use a package hosted on Unpub server, add the following to your `pubspec.yaml`:
|
||
|
||
```yaml
|
||
dependencies:
|
||
<package_name>:
|
||
hosted:
|
||
name: <package_name>
|
||
url: <unpub_server_url>
|
||
version: <semantic_version>
|
||
```
|
||
|
||
---
|
||
|
||
## 🐳 Docker Setup
|
||
|
||
This project includes a Docker-based deployment setup.
|
||
|
||
1. **Adjust** Unpub settings (especially the version) in `res/unpub/pubspec.yaml`
|
||
2. **Build the image:**
|
||
```bash
|
||
docker image build -t unpub .
|
||
```
|
||
3. **Start containers:**
|
||
```bash
|
||
docker-compose up -d
|
||
```
|
||
|
||
> 🔧 Make sure to adjust the `docker-compose.yaml` file according to your needs before running the containers.
|
||
|
||
---
|
||
|
||
## 🎨 Customizing the Web UI
|
||
|
||
To modify the web interface (e.g. logo, colors, layout):
|
||
|
||
- Edit the files in the `res/web` directory
|
||
- **Do this _before_ building the Docker image**, so your changes are included
|
||
|
||
---
|
||
|
||
## 💽 Backup & Restore Data
|
||
|
||
Packages are stored in the volume `volumes/packages-data`, the corresponding metadata in MongoDB (volume `volumes/db-data`). Make sure the volumes (see `docker-compose.yaml`) are **not deleted**.
|
||
|
||
In terms of prevent data lost, the volume `volumes/packages-data` has only be copied, but
|
||
just copying the volume `volumes/db-data` is not the best choice, additionally, you have the following options:
|
||
|
||
### 📦 Download a Package Archive
|
||
|
||
On the Unpub web interface, you can download an archive of any package version directly under the **Versions** section of the package page.
|
||
|
||
---
|
||
|
||
### 🔄 Create a MongoDB Backup
|
||
|
||
#### 1. Create a backup inside the container (e.g., under `/data/backup`)
|
||
|
||
```bash
|
||
docker exec mongo-unpub mongodump --out=/data/backup
|
||
```
|
||
|
||
#### 2. Copy the backup to the host machine
|
||
|
||
```bash
|
||
docker cp mongo-unpub:/data/backup ./mongo-backup
|
||
```
|
||
|
||
---
|
||
|
||
### ♻️ Restore a MongoDB Backup
|
||
|
||
#### 1. Copy the backup back into the container
|
||
|
||
```bash
|
||
docker cp ./mongo-backup mongo-unpub:/data/restore
|
||
```
|
||
|
||
#### 2. Start the restore process
|
||
|
||
```bash
|
||
docker exec mongo-unpub mongorestore /data/restore
|
||
```
|
||
|
||
🔁 Optional: Drop existing data before restoring:
|
||
|
||
```bash
|
||
docker exec mongo-unpub mongorestore --drop /data/restore
|
||
```
|
||
|
||
---
|
||
|
||
### 🗄️ Using the Provided Backup Service
|
||
|
||
A dedicated backup service is included to simplify data preservation. It performs a full backup by copying all unpub packages and dumping the MongoDB database in one step.
|
||
|
||
To run the backup, use the following command:
|
||
|
||
```bash
|
||
docker-compose run --rm backup
|
||
```
|
||
|
||
The resulting archive file will be saved in the `volumes/backups` directory.
|
||
|
||
---
|
||
|
||
## 🌐 Access
|
||
|
||
Once deployed, you can access the web interface via the unpub server address:
|
||
|
||
```
|
||
scheme://<unpub-server>/
|
||
```
|
||
|
||
Depending on the settings in `docker-compose.yaml` the uri can differ.
|
||
Without reverse proxy and other settings the server can be reached under the adress:
|
||
|
||
```
|
||
http://localhost:8080
|
||
```
|
||
|
||
---
|
||
|
||
## 👤 Author
|
||
|
||
Dennis Skupin
|
||
Based on the [unpub](https://pub.dev/packages/unpub) package by [Bytedance](https://pub.dev/packages/unpub)
|
||
Licensed under the [MIT License](LICENSE)
|
||
|
||
---
|