Skip to content

Commit b340c79

Browse files
committed
chore: update example
1 parent e45ada1 commit b340c79

File tree

8 files changed

+84
-64
lines changed

8 files changed

+84
-64
lines changed

README.md

+4-35
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</p>
77

88
<p align="center">
9-
<img src="https://skillicons.dev/icons?i=next,tailwind,nest,typescript,docker,graphql" />
9+
<img src="https://skillicons.dev/icons?i=vite,tailwind,nest,typescript,docker,graphql" />
1010
<br/>
11-
<a href="https://discord.gg/VDMX6VQRZm"><kbd>🔵 discord</kbd></a> <a href="https://micro.sylo.digital"><kbd>🟢 hosted instance</kbd></a>
11+
<a href="https://discord.gg/VDMX6VQRZm"><kbd>🔵 discord</kbd></a> <a href="https://micro.sylo.digital"><kbd>🟣 hosted instance</kbd></a>
1212
</p>
1313

1414
# micro
@@ -19,8 +19,6 @@ A vanity file sharing service with support for ShareX. You can see a preview at
1919
- [features](#features)
2020
- [screenshots](#screenshots)
2121
- [installation](#installation)
22-
- [configuration](#configuration)
23-
- [updating](#updating)
2422
- [development](#development)
2523
- [`web` package notes](#web-package-notes)
2624
- [todo](#todo)
@@ -45,6 +43,7 @@ A vanity file sharing service with support for ShareX. You can see a preview at
4543
- [x] Conversions (GIF>WebM, WebP>PNG, etc.)
4644
- [x] Purging of old and/or large files (`config.purge`).
4745
- [x] 2FA support
46+
- [X] Decay files to S3 to save space
4847

4948
## screenshots
5049

@@ -67,37 +66,7 @@ A vanity file sharing service with support for ShareX. You can see a preview at
6766

6867
## installation
6968

70-
> [!NOTE]
71-
> If you need help, join the [discord server](https://discord.gg/VDMX6VQRZm). This guide assumes you are on linux with a basic understanding of linux and docker.
72-
73-
> [!TIP]
74-
> If you are already familiar with docker, you can look at the [compose file](./example/compose.yml) and [config file](./example/.microrc.yaml) to get setup quickly. The below is a more detailed guide for inexperienced users.
75-
76-
1. Install `git` and `docker`
77-
2. Download the files in this repository, `git clone https://github.com/sylv/micro.git`
78-
3. Copy the example configs to the current directory, `cp ./micro/example/* ./`
79-
4. Fill out `.microrc.yaml`, `Caddyfile` and `docker compose.yml`. **It is extremely important you read through each of the 3 files and make sure you understand what they do.** Specifically, `.microrc.yaml` contains a secret that handles authentication, if it is not a secure random string everyone can sign in as anyone they want without a password.
80-
5. Run `docker compose up -d` to start the database and micro.
81-
6. Get the startup invite by doing `docker compose logs micro` and copying the invite URL that should be somewhere towards the end of the log. Go to that URL to create the first account.
82-
83-
Setup is now complete and your instance should be working.
84-
To add another user, sign in then go to `/api/invite` and copy the URL it gives you. This will be improved in the future.
85-
86-
### configuration
87-
88-
micro uses [venera](https://github.com/sylv/venera) to load configuration files. Configuration files are validated on startup, and may log errors if invalid setups are detected. The venera page has more information, but tl;dr:
89-
90-
- `.microrc.yaml` is the main configuration file.
91-
- You can override any config value with an environment variable. The key `hosts.0.url` would be set as `MICRO_HOSTS__0__URL`
92-
- You can use other file formats, like JSON or TOML.
93-
94-
### updating
95-
96-
You should take a full database backup before updating, but you won't, will you?
97-
The database will be automatically migrated on startup.
98-
99-
1. `docker compose pull micro`
100-
2. `docker compose up -d micro`
69+
[See the `example` directory](./example) for how to setup micro.
10170

10271
## development
10372

compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE IS FOR DEVELOPMENT ONLY.
2+
# PERSISTENCE IS NOT ENABLED, `docker compose down` WILL DELETE ALL DATA.
23
# If you want complete examples on how to host micro, see the /examples directory.
3-
# Persistence is not setup for this postgres instance.
44
version: "3"
55
services:
66
postgres:

example/Caddyfile

-6
This file was deleted.

example/README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# example
2+
3+
This directory contains an example deployment for micro.
4+
It uses [docker](https://docker.com) and [cloudflare tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/) to deploy it anywhere.
5+
6+
## usage
7+
8+
> [!NOTE]
9+
> If you need help, join the [discord server](https://discord.gg/VDMX6VQRZm). This guide assumes you are on linux with a basic understanding of linux and docker.
10+
11+
> [!IMPORTANT]
12+
> This guide assumes you have installed docker and cloudflare tunnel. It also assumes you have basic knowledge of them.
13+
> If you are stuck or discover problems with this guide, ask in the [discord server](https://discord.gg/VDMX6VQRZm) or look at other guides for discord/cloudflare tunnel.
14+
15+
1. Clone the example to a local directory
16+
2. Fill out `micro.yaml`, each option is documented in the file. Most importantly, make sure `secret` is changed.
17+
3. Replace the postgresql password in `compose.yaml` with a secure password.
18+
4. Setup the tunnel
19+
1. `docker compose exec tunnel cloudflared tunnel login`
20+
2. `docker compose exec tunnel cloudflared tunnel create micro`
21+
3. You will get a tunnel ID that looks like `168b9890-caa1-44c1-822b-12cf1a5e361e`, copy it and replace `YOUR_TUNNEL_ID` in `tunnel.yaml` with it.
22+
4. Replace the `example.net` domain with your own domain in `tunnel.yaml`.
23+
5. Start micro with `docker compose up -d`
24+
6. Run `docker compose logs micro`, the initial startup will log an invite link. Go to it and setup the first account, which is given admin permissions automatically.
25+
26+
> [!TIP]
27+
> Consider swapping cloudflare tunnel for something else. It's used in this example for convenience as it works behind NATs and firewalls and provides automatic SSL. You might prefer using Caddy, nginx, traefik, or something else in its place.
28+
29+
### configuration
30+
31+
All the configuration options are listed in [the example config](./micro.yaml) file. [venera](https://github.com/sylv/venera) is used to load configs, which are validated at startup and may log errors if an invalid configuration is detected. The venera page has detailed information, but tl;dr:
32+
33+
- `.microrc.yaml` is the main configuration file.
34+
- You can override any config value with an environment variable. The key `hosts.0.url` would be set as `MICRO_HOSTS__0__URL`
35+
- You can use other file formats, like JSON or TOML.
36+
37+
### updating micro
38+
39+
You should take a full database backup before updating, but you won't, will you?
40+
The database will be automatically migrated on startup, all you have to do is run a newer version of micro.
41+
42+
1. `docker compose pull micro`
43+
2. `docker compose up -d micro`
44+
45+
### updating postgresql
46+
47+
Updating postgres is an involved process. Google will have better information. In general, you will want to do something like this:
48+
49+
- Export your database to a `.sql` file, using something like `docker compose exec postgres pg_dump -U postgres -d micro > backup.sql`
50+
- Stop your database
51+
- Rename the database directory to something else, like `mv ./data ./data-old`
52+
- Update `compose.yaml` to point to the new postgres version, for example `postgres:16-alpine` is for v16 of postgres.
53+
- Start the database `docker compose up -d postgres`
54+
- Restore the database using the `.sql` file
55+
- Once it all checks out, you can delete the old database directory if you are confident you won't need it.

example/compose.yml

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
1-
version: '3'
21
services:
32
micro:
43
image: sylver/micro:main
54
restart: unless-stopped
65
volumes:
7-
- $PWD/.microrc.yaml:/usr/src/micro/.microrc.yaml
8-
- $PWD/data:/data
9-
# uncomment this if you dont care about https, then comment out the proxy service
10-
# ports:
11-
# - 80:3000
6+
- ./micro.yaml:/usr/src/micro/micro.yaml
7+
- ./data:/data
8+
129
postgres:
13-
image: postgres:12-alpine
10+
image: postgres:16-alpine
1411
restart: unless-stopped
1512
environment:
16-
# leaving this as default should be fine as postgres will only ever be exposed to services
17-
# in this compose file, but you might still want to consider changing it to something more secure.
18-
- POSTGRES_PASSWORD=youshallnotpass
13+
- POSTGRES_PASSWORD=youshallnotpass # change this!
1914
- POSTGRES_USER=micro
2015
- POSTGRES_DB=micro
2116
volumes:
22-
- $PWD/.pg-data:/var/lib/postgresql/data
23-
# comment this out if you dont care about https, then uncomment the above ports
24-
proxy:
25-
image: caddy:2-alpine
17+
- ./.pg-data:/var/lib/postgresql/data
18+
19+
tunnel:
20+
container_name: tunnel
21+
image: cloudflare/cloudflared:latest
2622
restart: unless-stopped
27-
ports:
28-
- 80:80
29-
- 443:443
23+
command: tunnel run micro
3024
volumes:
31-
- $PWD/.caddy-data:/data
32-
- $PWD/.caddy-config:/config
33-
- $PWD/Caddyfile:/etc/caddy/Caddyfile
25+
- ./.cloudflared:/etc/cloudflared
26+
- ./tunnel.yaml:/etc/cloudflared/config.yml

example/.microrc.yaml renamed to example/micro.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# you can pass in most config options through environment variables,
2-
# for example `DATABASE_URL` will override the databaseUrl in this config file.
2+
# for example `MICRO_DATABASE_URL` will override the databaseUrl in this config file.
33
# remove the .yaml extension or change it to .json to use JSON-with-comments
44
# ref: https://github.com/sylv/venera#sources
55

example/tunnel.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tunnel: YOUR_TUNNEL_ID
2+
3+
ingress:
4+
- hostname: "*.example.net"
5+
service: http://micro:3000
6+
- hostname: "example.net"
7+
service: http://micro:3000
8+
9+
- service: http_status:404

packages/api/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const schema = strictObject({
6868
),
6969
});
7070

71-
const data = loadConfig("micro");
71+
const data = loadConfig("micro", { pathHints: ["micro.yaml"] });
7272
const result = schema.safeParse(data);
7373
if (!result.success) {
7474
console.dir({ data, error: result.error }, { depth: null });

0 commit comments

Comments
 (0)