mirror of
https://github.com/fluxerapp/fluxer.git
synced 2026-11-20 01:01:18 -08:00
build(native): add native dist and image (#4007)
This commit is contained in:
1 parent
6684760d33
commit
44159ac5b3
29 files changed
+1530
-12
No files matched your search
@@ -19,6 +19,7 @@
|
||||
**/_build/
|
||||
**/coverage/
|
||||
**/dist/
|
||||
!/tools/dist/
|
||||
**/node_modules/
|
||||
**/target/
|
||||
**/test-results.json
|
||||
@@ -64,3 +65,5 @@
|
||||
|
||||
**/.DS_Store
|
||||
**/Thumbs.db
|
||||
|
||||
/fluxer_native/fluxerd
|
||||
@@ -20,6 +20,7 @@
|
||||
**/_build/
|
||||
**/coverage/
|
||||
**/dist/
|
||||
!/tools/dist/
|
||||
**/node_modules/
|
||||
**/target/
|
||||
**/test-results.json
|
||||
|
||||
@@ -85,3 +85,8 @@ lto = true
|
||||
opt-level = "z"
|
||||
panic = "abort"
|
||||
strip = true
|
||||
|
||||
[profile.release-fast]
|
||||
inherits = "release"
|
||||
lto = "thin"
|
||||
codegen-units = 16
|
||||
@@ -0,0 +1,37 @@
|
||||
DIST_DIR ?= $(CURDIR)/dist
|
||||
TOOLCHAIN ?= $(DIST_DIR)/toolchain
|
||||
NATIVE ?= $(DIST_DIR)/native
|
||||
PROFILE ?= release
|
||||
ONLY ?=
|
||||
INTO ?=
|
||||
IMAGE ?= fluxer:dev
|
||||
SOURCE ?=
|
||||
DIST ?=
|
||||
|
||||
.PHONY: toolchain native-deps dist image clean-build
|
||||
|
||||
toolchain:
|
||||
tools/dist/toolchain.sh '$(TOOLCHAIN)'
|
||||
|
||||
native-deps:
|
||||
@if [ "$$(id -u)" = 0 ]; then echo "run make native-deps as a normal user, install-native-deps.sh registers its prefix system-wide when run as root" >&2; exit 1; fi
|
||||
fluxer_media_proxy/tools/install-native-deps.sh '$(NATIVE)'
|
||||
|
||||
dist:
|
||||
FLUXER_TOOLCHAIN='$(TOOLCHAIN)' FLUXER_NATIVE_PREFIX='$(NATIVE)' PROFILE='$(PROFILE)' \
|
||||
tools/dist/build.sh $(if $(ONLY),--only '$(ONLY)') $(if $(INTO),--into '$(INTO)') '$(DIST_DIR)'
|
||||
|
||||
image:
|
||||
docker build -f packaging/monolith/Dockerfile -t '$(IMAGE)' --build-arg PROFILE='$(PROFILE)' \
|
||||
$(if $(SOURCE),--build-arg SOURCE='$(SOURCE)') \
|
||||
$(if $(filter fromdist,$(SOURCE)),--build-context dist='$(DIST_DIR)') \
|
||||
$(if $(DIST),--build-arg DIST='$(DIST)') \
|
||||
$(if $(BUILD_VERSION),--build-arg BUILD_VERSION='$(BUILD_VERSION)') \
|
||||
$(if $(CARGO_BUILD_JOBS),--build-arg CARGO_BUILD_JOBS='$(CARGO_BUILD_JOBS)') \
|
||||
.
|
||||
|
||||
clean-build:
|
||||
find '$(CURDIR)' \( -path '$(CURDIR)/.git' -o -path '$(DIST_DIR)' -o -path '$(TOOLCHAIN)' -o -path '$(NATIVE)' \) -prune \
|
||||
-o \( -name target -o -name node_modules \) -type d -prune -exec rm -rf {} +
|
||||
rm -rf fluxer_gateway/_build fluxer_gateway/priv fluxer_app/dist fluxer_api/dist
|
||||
if [ -n "$${PNPM_STORE_DIR:-}" ]; then rm -rf "$$PNPM_STORE_DIR"; fi
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import {request} from 'node:http';
|
||||
|
||||
const SOCKET_PATH = process.env.FLUXER_OPERATOR_SOCKET ?? '/run/fluxer/operator.sock';
|
||||
const SOCKET_PATH = process.env.FLUXER_OPERATOR_SOCKET || '/run/fluxer/operator.sock';
|
||||
const HOST_USER_HEADER = 'X-Fluxer-Operator-Host-User';
|
||||
const SCHEMA_MAJOR = 1;
|
||||
const TIMEOUT_MS = 120_000;
|
||||
|
||||
@@ -367,6 +367,7 @@ export function buildAPIConfigFromMaster(master: MasterConfig): APIConfig {
|
||||
return {
|
||||
nodeEnv: master.env === 'test' ? 'development' : master.env,
|
||||
port: master.services.api.port,
|
||||
host: master.services.api.host,
|
||||
headersTimeoutMs: master.services.api.headers_timeout_ms,
|
||||
requestTimeoutMs: master.services.api.request_timeout_ms,
|
||||
maxInflightRequests: master.services.api.max_inflight_requests,
|
||||
@@ -721,6 +722,7 @@ export function buildAPIConfigFromMaster(master: MasterConfig): APIConfig {
|
||||
|
||||
interface APIServerOptions {
|
||||
port: number;
|
||||
hostname?: string;
|
||||
headersTimeoutMs: number;
|
||||
requestTimeoutMs: number;
|
||||
}
|
||||
@@ -728,6 +730,7 @@ interface APIServerOptions {
|
||||
export function buildAPIServerOptions(config: APIConfig): APIServerOptions {
|
||||
return {
|
||||
port: config.port,
|
||||
hostname: config.host,
|
||||
headersTimeoutMs: config.headersTimeoutMs,
|
||||
requestTimeoutMs: config.requestTimeoutMs,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import {stripApiPrefix} from '@app/api/utils/RequestPathUtils';
|
||||
|
||||
export const OPERATOR_SOCKET_PATH = '/run/fluxer/operator.sock';
|
||||
export const OPERATOR_SOCKET_PATH = process.env.FLUXER_OPERATOR_SOCKET || '/run/fluxer/operator.sock';
|
||||
export const OPERATOR_HOST_USER_HEADER = 'X-Fluxer-Operator-Host-User';
|
||||
export const OPERATOR_PEER_ADDRESS = '127.0.0.1';
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ type APIGeoipConfig = APIGeoipFilesystemConfig | APIGeoipS3Config;
|
||||
export interface APIConfig {
|
||||
nodeEnv: 'development' | 'production';
|
||||
port: number;
|
||||
host?: string;
|
||||
headersTimeoutMs: number;
|
||||
requestTimeoutMs: number;
|
||||
maxInflightRequests: number;
|
||||
|
||||
@@ -170,6 +170,7 @@ export default defineConfig({
|
||||
'operator/sign-in',
|
||||
'operator/kubernetes',
|
||||
'operator/docker-compose',
|
||||
'operator/build-from-source',
|
||||
'operator/voice-compose',
|
||||
'operator/environment',
|
||||
'operator/rexctl',
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
---
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
title: Build Fluxer from source
|
||||
description: Build Fluxer yourself and run it as one container or as one systemd service on Debian.
|
||||
sidebar:
|
||||
label: Build from source
|
||||
---
|
||||
|
||||
You can build all of Fluxer from the [repository](https://github.com/fluxerapp/fluxer) into one release tarball. You can run that tarball as a single container, or as one systemd service on Debian 13 or in a Proxmox container. Neither way needs Docker Compose or rexctl.
|
||||
|
||||
## Build the release
|
||||
|
||||
Build on a Debian 13 machine with the same architecture as the machine that will run Fluxer, amd64 or arm64. Run this in your clone of the repository as a normal user who can use sudo.
|
||||
|
||||
```sh
|
||||
make toolchain native-deps dist
|
||||
```
|
||||
|
||||
`make toolchain` installs the build packages with apt and puts the rest of the toolchain in `dist/toolchain`. The build writes `dist/fluxer-<version>-linux-<arch>.tar.zst` and `dist/SHA256SUMS`.
|
||||
|
||||
## Run it as one container
|
||||
|
||||
`make image` builds everything inside Docker and tags the image `fluxer:dev`. Set `IMAGE` to use another tag. If you've already run `make dist`, `make image SOURCE=fromdist` packages that tarball and doesn't build it again.
|
||||
|
||||
With an empty Docker cache, a full build took 11 minutes on an arm64 machine with 27 CPU cores and 47 GB of memory. It used about 15 GB more disk space while it ran. Most of that space is Docker's build cache, and `docker builder prune` deletes it when you're done.
|
||||
|
||||
Start the container with your domain.
|
||||
|
||||
```sh
|
||||
docker run -d --name fluxer --stop-timeout 90 -p 80:80 -p 443:443 -p 443:443/udp \
|
||||
-v fluxer-data:/var/lib/fluxer -e FLUXER_DOMAIN=chat.example.com fluxer:dev
|
||||
```
|
||||
|
||||
The `fluxer-data` volume has all of Fluxer's data and secrets. If you use a folder on the host instead, it must belong to user ID 65532. You can pass any other [setting](/operator/environment/) with more `-e` flags or with `--env-file`.
|
||||
|
||||
The first start creates the secrets and the database and writes the setup token to the log.
|
||||
|
||||
```sh
|
||||
docker logs fluxer 2>&1 | grep "setup token"
|
||||
```
|
||||
|
||||
When the container is healthy, open your domain and enter the setup token to create your admin account. `docker exec fluxer /opt/fluxer/current/bin/fluxerd help` lists the other things the container can do, such as backups.
|
||||
|
||||
## Install on Debian or Proxmox
|
||||
|
||||
The install script needs Debian 13 with systemd. In Proxmox, create an unprivileged container from the Debian 13 template with at least 4 GB of memory. Use a machine or container that runs only Fluxer, because some of Fluxer's internal services on 127.0.0.1 don't ask for a password.
|
||||
|
||||
Copy the tarball, `dist/SHA256SUMS` and `packaging/install.sh` into one folder on the machine or container. Then run the script there as root with your domain.
|
||||
|
||||
```sh
|
||||
FLUXER_DOMAIN=chat.example.com ./install.sh
|
||||
```
|
||||
|
||||
The script installs the packages Fluxer needs, writes every `FLUXER_` variable you set into `/etc/fluxer/fluxer.env` on the first install and starts the `fluxerd` service. When it's done, it prints the setup token and the commands for logs and settings. Open your domain and enter the setup token to create your admin account.
|
||||
|
||||
To upgrade, copy the new tarball, its `SHA256SUMS` and the new `install.sh` into the same folder and run `./install.sh --upgrade` with the new tarball. The script takes a backup first. If the new version doesn't start, it goes back to the old version and restores that backup.
|
||||
|
||||
## What a new install runs
|
||||
|
||||
A new install runs Fluxer's eight Rust services in one process and keeps uploaded files as plain files in `/var/lib/fluxer/objects`. Fluxer's cache, rate limits and queues are in its Postgres database, and Valkey and SeaweedFS don't run. The first start writes these choices to `/var/lib/fluxer/modes.env`, and later starts and upgrades use them.
|
||||
|
||||
To run the Rust services one process each, set `FLUXER_RUST_PROCESS=per-service`. To keep uploads in SeaweedFS, set `FLUXER_STORAGE_BACKEND=s3`, and for Valkey, set `FLUXER_KV_MODE=standalone`. Set them before the first start. If you set `FLUXER_S3_ENDPOINT` or `FLUXER_KV_URL`, Fluxer uses that object store or that Valkey server from the first start.
|
||||
|
||||
When you restore a backup of an instance that used SeaweedFS or Valkey, Fluxer keeps using them. You can change `FLUXER_RUST_PROCESS` at any time. Fluxer doesn't start with `FLUXER_STORAGE_BACKEND=filesystem` while SeaweedFS still has files, or with `FLUXER_KV_MODE=postgres` while Valkey still has data.
|
||||
|
||||
## Ports
|
||||
|
||||
Open TCP ports 80 and 443 and UDP port 443 to the machine or container. On a home network, forward them from your router to its address.
|
||||
|
||||
Voice and video are off in both of these setups. To turn them on, set `FLUXER_LIVEKIT_ENABLED=true` and also open TCP port 7881 and UDP port 7882. For the container, add `-p 7881:7881 -p 7882:7882/udp` to `docker run`. LiveKit looks up the public address of the machine through STUN and tells apps to connect there. If people connect to another address, such as the address of the machine on your home network, set `FLUXER_LIVEKIT_NODE_IP` to that address and Fluxer skips the STUN lookup.
|
||||
@@ -2062,7 +2062,7 @@ The Rust services the one Rust process runs, separated by commas.
|
||||
|
||||
### `FLUXER_SNOWFLAKES_WORKER_GUARD`
|
||||
|
||||
Whether the snowflakes service refuses to start while another snowflakes service with the same worker id answers on NATS. The guard waits up to one second for an answer and refuses only when another running snowflakes service answers, so a second snowflakes service started by hand can't hand out the same IDs. The Docker Compose stack sets it to `true` for the snowflakes service, including the one inside the single Rust process. The Helm chart leaves it unset and the guard off, because a rolling update can briefly run two pods with the same worker id. Docker Compose sets it to `true`.
|
||||
Whether the snowflakes service refuses to start while another snowflakes service with the same worker id answers on NATS. The guard waits up to one second for an answer and refuses only when another running snowflakes service answers, so a second snowflakes service started by hand can't hand out the same IDs. fluxerd sets it to `true` for every snowflakes service, including the one inside the single Rust process. The Helm chart leaves it unset and the guard off, because a rolling update can briefly run two pods with the same worker id. Docker Compose sets it to `true`.
|
||||
|
||||
### `UV_THREADPOOL_SIZE`
|
||||
|
||||
@@ -2244,6 +2244,10 @@ The OAuth2 redirect URL of the admin panel. The admin service works it out from
|
||||
|
||||
The single sign-on redirect URL of the admin panel. The admin service works it out from its own address.
|
||||
|
||||
### `FLUXER_API_HOST`
|
||||
|
||||
The address the api service listens on. When it's empty, it listens on every interface.
|
||||
|
||||
### `FLUXER_API_WORKER_LANE`
|
||||
|
||||
The job lane a worker runs when `FLUXER_API_WORKER_MODE` is `single_lane`. Each worker container in the stack runs every lane.
|
||||
@@ -2272,6 +2276,10 @@ A file that has the gateway's Erlang cookie. The stack passes `FLUXER_ERLANG_COO
|
||||
|
||||
The URL the gateway sends API RPC requests to. When it's empty, the gateway uses `FLUXER_INTERNAL_API_ENDPOINT` followed by `/internal/rpc`.
|
||||
|
||||
### `FLUXER_GATEWAY_BIND_HOST`
|
||||
|
||||
The IP address the gateway listens on. When it's empty, it listens on every interface.
|
||||
|
||||
### `FLUXER_GATEWAY_NATS_RPC_ENABLED`
|
||||
|
||||
Whether the gateway responds to RPC requests over NATS. The gateway responds to the API only over NATS RPC and must keep it turned on.
|
||||
@@ -2292,6 +2300,10 @@ The directory the media proxy keeps files in when it stores them on disk. The st
|
||||
|
||||
The older name for `FLUXER_NATS_URL`, which only the api and worker read. Docker Compose passes `FLUXER_NATS_URL`.
|
||||
|
||||
### `FLUXER_OPERATOR_SOCKET`
|
||||
|
||||
The socket path the api listens on for operator requests and the operator relay connects to. When it's empty, both use `/run/fluxer/operator.sock`.
|
||||
|
||||
### `FLUXER_PUSH_SERVICE_HOST`
|
||||
|
||||
The address the push service listens on. When it's empty, it listens on `0.0.0.0`.
|
||||
@@ -2828,10 +2840,6 @@ Only tests and development use these.
|
||||
|
||||
Whether rate limits are off.
|
||||
|
||||
#### `FLUXER_OPERATOR_SOCKET`
|
||||
|
||||
The socket path the operator relay connects to. The api listens on `/run/fluxer/operator.sock`.
|
||||
|
||||
#### `FLUXER_RELAX_REGISTRATION_RATE_LIMITS`
|
||||
|
||||
Whether registration rate limits are relaxed.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
% SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
[
|
||||
{kernel, [
|
||||
{logger_level, warning},
|
||||
{logger, [
|
||||
{handler, default, logger_std_h, #{
|
||||
formatter =>
|
||||
{logger_formatter, #{
|
||||
single_line => true,
|
||||
chars_limit => 16384,
|
||||
max_size => 16384,
|
||||
depth => 30
|
||||
}}
|
||||
}}
|
||||
]}
|
||||
]},
|
||||
{sasl, [
|
||||
{errlog_type, error}
|
||||
]},
|
||||
{inet, [
|
||||
{lookup, [native, file, dns]}
|
||||
]}
|
||||
].
|
||||
@@ -0,0 +1,24 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-sname fluxer_gateway@localhost
|
||||
-setcookie fluxer_gateway_native
|
||||
-start_epmd false
|
||||
-dist_listen false
|
||||
+A1
|
||||
+P 262144
|
||||
+Q 65536
|
||||
+S ${FLUXER_ERLANG_SCHEDULERS:-2}:${FLUXER_ERLANG_SCHEDULERS:-2}
|
||||
+SDcpu ${FLUXER_ERLANG_DIRTY_CPU_SCHEDULERS:-1}:${FLUXER_ERLANG_DIRTY_CPU_SCHEDULERS:-1}
|
||||
+SDio ${FLUXER_ERLANG_DIRTY_IO_SCHEDULERS:-2}
|
||||
+sbwt none
|
||||
+sbwtdcpu none
|
||||
+sbwtdio none
|
||||
+zdbbl 32768
|
||||
+MBacul 0
|
||||
+MBramv true
|
||||
+MHas ageffcbf
|
||||
+MBas ageffcbf
|
||||
+MEas ageffcbf
|
||||
+MHlmbcs 512
|
||||
+MBlmbcs 512
|
||||
+MElmbcs 512
|
||||
-kernel logger_level warning
|
||||
@@ -45,7 +45,13 @@
|
||||
{prod, [
|
||||
{relx, [
|
||||
{dev_mode, false},
|
||||
{include_erts, true}
|
||||
{include_erts, true},
|
||||
{overlay, [
|
||||
{copy, "config/vm.args.native",
|
||||
"releases/{{release_version}}/vm.args.native.src"},
|
||||
{copy, "config/sys.config.native",
|
||||
"releases/{{release_version}}/sys.native.config"}
|
||||
]}
|
||||
]}
|
||||
]}
|
||||
]}.
|
||||
|
||||
@@ -41,7 +41,7 @@ start_cowboy() ->
|
||||
cowboy:start_clear(
|
||||
http,
|
||||
#{
|
||||
socket_opts => [{port, Port}],
|
||||
socket_opts => bind_opts(fluxer_gateway_env:get(bind_ip)) ++ [{port, Port}],
|
||||
max_connections => infinity
|
||||
},
|
||||
#{
|
||||
@@ -55,6 +55,10 @@ start_cowboy() ->
|
||||
{error, E} -> {error, E}
|
||||
end.
|
||||
|
||||
-spec bind_opts(inet:ip_address() | undefined) -> [{ip, inet:ip_address()}].
|
||||
bind_opts(undefined) -> [];
|
||||
bind_opts(Ip) -> [{ip, Ip}].
|
||||
|
||||
-spec prep_stop(term()) -> term().
|
||||
prep_stop(State) ->
|
||||
ok = gateway_shutdown_drain:run(),
|
||||
|
||||
@@ -104,6 +104,7 @@ env_gateway_config() ->
|
||||
env_gateway_base_config() ->
|
||||
#{
|
||||
<<"port">> => env_int("FLUXER_GATEWAY_PORT", 8771),
|
||||
<<"bind_host">> => env_optional_binary("FLUXER_GATEWAY_BIND_HOST"),
|
||||
<<"gateway_role">> => env_optional_binary("FLUXER_GATEWAY_ROLE"),
|
||||
<<"rpc_auth_token">> => env_binary("FLUXER_GATEWAY_RPC_AUTH_TOKEN", <<>>),
|
||||
<<"push_enabled">> => env_bool("FLUXER_GATEWAY_PUSH_ENABLED", true),
|
||||
@@ -195,6 +196,7 @@ build_config(RawConfig) ->
|
||||
build_core_config(Service, Internal, Nats, Proxy) ->
|
||||
#{
|
||||
port => get_int(Service, <<"port">>, 8080),
|
||||
bind_ip => parse_bind_ip(get_optional_binary(Service, <<"bind_host">>)),
|
||||
gateway_role => normalize_gateway_role(get_value(Service, <<"gateway_role">>)),
|
||||
client_ip_header => get_binary(Proxy, <<"client_ip_header">>, <<"x-forwarded-for">>),
|
||||
trust_client_ip_header => get_bool(Proxy, <<"trust_client_ip_header">>, false),
|
||||
@@ -207,6 +209,15 @@ build_core_config(Service, Internal, Nats, Proxy) ->
|
||||
get_int(Service, <<"gateway_nats_rpc_max_handlers">>, 512)
|
||||
}.
|
||||
|
||||
-spec parse_bind_ip(binary() | undefined) -> inet:ip_address() | undefined.
|
||||
parse_bind_ip(undefined) ->
|
||||
undefined;
|
||||
parse_bind_ip(Host) ->
|
||||
case inet:parse_address(string:trim(binary_to_list(Host))) of
|
||||
{ok, Ip} -> Ip;
|
||||
{error, einval} -> erlang:error({invalid_gateway_bind_host, Host})
|
||||
end.
|
||||
|
||||
-spec build_push_config(map(), map(), map()) -> config().
|
||||
build_push_config(Service, Public, Instance) ->
|
||||
#{
|
||||
|
||||
@@ -27,7 +27,7 @@ func otherInstance(l spec.Layout, specs []spec.Child) error {
|
||||
}
|
||||
if c, err := net.DialTimeout("unix", sock, time.Second); err == nil {
|
||||
c.Close()
|
||||
return fmt.Errorf("%w: the fluxerd behind %s answers. Stop it first", errOtherInstance, sock)
|
||||
return fmt.Errorf("%w: the fluxerd behind %s answers. Stop it first, with systemctl stop fluxerd for an install.sh install", errOtherInstance, sock)
|
||||
}
|
||||
}
|
||||
ports := []int{spec.PortNATS}
|
||||
|
||||
@@ -515,7 +515,7 @@ var envVars = []envVar{
|
||||
{"FLUXER_DATABASE_BACKEND", "stack", "The database the services use."},
|
||||
{"FLUXER_ADMIN_UPSTREAM", "stack", "The address the edge sends admin panel requests to, which changes when FLUXER_RUST_PROCESS is `single`."},
|
||||
{"FLUXER_SERVER_SERVICES", "stack", "The Rust services the one Rust process runs, separated by commas."},
|
||||
{"FLUXER_SNOWFLAKES_WORKER_GUARD", "stack", "Whether the snowflakes service refuses to start while another snowflakes service with the same worker id answers on NATS. The guard waits up to one second for an answer and refuses only when another running snowflakes service answers, so a second snowflakes service started by hand can't hand out the same IDs. The Docker Compose stack sets it to `true` for the snowflakes service, including the one inside the single Rust process. The Helm chart leaves it unset and the guard off, because a rolling update can briefly run two pods with the same worker id."},
|
||||
{"FLUXER_SNOWFLAKES_WORKER_GUARD", "stack", "Whether the snowflakes service refuses to start while another snowflakes service with the same worker id answers on NATS. The guard waits up to one second for an answer and refuses only when another running snowflakes service answers, so a second snowflakes service started by hand can't hand out the same IDs. fluxerd sets it to `true` for every snowflakes service, including the one inside the single Rust process. The Helm chart leaves it unset and the guard off, because a rolling update can briefly run two pods with the same worker id."},
|
||||
{"UV_THREADPOOL_SIZE", "stack", "The size of the libuv thread pool in the api and worker, which file reads and writes use when FLUXER_STORAGE_BACKEND is `filesystem`."},
|
||||
{"FLUXER_EDGE_TLS_DIRECTIVE", "stack", "The tls line of the edge Caddyfile, set from FLUXER_EDGE_TLS."},
|
||||
{"FLUXER_ENV", "stack", "The environment the services run in."},
|
||||
@@ -564,6 +564,7 @@ var envVars = []envVar{
|
||||
{"FLUXER_ADMIN_OAUTH_REDIRECT_URI", "internal", "The OAuth2 redirect URL of the admin panel. The admin service works it out from its own address."},
|
||||
{"FLUXER_ADMIN_SSO_REDIRECT_URI", "internal", "The single sign-on redirect URL of the admin panel. The admin service works it out from its own address."},
|
||||
{"FLUXER_API_AUTOMATED_MESSAGE_DELETION_DELAY_DAYS", "hosted", "The delay before automated account actions delete messages, in days."},
|
||||
{"FLUXER_API_HOST", "internal", "The address the api service listens on. When it's empty, it listens on every interface."},
|
||||
{"FLUXER_API_WORKER_LANE", "internal", "The job lane a worker runs when FLUXER_API_WORKER_MODE is `single_lane`. Each worker container in the stack runs every lane."},
|
||||
{"FLUXER_API_WORKER_METRICS_PORT", "internal", "The port the worker serves its metrics on. The stack doesn't collect worker metrics."},
|
||||
{"FLUXER_API_WORKER_TASK", "internal", "The one task a worker runs when FLUXER_API_WORKER_MODE is `single_task`. Each worker container in the stack runs every lane."},
|
||||
@@ -592,6 +593,7 @@ var envVars = []envVar{
|
||||
{"FLUXER_ERLANG_NODE_NAME", "cluster", "The Erlang node name of the gateway."},
|
||||
{"FLUXER_ERLANG_NODE_NAME_PREFIX", "cluster", "A prefix that gives each gateway node a unique Erlang node name."},
|
||||
{"FLUXER_GATEWAY_API_RPC_ENDPOINT", "internal", "The URL the gateway sends API RPC requests to. When it's empty, the gateway uses FLUXER_INTERNAL_API_ENDPOINT followed by `/internal/rpc`."},
|
||||
{"FLUXER_GATEWAY_BIND_HOST", "internal", "The IP address the gateway listens on. When it's empty, it listens on every interface."},
|
||||
{"FLUXER_GATEWAY_CLUSTER_DISCOVERY_DNS_NAME", "cluster", "The DNS name gateway nodes find each other through."},
|
||||
{"FLUXER_GATEWAY_CLUSTER_DISCOVERY_NODE_BASENAME", "cluster", "The node name gateway nodes use when they find each other through DNS."},
|
||||
{"FLUXER_GATEWAY_CLUSTER_DISCOVERY_POLL_INTERVAL_MS", "cluster", "How often gateway nodes look for each other, in milliseconds."},
|
||||
@@ -618,7 +620,7 @@ var envVars = []envVar{
|
||||
{"FLUXER_MEDIA_PROXY_HOST", "internal", "The address the media proxy listens on. When it's empty, it listens on `0.0.0.0`."},
|
||||
{"FLUXER_MEDIA_PROXY_STORAGE_ROOT", "internal", "The directory the media proxy keeps files in when it stores them on disk. The stack keeps media in the object store."},
|
||||
{"FLUXER_NATS_CORE_URL", "internal", "The older name for FLUXER_NATS_URL, which only the api and worker read. Docker Compose passes FLUXER_NATS_URL."},
|
||||
{"FLUXER_OPERATOR_SOCKET", "dev", "The socket path the operator relay connects to. The api listens on /run/fluxer/operator.sock."},
|
||||
{"FLUXER_OPERATOR_SOCKET", "internal", "The socket path the api listens on for operator requests and the operator relay connects to. When it's empty, both use /run/fluxer/operator.sock."},
|
||||
{"FLUXER_PAYMENT_DISPUTE_CLOSURE_EFFECTIVE_AT", "hosted", "When account closures for payment disputes take effect."},
|
||||
{"FLUXER_PUSH_RELAY_MAX_BODY_BYTES", "relay", "The largest request the push relay accepts, in bytes."},
|
||||
{"FLUXER_PUSH_RELAY_MAX_CONCURRENT", "relay", "How many requests the push relay handles at once."},
|
||||
|
||||
@@ -121,6 +121,7 @@ export interface MasterConfig {
|
||||
services: {
|
||||
api: {
|
||||
port: number;
|
||||
host?: string;
|
||||
headers_timeout_ms: number;
|
||||
request_timeout_ms: number;
|
||||
max_inflight_requests: number;
|
||||
|
||||
@@ -75,6 +75,7 @@ const NAMED_FLUXER_ENV_OVERRIDES: Record<string, NamedEnvOverride> = {
|
||||
FLUXER_NATS_JETSTREAM_URL: {path: ['services', 'nats', 'jetstream_url']},
|
||||
FLUXER_NATS_AUTH_TOKEN: {path: ['services', 'nats', 'auth_token']},
|
||||
FLUXER_API_PORT: {path: ['services', 'api', 'port'], parse: parseInteger},
|
||||
FLUXER_API_HOST: {path: ['services', 'api', 'host']},
|
||||
FLUXER_API_HEADERS_TIMEOUT_MS: {path: ['services', 'api', 'headers_timeout_ms'], parse: parseInteger},
|
||||
FLUXER_API_REQUEST_TIMEOUT_MS: {path: ['services', 'api', 'request_timeout_ms'], parse: parseInteger},
|
||||
FLUXER_API_MAX_INFLIGHT_REQUESTS: {path: ['services', 'api', 'max_inflight_requests'], parse: parseInteger},
|
||||
|
||||
Executable
+399
@@ -0,0 +1,399 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
set -euo pipefail
|
||||
|
||||
PREFIX=/opt/fluxer
|
||||
RELEASES="$PREFIX/releases"
|
||||
CURRENT="$PREFIX/current"
|
||||
CONFIG_DIR=/etc/fluxer
|
||||
ENV_FILE="$CONFIG_DIR/fluxer.env"
|
||||
DATA_DIR=/var/lib/fluxer
|
||||
UPGRADE_BACKUPS="$DATA_DIR/backups/pre-upgrade"
|
||||
UNIT=fluxerd.service
|
||||
UNIT_PATH="/etc/systemd/system/$UNIT"
|
||||
DROPIN_DIR="/etc/systemd/system/$UNIT.d"
|
||||
KEEP_RELEASES=3
|
||||
KEEP_BACKUPS=3
|
||||
CONTROL_VARS=(FLUXER_TARBALL)
|
||||
PACKAGE_LIST=share/runtime-packages
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ARCH=""
|
||||
|
||||
log() { printf '==> %s\n' "$*" >&2; }
|
||||
warn() { printf 'install.sh: warning: %s\n' "$*" >&2; }
|
||||
die() {
|
||||
printf 'install.sh: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: install.sh [TARBALL]
|
||||
install.sh --upgrade TARBALL
|
||||
|
||||
Installs Fluxer from fluxer-<version>-linux-<arch>.tar.zst into $RELEASES/<version>
|
||||
and runs it as $UNIT. Without TARBALL, FLUXER_TARBALL or the single matching
|
||||
tarball next to this script is used.
|
||||
|
||||
A new install writes every FLUXER_* variable from the environment into $ENV_FILE.
|
||||
FLUXER_DOMAIN is required then. An existing $ENV_FILE is never changed.
|
||||
|
||||
Fluxer's internal services listen on 127.0.0.1, and some of them don't ask
|
||||
for a password. Install it on a machine or container where every local account
|
||||
is trusted.
|
||||
EOF
|
||||
}
|
||||
|
||||
as_fluxer() {
|
||||
(cd / && runuser -u fluxer -- env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
|
||||
HOME="$DATA_DIR" LANG=C.UTF-8 FLUXER_DATA_DIR="$DATA_DIR" "$@")
|
||||
}
|
||||
|
||||
check_host() {
|
||||
[ "$(id -u)" = 0 ] || die "run this as root"
|
||||
[ -r /etc/os-release ] || die "/etc/os-release is missing, Debian 13 (trixie) is required"
|
||||
local codename
|
||||
codename="$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release | tr -d '"')"
|
||||
[ "$codename" = trixie ] || die "Debian 13 (trixie) is required, this host is '${codename:-unknown}'"
|
||||
[ -d /run/systemd/system ] || die "systemd must be running as init"
|
||||
ARCH="$(dpkg --print-architecture)"
|
||||
case "$ARCH" in
|
||||
amd64 | arm64) ;;
|
||||
*) die "unsupported architecture $ARCH, only amd64 and arm64 are built" ;;
|
||||
esac
|
||||
if [ -n "${FLUXER_DATA_DIR:-}" ] && [ "$FLUXER_DATA_DIR" != "$DATA_DIR" ]; then
|
||||
die "FLUXER_DATA_DIR must be $DATA_DIR, $UNIT only allows writes there"
|
||||
fi
|
||||
[ ! -e "$PREFIX/.rexctl" ] || die "$PREFIX holds a Fluxer instance managed by rexctl, use rexctl for it"
|
||||
check_other_instance
|
||||
}
|
||||
|
||||
check_other_instance() {
|
||||
local port
|
||||
systemctl is-active --quiet "$UNIT" && return 0
|
||||
for port in 14222 15432; do
|
||||
if (exec 3<>"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then
|
||||
die "127.0.0.1:$port is in use, so another Fluxer instance or another program runs on this machine, stop it first"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
resolve_tarball() {
|
||||
local given="$1"
|
||||
if [ -z "$given" ]; then
|
||||
local found=()
|
||||
shopt -s nullglob
|
||||
found=("$SCRIPT_DIR"/fluxer-*-linux-"$ARCH".tar.zst)
|
||||
shopt -u nullglob
|
||||
[ "${#found[@]}" -eq 1 ] || die "pass the release tarball, found ${#found[@]} candidates next to $0"
|
||||
given="${found[0]}"
|
||||
fi
|
||||
[ -f "$given" ] || die "$given does not exist"
|
||||
printf '%s/%s\n' "$(cd "$(dirname "$given")" && pwd)" "$(basename "$given")"
|
||||
}
|
||||
|
||||
tarball_version() {
|
||||
local name
|
||||
name="$(basename "$1")"
|
||||
[[ "$name" =~ ^fluxer-([0-9A-Za-z][0-9A-Za-z._+~-]*)-linux-(amd64|arm64)\.tar\.zst$ ]] \
|
||||
|| die "$name does not match fluxer-<version>-linux-<arch>.tar.zst"
|
||||
[ "${BASH_REMATCH[2]}" = "$ARCH" ] || die "$name is built for ${BASH_REMATCH[2]}, this host is $ARCH"
|
||||
printf '%s\n' "${BASH_REMATCH[1]}"
|
||||
}
|
||||
|
||||
verify_tarball() {
|
||||
local tarball="$1" dir name sums line
|
||||
dir="$(dirname "$tarball")"
|
||||
name="$(basename "$tarball")"
|
||||
sums="$dir/SHA256SUMS"
|
||||
if [ ! -f "$sums" ]; then
|
||||
warn "no SHA256SUMS next to $name, skipping the checksum check"
|
||||
return
|
||||
fi
|
||||
line="$(awk -v n="$name" '$1 ~ /^[0-9a-f]{64}$/ && ($2 == n || $2 == "*" n)' "$sums")"
|
||||
[ -n "$line" ] || die "$sums has no entry for $name"
|
||||
(cd "$dir" && printf '%s\n' "$line" | sha256sum --check --quiet -) || die "checksum mismatch for $name"
|
||||
}
|
||||
|
||||
current_version() {
|
||||
[ -L "$CURRENT" ] || return 0
|
||||
basename "$(readlink "$CURRENT")"
|
||||
}
|
||||
|
||||
install_bootstrap() {
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
log "installing the packages that unpack the release"
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends zstd postgresql-common
|
||||
sed -ri 's/^#?[[:space:]]*create_main_cluster[[:space:]]*=.*/create_main_cluster = false/' \
|
||||
/etc/postgresql-common/createcluster.conf
|
||||
grep -q '^create_main_cluster = false$' /etc/postgresql-common/createcluster.conf \
|
||||
|| die "could not set create_main_cluster = false in /etc/postgresql-common/createcluster.conf"
|
||||
}
|
||||
|
||||
install_packages() {
|
||||
local list="$1/$PACKAGE_LIST" packages=()
|
||||
[ -f "$list" ] || die "$1 has no $PACKAGE_LIST"
|
||||
mapfile -t packages < <(grep -v '^[[:space:]]*$' "$list")
|
||||
log "installing runtime packages: ${packages[*]}"
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "${packages[@]}"
|
||||
if [ -z "$(pg_lsclusters -h 2>/dev/null)" ]; then
|
||||
systemctl disable --now postgresql.service >/dev/null 2>&1 || true
|
||||
else
|
||||
warn "existing PostgreSQL clusters were found and left running, Fluxer runs its own on 127.0.0.1:15432"
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_user() {
|
||||
getent group fluxer >/dev/null || groupadd --system fluxer
|
||||
getent passwd fluxer >/dev/null \
|
||||
|| useradd --system --gid fluxer --home-dir "$DATA_DIR" --no-create-home --shell /usr/sbin/nologin fluxer
|
||||
}
|
||||
|
||||
ensure_dirs() {
|
||||
install -d -m 0755 "$PREFIX" "$RELEASES"
|
||||
install -d -o root -g fluxer -m 0750 "$CONFIG_DIR" "$CONFIG_DIR/caddy.d" "$CONFIG_DIR/caddy.d/sites" "$CONFIG_DIR/certs"
|
||||
install -d -o fluxer -g fluxer -m 0750 "$DATA_DIR"
|
||||
}
|
||||
|
||||
unpack_release() {
|
||||
local tarball="$1" version="$2" dest="$RELEASES/$2" tmp root entries
|
||||
if [ -d "$dest" ]; then
|
||||
[ -x "$dest/bin/fluxerd" ] || die "$dest exists without bin/fluxerd, remove it and run again"
|
||||
log "release $version is already unpacked"
|
||||
return
|
||||
fi
|
||||
rm -rf "$RELEASES"/.unpack-*
|
||||
log "unpacking $version into $dest"
|
||||
tmp="$(mktemp -d "$RELEASES/.unpack-XXXXXX")"
|
||||
tar --zstd -xf "$tarball" -C "$tmp" --no-same-owner
|
||||
root="$tmp"
|
||||
if [ ! -e "$tmp/bin" ]; then
|
||||
entries=("$tmp"/*)
|
||||
if [ "${#entries[@]}" -eq 1 ] && [ -d "${entries[0]}" ]; then
|
||||
root="${entries[0]}"
|
||||
fi
|
||||
fi
|
||||
[ -x "$root/bin/fluxerd" ] || die "$(basename "$tarball") has no bin/fluxerd"
|
||||
chown -R root:root "$root"
|
||||
chmod -R go-w "$root"
|
||||
chmod 0755 "$root"
|
||||
mv "$root" "$dest"
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
flip_current() {
|
||||
ln -sfn "releases/$1" "$PREFIX/.current.new"
|
||||
mv -Tf "$PREFIX/.current.new" "$CURRENT"
|
||||
touch "$RELEASES/$1"
|
||||
log "$CURRENT now points to releases/$1"
|
||||
}
|
||||
|
||||
write_env_file() {
|
||||
local names name value given=()
|
||||
mapfile -t names < <(compgen -e | grep '^FLUXER_' | sort)
|
||||
for name in "${names[@]}"; do
|
||||
[[ " ${CONTROL_VARS[*]} " == *" $name "* ]] || given+=("$name")
|
||||
done
|
||||
if [ -e "$ENV_FILE" ]; then
|
||||
log "keeping the existing $ENV_FILE"
|
||||
[ "${#given[@]}" -eq 0 ] || warn "not applied from the environment: ${given[*]}, edit $ENV_FILE instead"
|
||||
return
|
||||
fi
|
||||
[ -n "${FLUXER_DOMAIN:-}" ] || die "FLUXER_DOMAIN is required for a new install"
|
||||
local tmp
|
||||
tmp="$(mktemp "$CONFIG_DIR/.fluxer.env.XXXXXX")"
|
||||
for name in "${given[@]}"; do
|
||||
value="${!name}"
|
||||
[[ "$value" != *$'\n'* ]] || die "$name contains a newline"
|
||||
printf '%s=%s\n' "$name" "$value" >>"$tmp"
|
||||
done
|
||||
chown root:fluxer "$tmp"
|
||||
chmod 0640 "$tmp"
|
||||
mv "$tmp" "$ENV_FILE"
|
||||
log "wrote $ENV_FILE"
|
||||
}
|
||||
|
||||
install_unit() {
|
||||
local src="$1/share/systemd/$UNIT"
|
||||
[ -f "$src" ] || src="$SCRIPT_DIR/systemd/$UNIT"
|
||||
[ -f "$src" ] || die "no $UNIT in $1/share/systemd or $SCRIPT_DIR/systemd"
|
||||
if cmp -s "$src" "$UNIT_PATH"; then
|
||||
return 1
|
||||
fi
|
||||
install -m 0644 "$src" "$UNIT_PATH"
|
||||
systemctl daemon-reload
|
||||
log "installed $UNIT_PATH"
|
||||
}
|
||||
|
||||
start_unit() {
|
||||
local verb="$1"
|
||||
log "running systemctl $verb $UNIT, this waits until every service is ready"
|
||||
systemctl reset-failed "$UNIT" 2>/dev/null || true
|
||||
if systemctl "$verb" "$UNIT"; then
|
||||
return 0
|
||||
fi
|
||||
if [ "$(systemctl show -p ExecMainStatus --value "$UNIT")" = 226 ] && [ ! -e "$DROPIN_DIR/no-namespaces.conf" ]; then
|
||||
warn "$UNIT could not set up its mount namespace (status 226), which happens in LXC containers without nesting"
|
||||
warn "turning off PrivateTmp and ProtectSystem in $DROPIN_DIR/no-namespaces.conf and trying again"
|
||||
install -d -m 0755 "$DROPIN_DIR"
|
||||
printf '[Service]\nPrivateTmp=no\nProtectSystem=no\nReadWritePaths=\n' >"$DROPIN_DIR/no-namespaces.conf"
|
||||
systemctl daemon-reload
|
||||
systemctl reset-failed "$UNIT"
|
||||
systemctl "$verb" "$UNIT" && return 0
|
||||
warn "that did not help, removing $DROPIN_DIR/no-namespaces.conf again"
|
||||
rm -f "$DROPIN_DIR/no-namespaces.conf"
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
newest_backup() {
|
||||
find "$UPGRADE_BACKUPS" -mindepth 1 -maxdepth 1 -newer "$1" -printf '%T@ %p\n' 2>/dev/null \
|
||||
| sort -rn | head -n 1 | cut -d' ' -f2-
|
||||
}
|
||||
|
||||
prune_releases() {
|
||||
local current n=0 dir
|
||||
current="$(current_version)"
|
||||
while IFS= read -r dir; do
|
||||
n=$((n + 1))
|
||||
if [ "$n" -le "$KEEP_RELEASES" ] || [ "$(basename "$dir")" = "$current" ]; then
|
||||
continue
|
||||
fi
|
||||
log "removing old release $(basename "$dir")"
|
||||
rm -rf "$dir"
|
||||
done < <(find "$RELEASES" -mindepth 1 -maxdepth 1 -type d ! -name '.*' -printf '%T@ %p\n' | sort -rn | cut -d' ' -f2-)
|
||||
}
|
||||
|
||||
prune_backups() {
|
||||
local n=0 file
|
||||
while IFS= read -r file; do
|
||||
n=$((n + 1))
|
||||
[ "$n" -gt "$KEEP_BACKUPS" ] || continue
|
||||
log "removing old pre-upgrade backup $(basename "$file")"
|
||||
rm -f "$file"
|
||||
done < <(find "$UPGRADE_BACKUPS" -mindepth 1 -maxdepth 1 -type f -name 'fluxer-*.tar.zst' -printf '%T@ %p\n' 2>/dev/null | sort -rn | cut -d' ' -f2-)
|
||||
}
|
||||
|
||||
print_done() {
|
||||
log "Fluxer $(current_version) is running"
|
||||
printf '%s\n' \
|
||||
"Logs: journalctl -u $UNIT" \
|
||||
"Services: runuser -u fluxer -- $CURRENT/bin/fluxerd ps" \
|
||||
"Setup token: runuser -u fluxer -- $CURRENT/bin/fluxerd exec api -- printenv FLUXER_SETUP_TOKEN" \
|
||||
"Settings: $ENV_FILE, then systemctl restart $UNIT"
|
||||
}
|
||||
|
||||
install_fresh() {
|
||||
local tarball="$1" version current unit_changed=0
|
||||
version="$(tarball_version "$tarball")"
|
||||
current="$(current_version)"
|
||||
if [ -n "$current" ] && [ "$current" != "$version" ]; then
|
||||
die "release $current is installed, use --upgrade $tarball to move to $version"
|
||||
fi
|
||||
verify_tarball "$tarball"
|
||||
install_bootstrap
|
||||
ensure_user
|
||||
ensure_dirs
|
||||
unpack_release "$tarball" "$version"
|
||||
install_packages "$RELEASES/$version"
|
||||
[ "$current" = "$version" ] || flip_current "$version"
|
||||
write_env_file
|
||||
if [ -e "$DATA_DIR/secrets.env" ]; then
|
||||
log "secrets already exist in $DATA_DIR/secrets.env"
|
||||
else
|
||||
log "creating secrets, note the setup token printed below"
|
||||
as_fluxer "$CURRENT/bin/fluxerd" init
|
||||
fi
|
||||
as_fluxer "$CURRENT/bin/fluxerd" check-config || die "check-config failed, fix $ENV_FILE and run again"
|
||||
install_unit "$CURRENT" && unit_changed=1
|
||||
systemctl enable "$UNIT"
|
||||
if [ "$unit_changed" = 1 ] && systemctl is-active --quiet "$UNIT"; then
|
||||
start_unit restart || die "$UNIT did not become ready, see journalctl -u $UNIT"
|
||||
else
|
||||
start_unit start || die "$UNIT did not become ready, see journalctl -u $UNIT"
|
||||
fi
|
||||
print_done
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
local tarball="$1" old new marker backup
|
||||
old="$(current_version)"
|
||||
[ -n "$old" ] || die "Fluxer is not installed, run install.sh without --upgrade first"
|
||||
new="$(tarball_version "$tarball")"
|
||||
[ "$new" != "$old" ] || die "$new is already the current release"
|
||||
systemctl is-active --quiet "$UNIT" || die "$UNIT is not running, start it so the pre-upgrade backup can be taken"
|
||||
verify_tarball "$tarball"
|
||||
install_bootstrap
|
||||
unpack_release "$tarball" "$new"
|
||||
install_packages "$RELEASES/$new"
|
||||
if ! as_fluxer "$RELEASES/$new/bin/fluxerd" check-config; then
|
||||
rm -rf "${RELEASES:?}/$new"
|
||||
die "check-config failed for $new, nothing was changed"
|
||||
fi
|
||||
|
||||
log "taking the pre-upgrade backup"
|
||||
marker="$(mktemp)"
|
||||
as_fluxer "$RELEASES/$old/bin/fluxerd" backup --pre-upgrade --dir "$UPGRADE_BACKUPS" || {
|
||||
rm -f "$marker"
|
||||
die "the pre-upgrade backup failed, nothing was changed"
|
||||
}
|
||||
backup="$(newest_backup "$marker")"
|
||||
rm -f "$marker"
|
||||
[ -n "$backup" ] || die "the pre-upgrade backup did not appear in $UPGRADE_BACKUPS, nothing was changed"
|
||||
log "backup written to $backup"
|
||||
|
||||
flip_current "$new"
|
||||
install_unit "$RELEASES/$new" || true
|
||||
if start_unit restart; then
|
||||
prune_releases
|
||||
prune_backups
|
||||
print_done
|
||||
return
|
||||
fi
|
||||
|
||||
warn "$new did not become ready, rolling back to $old"
|
||||
systemctl stop "$UNIT" || true
|
||||
flip_current "$old"
|
||||
install_unit "$RELEASES/$old" || true
|
||||
as_fluxer "$RELEASES/$old/bin/fluxerd" restore "$backup" \
|
||||
|| die "restoring $backup failed, $UNIT is stopped on $old, see journalctl -u $UNIT"
|
||||
start_unit start || die "$old did not become ready after the rollback, the backup is $backup"
|
||||
rm -rf "${RELEASES:?}/$new"
|
||||
die "upgrade to $new failed, $old is running again with the data from $backup"
|
||||
}
|
||||
|
||||
main() {
|
||||
local mode=install tarball="${FLUXER_TARBALL:-}"
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--upgrade)
|
||||
mode=upgrade
|
||||
[ "$#" -ge 2 ] || die "--upgrade needs a tarball"
|
||||
tarball="$2"
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-*) die "unknown option $1, see --help" ;;
|
||||
*) tarball="$1" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
check_host
|
||||
exec 9>/run/lock/fluxer-install.lock
|
||||
flock -n 9 || die "another install.sh is running"
|
||||
tarball="$(resolve_tarball "$tarball")"
|
||||
if [ "$mode" = upgrade ]; then
|
||||
upgrade "$tarball"
|
||||
else
|
||||
install_fresh "$tarball"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,125 @@
|
||||
# syntax=docker/dockerfile:1.7
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
ARG SOURCE=export
|
||||
ARG DIST=fluxer-*-linux-*.tar.zst
|
||||
|
||||
FROM erlang:28.5.0.8-slim@sha256:45e0fcffac25a41ed047898a57c7913cc69b5114c1aea0db12c85ed4b1164d77 AS toolchain
|
||||
|
||||
COPY tools/dist/toolchain.sh /usr/local/src/fluxer-dist/toolchain.sh
|
||||
RUN /usr/local/src/fluxer-dist/toolchain.sh /opt/toolchain \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
FROM toolchain AS native
|
||||
|
||||
RUN useradd --create-home --uid 1000 build \
|
||||
&& install -d -o build -g build /opt/native
|
||||
|
||||
COPY fluxer_media_proxy/tools/install-native-deps.sh /usr/local/src/fluxer-dist/install-native-deps.sh
|
||||
|
||||
USER build
|
||||
RUN /usr/local/src/fluxer-dist/install-native-deps.sh /opt/native
|
||||
USER root
|
||||
|
||||
FROM native AS build
|
||||
|
||||
ARG BUILD_VERSION
|
||||
ARG PROFILE
|
||||
ARG CARGO_BUILD_JOBS
|
||||
|
||||
ENV FLUXER_TOOLCHAIN=/opt/toolchain \
|
||||
FLUXER_NATIVE_PREFIX=/opt/native \
|
||||
PNPM_STORE_DIR=/root/.cache/pnpm-store
|
||||
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
|
||||
RUN --mount=type=cache,target=/opt/toolchain/cargo/registry \
|
||||
--mount=type=cache,target=/opt/toolchain/cargo/git \
|
||||
--mount=type=cache,target=/src/target \
|
||||
--mount=type=cache,target=/root/.cache \
|
||||
--mount=type=cache,target=/root/go/pkg/mod \
|
||||
tools/dist/build.sh /out
|
||||
|
||||
FROM scratch AS export
|
||||
COPY --from=build /out/*.tar.zst /out/SHA256SUMS /
|
||||
|
||||
FROM scratch AS fromdist
|
||||
ARG DIST
|
||||
COPY --from=dist ${DIST} /
|
||||
|
||||
FROM ${SOURCE} AS release
|
||||
|
||||
FROM debian:trixie-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 AS unpack
|
||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||
rm -f /etc/apt/apt.conf.d/docker-clean \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends zstd
|
||||
RUN --mount=type=bind,from=release,target=/dist \
|
||||
set -eu; \
|
||||
set -- /dist/fluxer-*-linux-*.tar.zst; \
|
||||
[ "$#" -eq 1 ] && [ -f "$1" ] || { echo "expected exactly one fluxer-*-linux-*.tar.zst, found: $*" >&2; exit 1; }; \
|
||||
mkdir -p /stage; \
|
||||
tar --zstd -xf "$1" -C /stage --no-same-owner; \
|
||||
if [ -e /stage/bin ]; then mv /stage /release; else mv /stage/* /release; fi; \
|
||||
test -x /release/bin/fluxerd
|
||||
|
||||
FROM debian:trixie-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 AS runtime
|
||||
|
||||
ARG BUILD_VERSION=""
|
||||
ARG SOURCE_SHA=""
|
||||
ARG SOURCE_DATE=""
|
||||
|
||||
LABEL org.opencontainers.image.title="fluxer"
|
||||
LABEL org.opencontainers.image.description="Fluxer in one container, supervised by fluxerd"
|
||||
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
|
||||
LABEL org.opencontainers.image.vendor="Fluxer"
|
||||
LABEL org.opencontainers.image.url="https://fluxer.com"
|
||||
LABEL org.opencontainers.image.documentation="https://docs.fluxer.com"
|
||||
LABEL org.opencontainers.image.source="https://github.com/fluxerapp/fluxer"
|
||||
LABEL org.opencontainers.image.version="${BUILD_VERSION}"
|
||||
LABEL org.opencontainers.image.revision="${SOURCE_SHA}"
|
||||
LABEL org.opencontainers.image.created="${SOURCE_DATE}"
|
||||
LABEL app.fluxer.build-version="${BUILD_VERSION}"
|
||||
|
||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||
--mount=type=bind,from=unpack,source=/release/share/runtime-packages,target=/run/runtime-packages \
|
||||
rm -f /etc/apt/apt.conf.d/docker-clean \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends postgresql-common \
|
||||
&& sed -ri 's/^#?[[:space:]]*create_main_cluster[[:space:]]*=.*/create_main_cluster = false/' \
|
||||
/etc/postgresql-common/createcluster.conf \
|
||||
&& grep -q '^create_main_cluster = false$' /etc/postgresql-common/createcluster.conf \
|
||||
&& apt-get install -y --no-install-recommends tini libcap2-bin $(cat /run/runtime-packages) \
|
||||
&& rm -f /usr/lib/*/libheif.so.1* \
|
||||
&& ldconfig \
|
||||
&& test ! -e /etc/postgresql/17/main
|
||||
|
||||
COPY --from=unpack /release /opt/fluxer/current
|
||||
|
||||
RUN groupadd --gid 65532 fluxer \
|
||||
&& useradd --uid 65532 --gid 65532 --home-dir /var/lib/fluxer --no-create-home --shell /usr/sbin/nologin fluxer \
|
||||
&& install -d -o 65532 -g 65532 -m 0700 /var/lib/fluxer /run/fluxer \
|
||||
&& setcap cap_net_bind_service=+p /opt/fluxer/current/bin/fluxerd \
|
||||
&& for f in /opt/fluxer/current/bin/* /opt/fluxer/current/gateway/erts-*/bin/beam.smp; do \
|
||||
out="$(LD_LIBRARY_PATH=/opt/fluxer/current/lib ldd "$f" 2>&1)" || continue; \
|
||||
if printf '%s\n' "$out" | grep 'not found'; then echo "$f has unresolved libraries" >&2; exit 1; fi; \
|
||||
done
|
||||
|
||||
ENV FLUXER_DATA_DIR=/var/lib/fluxer
|
||||
ENV BUILD_VERSION="${BUILD_VERSION}"
|
||||
|
||||
USER 65532:65532
|
||||
WORKDIR /var/lib/fluxer
|
||||
VOLUME /var/lib/fluxer
|
||||
|
||||
EXPOSE 80 443 443/udp 7881 7882/udp
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \
|
||||
CMD ["/opt/fluxer/current/bin/fluxerd", "health"]
|
||||
|
||||
STOPSIGNAL SIGTERM
|
||||
|
||||
ENTRYPOINT ["/usr/bin/tini", "--", "/opt/fluxer/current/bin/fluxerd", "run"]
|
||||
@@ -0,0 +1,17 @@
|
||||
ca-certificates
|
||||
zstd
|
||||
libjemalloc2
|
||||
libstdc++6
|
||||
libcurl4t64
|
||||
libvips42t64
|
||||
libwebp7
|
||||
libwebpmux3
|
||||
libwebpdemux2
|
||||
liblcms2-2
|
||||
libyuv0
|
||||
libde265-0
|
||||
libdav1d7
|
||||
libaom3
|
||||
libssl3t64
|
||||
zlib1g
|
||||
postgresql-17
|
||||
@@ -0,0 +1,32 @@
|
||||
[Unit]
|
||||
Description=Fluxer
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
NotifyAccess=main
|
||||
User=fluxer
|
||||
Group=fluxer
|
||||
ExecStart=/opt/fluxer/current/bin/fluxerd run
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
RestartSteps=6
|
||||
RestartMaxDelaySec=5min
|
||||
TimeoutStartSec=15min
|
||||
TimeoutStopSec=90
|
||||
KillMode=mixed
|
||||
RuntimeDirectory=fluxer
|
||||
RuntimeDirectoryMode=0750
|
||||
StateDirectory=fluxer
|
||||
StateDirectoryMode=0750
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
LimitNOFILE=65536
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ReadWritePaths=/var/lib/fluxer
|
||||
PrivateTmp=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
+386
@@ -0,0 +1,386 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
set -euo pipefail
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
repo="$(cd "$here/../.." && pwd)"
|
||||
|
||||
RUST_PARTS=(server media-proxy)
|
||||
declare -A RUST_CRATE=(
|
||||
[server]=fluxer-server
|
||||
[media-proxy]=fluxer-media-proxy
|
||||
)
|
||||
ALL_PARTS=(fluxerd "${RUST_PARTS[@]}" gateway api app valkey thirdparty share)
|
||||
STATIC_ENTRIES=(avatars badges desktop email emoji web LICENSE THIRD_PARTY_LICENSES.md)
|
||||
TOP_LEVEL=(bin lib gateway api app share tsconfigs)
|
||||
|
||||
log() { printf '==> %s\n' "$*" >&2; }
|
||||
|
||||
die() {
|
||||
printf 'build.sh: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat >&2 <<EOF
|
||||
usage: build.sh [--only part,...] [--into dist-dir] [--no-pack] <out-dir>
|
||||
|
||||
parts: ${ALL_PARTS[*]} rust
|
||||
--into rebuilds the chosen parts inside an existing unpacked dist directory.
|
||||
Without --into the dist directory is <out-dir>/fluxer-linux-<arch>, rebuilt from scratch.
|
||||
The tarball fluxer-<version>-linux-<arch>.tar.zst and SHA256SUMS are written to <out-dir>.
|
||||
|
||||
environment: BUILD_VERSION, PROFILE (release or release-fast), FLUXER_TOOLCHAIN,
|
||||
FLUXER_NATIVE_PREFIX, PNPM_STORE_DIR, JOBS or CARGO_BUILD_JOBS, ZSTD_LEVEL
|
||||
EOF
|
||||
exit 64
|
||||
}
|
||||
|
||||
need() {
|
||||
local tool
|
||||
for tool in "$@"; do
|
||||
command -v "$tool" >/dev/null 2>&1 || die "$tool is required but is not on PATH"
|
||||
done
|
||||
}
|
||||
|
||||
only=""
|
||||
into=""
|
||||
pack=1
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--only)
|
||||
only="${2:?--only needs a list of parts}"
|
||||
shift 2
|
||||
;;
|
||||
--only=*)
|
||||
only="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
--into)
|
||||
into="${2:?--into needs a directory}"
|
||||
shift 2
|
||||
;;
|
||||
--into=*)
|
||||
into="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
--no-pack)
|
||||
pack=0
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
;;
|
||||
-*)
|
||||
die "unknown option $1"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
[ "$#" -eq 1 ] || usage
|
||||
|
||||
declare -A want=()
|
||||
if [ -z "$only" ]; then
|
||||
for part in "${ALL_PARTS[@]}"; do want[$part]=1; done
|
||||
else
|
||||
IFS=, read -ra requested <<<"$only"
|
||||
for part in "${requested[@]}"; do
|
||||
if [ "$part" = rust ]; then
|
||||
for p in "${RUST_PARTS[@]}"; do want[$p]=1; done
|
||||
continue
|
||||
fi
|
||||
[[ " ${ALL_PARTS[*]} " == *" $part "* ]] || die "unknown part $part, expected one of: ${ALL_PARTS[*]} rust"
|
||||
want[$part]=1
|
||||
done
|
||||
fi
|
||||
|
||||
selected() {
|
||||
local part
|
||||
for part in "$@"; do
|
||||
[ -z "${want[$part]:-}" ] || return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
[ "$(uname -s)" = Linux ] || die "build.sh builds Linux releases only"
|
||||
case "$(uname -m)" in
|
||||
x86_64 | amd64) arch=amd64 ;;
|
||||
aarch64 | arm64) arch=arm64 ;;
|
||||
*) die "unsupported architecture $(uname -m)" ;;
|
||||
esac
|
||||
|
||||
profile="${PROFILE:-release}"
|
||||
case "$profile" in
|
||||
dev | test | bench) die "PROFILE=$profile is not a release profile" ;;
|
||||
esac
|
||||
target_dir="$repo/target/$profile"
|
||||
|
||||
if [ -n "${FLUXER_TOOLCHAIN:-}" ]; then
|
||||
[ -d "$FLUXER_TOOLCHAIN/bin" ] || die "no toolchain in $FLUXER_TOOLCHAIN, run make toolchain first"
|
||||
export RUSTUP_HOME="$FLUXER_TOOLCHAIN/rustup" CARGO_HOME="$FLUXER_TOOLCHAIN/cargo"
|
||||
export PATH="$FLUXER_TOOLCHAIN/bin:$CARGO_HOME/bin:$PATH"
|
||||
fi
|
||||
native="${FLUXER_NATIVE_PREFIX:-}"
|
||||
export CARGO_INCREMENTAL=0 ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
||||
export JOBS="${JOBS:-${CARGO_BUILD_JOBS:-$(nproc)}}"
|
||||
store_args=()
|
||||
[ -z "${PNPM_STORE_DIR:-}" ] || store_args=(--store-dir "$PNPM_STORE_DIR")
|
||||
|
||||
mkdir -p "$1"
|
||||
out="$(cd "$1" && pwd)"
|
||||
if [ -n "$into" ]; then
|
||||
[ -d "$into" ] || die "$into is not an unpacked dist directory"
|
||||
dist="$(cd "$into" && pwd)"
|
||||
else
|
||||
dist="$out/fluxer-linux-$arch"
|
||||
rm -rf "$dist"
|
||||
mkdir -p "$dist"
|
||||
fi
|
||||
|
||||
version="${BUILD_VERSION:-}"
|
||||
if [ -z "$version" ] && [ -f "$dist/share/VERSION" ]; then
|
||||
version="$(cat "$dist/share/VERSION")"
|
||||
fi
|
||||
if [ -z "$version" ]; then
|
||||
read -r year monthday hms < <(date -u '+%Y %-m%d %H%M%S')
|
||||
version="$year.$monthday.$((10#$hms))"
|
||||
fi
|
||||
[[ "$version" =~ ^[0-9A-Za-z][0-9A-Za-z._+~-]*$ ]] || die "version $version is not usable in a file name"
|
||||
if [ -n "$into" ] && [ -f "$dist/share/VERSION" ] && ! selected app; then
|
||||
built="$(cat "$dist/share/VERSION")"
|
||||
[ "$version" = "$built" ] || die "$dist holds release $built and its app bundle has that version, add app to --only to build $version"
|
||||
fi
|
||||
export BUILD_VERSION="$version"
|
||||
|
||||
run() {
|
||||
local name="$1" start=$SECONDS
|
||||
shift
|
||||
log "$name"
|
||||
"$@"
|
||||
log "$name done in $((SECONDS - start))s"
|
||||
}
|
||||
|
||||
build_ci() {
|
||||
need cargo
|
||||
(cd "$repo" && cargo build --profile "$profile" --locked -p fluxer-ci --no-default-features)
|
||||
export FLUXER_CI_BIN="$target_dir/fluxer-ci"
|
||||
}
|
||||
|
||||
pnpm_install() {
|
||||
need node pnpm
|
||||
(cd "$repo" && pnpm install --frozen-lockfile --config.confirm-modules-purge=false "${store_args[@]}")
|
||||
}
|
||||
|
||||
require_native() {
|
||||
[ -n "$native" ] || die "set FLUXER_NATIVE_PREFIX to the install-native-deps.sh prefix"
|
||||
[ -f "$native/lib/pkgconfig/libheif.pc" ] || die "no libheif in $native, run make native-deps first"
|
||||
need pkg-config ldd
|
||||
local prefix
|
||||
prefix="$(PKG_CONFIG_PATH="$native/lib/pkgconfig" pkg-config --variable=prefix libheif)"
|
||||
[ "$prefix" = "$native" ] || die "libheif resolves to $prefix instead of $native"
|
||||
}
|
||||
|
||||
check_media_ldd() {
|
||||
local listing bad
|
||||
listing="$(LD_LIBRARY_PATH="$dist/lib" ldd "$dist/bin/fluxer-media-proxy")"
|
||||
printf '%s\n' "$listing" >&2
|
||||
if grep -q 'not found' <<<"$listing"; then
|
||||
die "fluxer-media-proxy has unresolved libraries"
|
||||
fi
|
||||
grep -qF "libheif.so.1 => $dist/lib/libheif.so.1 " <<<"$listing" \
|
||||
|| die "libheif.so.1 does not resolve from $dist/lib"
|
||||
bad="$(grep -E '^[[:space:]]*lib(heif|av[a-z]+|sw[a-z]+)\.so' <<<"$listing" | grep -vF " => $dist/lib/" || true)"
|
||||
[ -z "$bad" ] || die "media libraries resolve outside $dist/lib: $bad"
|
||||
}
|
||||
|
||||
check_admin_assets() {
|
||||
local out_dir
|
||||
for out_dir in "$target_dir"/build/fluxer_admin-*/out/static; do
|
||||
[ -s "$out_dir/app.css" ] || continue
|
||||
[ "$(find "$out_dir/fonts" -maxdepth 1 -name '*.woff2' | wc -l)" -eq 16 ] || continue
|
||||
compgen -G "$out_dir/fonts/fonts.*.css" >/dev/null || continue
|
||||
return 0
|
||||
done
|
||||
die "fluxer_admin was built without its Tailwind CSS or its 16 bundled fonts"
|
||||
}
|
||||
|
||||
build_rust() {
|
||||
local part pkgs=()
|
||||
for part in "${RUST_PARTS[@]}"; do
|
||||
selected "$part" && pkgs+=(-p "${RUST_CRATE[$part]}")
|
||||
done
|
||||
need cargo
|
||||
if selected media-proxy; then
|
||||
require_native
|
||||
(cd "$repo" && PKG_CONFIG_PATH="$native/lib/pkgconfig:$native/lib64/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" \
|
||||
LD_LIBRARY_PATH="$native/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
||||
cargo build --profile "$profile" --locked "${pkgs[@]}")
|
||||
else
|
||||
(cd "$repo" && cargo build --profile "$profile" --locked "${pkgs[@]}")
|
||||
fi
|
||||
for part in "${RUST_PARTS[@]}"; do
|
||||
selected "$part" || continue
|
||||
install -D -m 0755 "$target_dir/${RUST_CRATE[$part]}" "$dist/bin/fluxer-$part"
|
||||
done
|
||||
if selected server; then
|
||||
check_admin_assets
|
||||
fi
|
||||
if selected media-proxy; then
|
||||
rm -rf "${dist:?}/lib"
|
||||
mkdir -p "$dist/lib"
|
||||
cp -a "$native"/lib/*.so.* "$dist/lib/"
|
||||
check_media_ldd
|
||||
fi
|
||||
}
|
||||
|
||||
build_gateway() {
|
||||
need rebar3 erl cargo
|
||||
local release
|
||||
(
|
||||
cd "$repo/fluxer_gateway"
|
||||
export REBAR_SKIP_PROJECT_PLUGINS=1
|
||||
rebar3 compile --deps_only
|
||||
cp config/sys.config.template config/sys.config
|
||||
rebar3 as prod release
|
||||
rm -f config/sys.config
|
||||
)
|
||||
release="$repo/fluxer_gateway/_build/prod/rel/fluxer_gateway"
|
||||
compgen -G "$release/releases/*/vm.args.native.src" >/dev/null \
|
||||
|| die "the gateway release has no vm.args.native.src, check the prod overlay in rebar.config"
|
||||
compgen -G "$release/releases/*/sys.native.config" >/dev/null \
|
||||
|| die "the gateway release has no sys.native.config, check the prod overlay in rebar.config"
|
||||
rm -rf "$dist/gateway"
|
||||
cp -a "$release" "$dist/gateway"
|
||||
mv "$dist/gateway/bin/fluxer_gateway" "$dist/gateway/bin/fluxer_gateway.real"
|
||||
install -m 0755 "$repo/fluxer_gateway/scripts/fluxer_gateway_release_wrapper.sh" "$dist/gateway/bin/fluxer_gateway"
|
||||
}
|
||||
|
||||
build_api() {
|
||||
need node pnpm
|
||||
local node_bin
|
||||
(cd "$repo" && pnpm --filter fluxer_api run build)
|
||||
rm -rf "$dist/api" "$dist/tsconfigs"
|
||||
(cd "$repo" && pnpm deploy --legacy --filter=fluxer_api --prod --config.allow-unused-patches=true "${store_args[@]}" "$dist/api")
|
||||
rm -rf "$dist/api/pkgs" "$dist/api/dist" "$dist/api/bin"
|
||||
cp -a "$repo/fluxer_api/dist" "$dist/api/dist"
|
||||
cp -a "$repo/fluxer_api/bin" "$dist/api/bin"
|
||||
cp -a "$repo/tsconfigs" "$dist/tsconfigs"
|
||||
remove_escaping_links "$dist/api"
|
||||
node_bin="$(readlink -f "$(command -v node)")"
|
||||
install -D -m 0755 "$node_bin" "$dist/bin/node"
|
||||
install -D -m 0644 "$(dirname "$(dirname "$node_bin")")/LICENSE" "$dist/share/LICENSES/node/LICENSE"
|
||||
}
|
||||
|
||||
escaping_links() {
|
||||
local link target root
|
||||
root="$(realpath "$dist")"
|
||||
while IFS= read -r link; do
|
||||
target="$(realpath -m "$link")"
|
||||
[[ "$target" == "$root"/* ]] || printf '%s\n' "$link"
|
||||
done < <(find "$@" -type l)
|
||||
}
|
||||
|
||||
remove_escaping_links() {
|
||||
local link
|
||||
while IFS= read -r link; do
|
||||
log "removing $link, it points at $(readlink "$link") outside the dist"
|
||||
rm "$link"
|
||||
done < <(escaping_links "$1")
|
||||
}
|
||||
|
||||
build_app() {
|
||||
need node pnpm brotli
|
||||
local static="$dist/app/static" entry
|
||||
(cd "$repo" && FLUXER_SELF_HOSTED=true PUBLIC_ASSET_BASE_URL="" BUNDLE_LOCAL_ASSETS=true pnpm --filter fluxer_app build)
|
||||
rm -rf "$dist/app"
|
||||
mkdir -p "$dist/app"
|
||||
cp -a "$repo/fluxer_app/dist" "$static"
|
||||
"$repo/fluxer_app_proxy/scripts/precompress_assets.sh" "$static"
|
||||
for entry in "${STATIC_ENTRIES[@]}"; do
|
||||
[ ! -e "$static/$entry" ] || die "the app build already has $entry, refusing to overwrite it with fluxer_static/$entry"
|
||||
cp -a "$repo/fluxer_static/$entry" "$static/$entry"
|
||||
done
|
||||
"$repo/fluxer_static/fetch-spellcheck-dictionaries.sh" "$static/desktop/spellcheck/dictionaries"
|
||||
}
|
||||
|
||||
build_valkey() {
|
||||
need make cc
|
||||
"$here/valkey.sh" "$dist"
|
||||
}
|
||||
|
||||
build_thirdparty() {
|
||||
need curl sha256sum
|
||||
"$here/fetch-thirdparty.sh" install "$arch" "$dist"
|
||||
}
|
||||
|
||||
build_fluxerd() {
|
||||
need go
|
||||
local licenses="$dist/share/LICENSES/fluxerd" module dir file
|
||||
(cd "$repo/fluxer_native" && CGO_ENABLED=0 GOTOOLCHAIN=local go build -trimpath -ldflags='-s -w' -o "$dist/bin/fluxerd" ./cmd/fluxerd)
|
||||
rm -rf "$licenses"
|
||||
install -D -m 0644 "$(go env GOROOT)/LICENSE" "$licenses/go/LICENSE"
|
||||
while read -r module dir; do
|
||||
[ "$dir" != "$repo/fluxer_native" ] || continue
|
||||
while IFS= read -r file; do
|
||||
install -D -m 0644 "$file" "$licenses/$module/$(basename "$file")"
|
||||
done < <(find "$dir" -maxdepth 1 -type f \( -iname 'LICENSE*' -o -iname 'COPYING*' -o -iname 'NOTICE*' \))
|
||||
done < <(cd "$repo/fluxer_native" && GOTOOLCHAIN=local go list -deps -f '{{with .Module}}{{.Path}} {{.Dir}}{{end}}' ./cmd/fluxerd | sort -u | sed '/^$/d')
|
||||
}
|
||||
|
||||
build_share() {
|
||||
install -D -m 0755 "$repo/packaging/install.sh" "$dist/share/install.sh"
|
||||
install -D -m 0644 "$repo/packaging/runtime-packages" "$dist/share/runtime-packages"
|
||||
install -D -m 0644 "$repo/packaging/systemd/fluxerd.service" "$dist/share/systemd/fluxerd.service"
|
||||
install -D -m 0644 "$repo/LICENSE" "$dist/share/LICENSES/fluxer/LICENSE"
|
||||
}
|
||||
|
||||
verify_layout() {
|
||||
local path missing=()
|
||||
local required=(
|
||||
bin/fluxerd bin/node bin/valkey-server bin/valkey-cli bin/weed bin/meilisearch bin/livekit-server
|
||||
lib/libheif.so.1
|
||||
gateway/bin/fluxer_gateway gateway/bin/fluxer_gateway.real
|
||||
api/package.json api/node_modules api/dist/AppEntrypoint.js api/bin
|
||||
app/static/index.html app/static/avatars app/static/web
|
||||
share/install.sh share/runtime-packages share/systemd/fluxerd.service share/LICENSES/fluxer/LICENSE
|
||||
tsconfigs
|
||||
)
|
||||
for part in "${RUST_PARTS[@]}"; do
|
||||
required+=("bin/fluxer-$part")
|
||||
done
|
||||
for path in "${required[@]}"; do
|
||||
[ -e "$dist/$path" ] || missing+=("$path")
|
||||
done
|
||||
[ "${#missing[@]}" -eq 0 ] || die "$dist is incomplete, missing: ${missing[*]}"
|
||||
missing=()
|
||||
while IFS= read -r path; do missing+=("${path#"$dist"/}"); done < <(escaping_links "${TOP_LEVEL[@]/#/$dist/}")
|
||||
[ "${#missing[@]}" -eq 0 ] || die "these links point outside $dist, installers refuse them: ${missing[*]}"
|
||||
}
|
||||
|
||||
pack() {
|
||||
need tar zstd sha256sum
|
||||
local name="fluxer-$version-linux-$arch.tar.zst"
|
||||
printf '%s\n' "$version" >"$dist/share/VERSION"
|
||||
verify_layout
|
||||
tar -C "$dist" --sort=name --owner=0 --group=0 --numeric-owner \
|
||||
--use-compress-program "zstd -T0 -${ZSTD_LEVEL:-10}" \
|
||||
-cf "$out/$name.part" "${TOP_LEVEL[@]}"
|
||||
mv "$out/$name.part" "$out/$name"
|
||||
(cd "$out" && sha256sum fluxer-*-linux-*.tar.zst >SHA256SUMS.part && mv SHA256SUMS.part SHA256SUMS)
|
||||
log "wrote $out/$name ($(du -h "$out/$name" | cut -f1))"
|
||||
}
|
||||
|
||||
log "building fluxer $version for linux/$arch with profile $profile into $dist"
|
||||
if selected gateway app; then run "fluxer-ci" build_ci; fi
|
||||
if selected api app server; then run "pnpm install" pnpm_install; fi
|
||||
if selected "${RUST_PARTS[@]}"; then run "rust services" build_rust; fi
|
||||
if selected gateway; then run "gateway" build_gateway; fi
|
||||
if selected app; then run "app" build_app; fi
|
||||
if selected api; then run "api" build_api; fi
|
||||
if selected valkey; then run "valkey" build_valkey; fi
|
||||
if selected thirdparty; then run "third-party binaries" build_thirdparty; fi
|
||||
if selected fluxerd; then run "fluxerd" build_fluxerd; fi
|
||||
if selected share; then run "share" build_share; fi
|
||||
if [ "$pack" = 1 ]; then run "tarball" pack; fi
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
set -euo pipefail
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LOCK="$here/thirdparty.lock"
|
||||
CACHE="${FLUXER_DIST_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/fluxer-dist}"
|
||||
tmp=""
|
||||
trap '[ -z "$tmp" ] || rm -rf "$tmp"' EXIT
|
||||
|
||||
log() { printf '==> %s\n' "$*" >&2; }
|
||||
|
||||
die() {
|
||||
printf 'fetch-thirdparty: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
printf '%s\n' \
|
||||
"usage: fetch-thirdparty.sh install <amd64|arm64> <dist-dir>" \
|
||||
" fetch-thirdparty.sh fetch <name> <amd64|arm64|any>" >&2
|
||||
exit 64
|
||||
}
|
||||
|
||||
sha256_of() {
|
||||
sha256sum "$1" | cut -d' ' -f1
|
||||
}
|
||||
|
||||
fetch_url() {
|
||||
local sha="$1" url="$2" dest
|
||||
dest="$CACHE/$sha/$(basename "$url")"
|
||||
if [ -f "$dest" ] && [ "$(sha256_of "$dest")" = "$sha" ]; then
|
||||
printf '%s\n' "$dest"
|
||||
return
|
||||
fi
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
log "downloading $url"
|
||||
curl -fsSL --retry 3 --retry-delay 2 -o "$dest.part" "$url"
|
||||
local actual
|
||||
actual="$(sha256_of "$dest.part")"
|
||||
if [ "$actual" != "$sha" ]; then
|
||||
rm -f "$dest.part"
|
||||
die "sha256 mismatch for $url: expected $sha, got $actual"
|
||||
fi
|
||||
mv "$dest.part" "$dest"
|
||||
printf '%s\n' "$dest"
|
||||
}
|
||||
|
||||
entries_for() {
|
||||
awk -v a="$1" 'NF && ($2 == a || $2 == "any")' "$LOCK"
|
||||
}
|
||||
|
||||
install_all() {
|
||||
local arch="$1" dist="$2" name entry_arch kind sha url member path
|
||||
tmp="$(mktemp -d)"
|
||||
while read -r name entry_arch kind sha url member; do
|
||||
path="$(fetch_url "$sha" "$url")"
|
||||
case "$kind" in
|
||||
bin)
|
||||
install -D -m 0755 "$path" "$dist/bin/$name"
|
||||
;;
|
||||
tgz)
|
||||
tar -xzf "$path" -C "$tmp" "$member"
|
||||
install -D -m 0755 "$tmp/$member" "$dist/bin/$name"
|
||||
rm -f "$tmp/$member"
|
||||
;;
|
||||
license)
|
||||
install -D -m 0644 "$path" "$dist/share/LICENSES/$name"
|
||||
;;
|
||||
src) ;;
|
||||
*)
|
||||
die "unknown kind $kind for $name ($entry_arch) in $LOCK"
|
||||
;;
|
||||
esac
|
||||
done < <(entries_for "$arch")
|
||||
}
|
||||
|
||||
fetch_one() {
|
||||
local name="$1" arch="$2" matches
|
||||
matches="$(awk -v n="$name" -v a="$arch" '$1 == n && ($2 == a || $2 == "any")' "$LOCK")"
|
||||
[ -n "$matches" ] || die "no entry for $name ($arch) in $LOCK"
|
||||
[ "$(printf '%s\n' "$matches" | wc -l)" -eq 1 ] || die "more than one entry for $name ($arch) in $LOCK"
|
||||
local sha url
|
||||
read -r _ _ _ sha url _ <<<"$matches"
|
||||
fetch_url "$sha" "$url"
|
||||
}
|
||||
|
||||
[ "$#" -ge 1 ] || usage
|
||||
case "$1" in
|
||||
install)
|
||||
[ "$#" -eq 3 ] || usage
|
||||
case "$2" in amd64 | arm64) ;; *) usage ;; esac
|
||||
mkdir -p "$3"
|
||||
install_all "$2" "$(cd "$3" && pwd)"
|
||||
;;
|
||||
fetch)
|
||||
[ "$#" -eq 3 ] || usage
|
||||
fetch_one "$2" "$3"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
weed amd64 tgz 8b538c22d47d0c3fb6792adaa6b0c735a967401270a53427d5a476dcaca9b7ae https://github.com/seaweedfs/seaweedfs/releases/download/4.52/linux_amd64.tar.gz weed
|
||||
weed arm64 tgz b70a09540bf8aa2b9ea2a48b3b16abe27e162e90a0c3bf041f8d414caf52de8a https://github.com/seaweedfs/seaweedfs/releases/download/4.52/linux_arm64.tar.gz weed
|
||||
meilisearch amd64 bin b1ffed74645730b3994afab738e4fc75111761e7069c96470d30fd1c5d80f892 https://github.com/meilisearch/meilisearch/releases/download/v1.53.3/meilisearch-linux-amd64
|
||||
meilisearch arm64 bin cf5d9bfe4352d8f87007d3207646408c8421550df526965c5a449440afdb9b5c https://github.com/meilisearch/meilisearch/releases/download/v1.53.3/meilisearch-linux-aarch64
|
||||
livekit-server amd64 tgz 9b89eb169c6c5795393bad6b52a9d0c73640a5993b37162558b4e249e5fe3aee https://github.com/livekit/livekit/releases/download/v1.12.0/livekit_1.12.0_linux_amd64.tar.gz livekit-server
|
||||
livekit-server arm64 tgz e72adb7d824b300ce54dde7c80c901d4062d1ca2f74b14d6fa56cbe32cc2b07a https://github.com/livekit/livekit/releases/download/v1.12.0/livekit_1.12.0_linux_arm64.tar.gz livekit-server
|
||||
valkey any src 184e34ed2d9b51879b682b5b15205e2b9d677c60280e3cb453be8f520d04e293 https://github.com/valkey-io/valkey/archive/refs/tags/9.1.3.tar.gz
|
||||
seaweedfs/LICENSE any license d789d433cc11da163273d1e39be2e8fa67642f9a58ef220d3f258fa9c14ef613 https://raw.githubusercontent.com/seaweedfs/seaweedfs/4.52/LICENSE
|
||||
meilisearch/LICENSE any license 315c57000333ab29e78c67d46e96494e987cdc2b76479fb745e4ad6b496de642 https://raw.githubusercontent.com/meilisearch/meilisearch/v1.53.3/LICENSE
|
||||
meilisearch/LICENSE-MIT any license 121168e4b0db909bf16badd9d1c51ad9aa356241487bf02ef69f8d1ef9e4be6f https://raw.githubusercontent.com/meilisearch/meilisearch/v1.53.3/LICENSE-MIT
|
||||
meilisearch/LICENSE-EE any license 941a2a776ed309d8ab8ef8c52cea052e9771394326bde8a4dfe8cfe61b63cfbb https://raw.githubusercontent.com/meilisearch/meilisearch/v1.53.3/LICENSE-EE
|
||||
livekit-server/LICENSE any license cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30 https://raw.githubusercontent.com/livekit/livekit/v1.12.0/LICENSE
|
||||
ffmpeg/COPYING.LGPLv2.1 any license 246041b6ecf9bc32d718a62c57877c78b5eb397b6467e74ed7ae2626ab189c30 https://raw.githubusercontent.com/FFmpeg/FFmpeg/n9.0.2/COPYING.LGPLv2.1
|
||||
ffmpeg/LICENSE.md any license 2e1d16c72fd74e12063776371da757322f8b77589386532f4fd8634bde7de1af https://raw.githubusercontent.com/FFmpeg/FFmpeg/n9.0.2/LICENSE.md
|
||||
libheif/COPYING any license fa81ce652315b013359d6e8e4744335f31a50c7c192907176d3632f78a3b4596 https://raw.githubusercontent.com/strukturag/libheif/v1.23.6/COPYING
|
||||
erlang-otp/LICENSE.txt any license 809fa1ed21450f59827d1e9aec720bbc4b687434fa22283c6cb5dd82a47ab9c0 https://raw.githubusercontent.com/erlang/otp/OTP-28.5.0.8/LICENSE.txt
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
set -euo pipefail
|
||||
|
||||
RUST_VERSION=1.98.1
|
||||
RUSTUP_VERSION=1.29.3
|
||||
WASM_BINDGEN_VERSION=0.2.128
|
||||
NODE_VERSION=26.8.1
|
||||
PNPM_VERSION=11.27.0
|
||||
OTP_VERSION=28.5.0.8
|
||||
OTP_SHA256=8a696e15bcbe5d57197b1f4c03c92d415f9fd9af70f9222a05911c8a5463cba6
|
||||
REBAR3_VERSION=3.27.3
|
||||
REBAR3_SHA256=f1d87d78decfc56b87d971c75ee6355698ec0c49fadd57f2c056043b7ca291b5
|
||||
GO_VERSION=1.27.3
|
||||
|
||||
APT_PACKAGES=(
|
||||
build-essential pkg-config cmake nasm yasm git curl ca-certificates xz-utils zstd python3 brotli clang llvm
|
||||
libssl-dev zlib1g-dev libcurl4-openssl-dev
|
||||
libvips-dev libwebp-dev liblcms2-dev libyuv-dev libde265-dev libdav1d-dev libaom-dev
|
||||
)
|
||||
OTP_APT_PACKAGES=(libncurses-dev)
|
||||
|
||||
log() { printf '==> %s\n' "$*" >&2; }
|
||||
|
||||
die() {
|
||||
printf 'toolchain.sh: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ "$#" -eq 1 ] || {
|
||||
printf 'usage: toolchain.sh <prefix>\n' >&2
|
||||
exit 64
|
||||
}
|
||||
[ "$(uname -s)" = Linux ] || die "toolchain.sh installs Linux toolchains only"
|
||||
|
||||
case "$(uname -m)" in
|
||||
x86_64 | amd64)
|
||||
RUST_TRIPLE=x86_64-unknown-linux-gnu
|
||||
RUSTUP_SHA256=b1c8cb14e30889e7e2999e6b69e62d9e9b9ffc0f4df8180564d306d9680e6c55
|
||||
NODE_ARCH=x64
|
||||
NODE_SHA256=3e301118d7df53d563b7e96c1617545f26e2f76f9724be668d6cab65c15dda5d
|
||||
GO_ARCH=amd64
|
||||
GO_SHA256=65efbc80fdc1fa2cd2631cad5b481777a68e8725f34e89f50fc6ac714e379b40
|
||||
;;
|
||||
aarch64 | arm64)
|
||||
RUST_TRIPLE=aarch64-unknown-linux-gnu
|
||||
RUSTUP_SHA256=9f608c142e0e38a78957d0661ba1dfaf0b6fb37184cfaa4b9a0aa57af6184282
|
||||
NODE_ARCH=arm64
|
||||
NODE_SHA256=23c1b4d19e2f12a7d06fe8aa3d6e0e4923cf77a47e13c5ccdf32fadaa33960f2
|
||||
GO_ARCH=arm64
|
||||
GO_SHA256=a06e99309dbcbdca1a8ccd2282c3ee146e55930886e26b4f1193269587165f49
|
||||
;;
|
||||
*)
|
||||
die "unsupported architecture $(uname -m)"
|
||||
;;
|
||||
esac
|
||||
|
||||
mkdir -p "$1"
|
||||
PREFIX="$(cd "$1" && pwd)"
|
||||
JOBS="${JOBS:-$(nproc)}"
|
||||
export RUSTUP_HOME="$PREFIX/rustup" CARGO_HOME="$PREFIX/cargo"
|
||||
export PATH="$PREFIX/bin:$CARGO_HOME/bin:$PATH"
|
||||
|
||||
work="$(mktemp -d "$PREFIX/.work.XXXXXX")"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
|
||||
fetch() {
|
||||
local url="$1" sha="$2" dest actual
|
||||
dest="$work/$(basename "$url")"
|
||||
log "downloading $url"
|
||||
curl -fsSL --retry 3 --retry-delay 2 -o "$dest" "$url"
|
||||
actual="$(sha256sum "$dest" | cut -d' ' -f1)"
|
||||
[ "$actual" = "$sha" ] || die "sha256 mismatch for $url: expected $sha, got $actual"
|
||||
printf '%s\n' "$dest"
|
||||
}
|
||||
|
||||
otp_version() {
|
||||
erl -noshell -eval '{ok, V} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:put_chars(string:trim(V)), halt().' 2>/dev/null || true
|
||||
}
|
||||
|
||||
missing_packages() {
|
||||
local pkg
|
||||
for pkg in "$@"; do
|
||||
[ "$(dpkg-query -W -f='${db:Status-Status}' "$pkg" 2>/dev/null)" = installed ] || printf '%s\n' "$pkg"
|
||||
done
|
||||
}
|
||||
|
||||
install_apt_packages() {
|
||||
command -v dpkg-query >/dev/null 2>&1 || die "install these Debian packages first: $*"
|
||||
local missing
|
||||
mapfile -t missing < <(missing_packages "$@")
|
||||
[ "${#missing[@]}" -gt 0 ] || return 0
|
||||
log "installing ${missing[*]}"
|
||||
local sudo=()
|
||||
[ "$(id -u)" = 0 ] || sudo=(sudo)
|
||||
"${sudo[@]}" apt-get update
|
||||
"${sudo[@]}" env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "${missing[@]}"
|
||||
}
|
||||
|
||||
install_rust() {
|
||||
if [ ! -x "$CARGO_HOME/bin/rustup" ]; then
|
||||
local init
|
||||
init="$(fetch "https://static.rust-lang.org/rustup/archive/${RUSTUP_VERSION}/${RUST_TRIPLE}/rustup-init" "$RUSTUP_SHA256")"
|
||||
chmod 0755 "$init"
|
||||
"$init" -y --no-modify-path --profile minimal --default-toolchain "$RUST_VERSION"
|
||||
fi
|
||||
rustup toolchain install "$RUST_VERSION" --profile minimal --no-self-update
|
||||
rustup target add --toolchain "$RUST_VERSION" wasm32-unknown-unknown
|
||||
rustup default "$RUST_VERSION"
|
||||
if [ "$(wasm-bindgen --version 2>/dev/null || true)" != "wasm-bindgen $WASM_BINDGEN_VERSION" ]; then
|
||||
cargo "+$RUST_VERSION" install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked --force
|
||||
fi
|
||||
}
|
||||
|
||||
install_node() {
|
||||
local dir="$PREFIX/node" tarball
|
||||
if [ "$("$dir/bin/node" --version 2>/dev/null || true)" != "v$NODE_VERSION" ]; then
|
||||
tarball="$(fetch "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz" "$NODE_SHA256")"
|
||||
rm -rf "$dir"
|
||||
mkdir -p "$dir"
|
||||
tar -xJf "$tarball" -C "$dir" --strip-components=1
|
||||
fi
|
||||
if [ "$("$dir/bin/pnpm" --version 2>/dev/null || true)" != "$PNPM_VERSION" ]; then
|
||||
PATH="$dir/bin:$PATH" npm install -g --prefix "$dir" --no-audit --no-fund "pnpm@$PNPM_VERSION"
|
||||
fi
|
||||
local tool
|
||||
for tool in node npm npx pnpm; do
|
||||
ln -sfn "../node/bin/$tool" "$PREFIX/bin/$tool"
|
||||
done
|
||||
}
|
||||
|
||||
install_go() {
|
||||
local tarball
|
||||
if ! "$PREFIX/go/bin/go" version 2>/dev/null | grep -qF "go$GO_VERSION "; then
|
||||
tarball="$(fetch "https://go.dev/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz" "$GO_SHA256")"
|
||||
rm -rf "$PREFIX/go"
|
||||
tar -xzf "$tarball" -C "$PREFIX"
|
||||
fi
|
||||
ln -sfn ../go/bin/go "$PREFIX/bin/go"
|
||||
ln -sfn ../go/bin/gofmt "$PREFIX/bin/gofmt"
|
||||
}
|
||||
|
||||
install_otp() {
|
||||
local tarball src="$work/otp" tool
|
||||
tarball="$(fetch "https://github.com/erlang/otp/releases/download/OTP-${OTP_VERSION}/otp_src_${OTP_VERSION}.tar.gz" "$OTP_SHA256")"
|
||||
rm -rf "$PREFIX/otp"
|
||||
mkdir -p "$src"
|
||||
tar -xzf "$tarball" -C "$src" --strip-components=1
|
||||
(
|
||||
cd "$src"
|
||||
./configure --prefix="$PREFIX/otp" --without-javac --without-jinterface --without-wx --without-odbc
|
||||
make -j"$JOBS"
|
||||
make install
|
||||
)
|
||||
for tool in "$PREFIX"/otp/bin/*; do
|
||||
ln -sfn "../otp/bin/$(basename "$tool")" "$PREFIX/bin/$(basename "$tool")"
|
||||
done
|
||||
}
|
||||
|
||||
install_rebar3() {
|
||||
local script
|
||||
if [ -x "$PREFIX/bin/rebar3" ] && [ "$(sha256sum "$PREFIX/bin/rebar3" | cut -d' ' -f1)" = "$REBAR3_SHA256" ]; then
|
||||
return
|
||||
fi
|
||||
script="$(fetch "https://github.com/erlang/rebar3/releases/download/${REBAR3_VERSION}/rebar3" "$REBAR3_SHA256")"
|
||||
install -m 0755 "$script" "$PREFIX/bin/rebar3"
|
||||
}
|
||||
|
||||
mkdir -p "$PREFIX/bin"
|
||||
|
||||
need_otp=0
|
||||
[ "$(otp_version)" = "$OTP_VERSION" ] || need_otp=1
|
||||
|
||||
if [ "$need_otp" = 1 ]; then
|
||||
install_apt_packages "${APT_PACKAGES[@]}" "${OTP_APT_PACKAGES[@]}"
|
||||
else
|
||||
install_apt_packages "${APT_PACKAGES[@]}"
|
||||
fi
|
||||
|
||||
install_rust
|
||||
install_node
|
||||
install_go
|
||||
if [ "$need_otp" = 1 ]; then
|
||||
log "building OTP ${OTP_VERSION} into $PREFIX/otp"
|
||||
install_otp
|
||||
fi
|
||||
[ "$(otp_version)" = "$OTP_VERSION" ] || die "erl on PATH does not report OTP ${OTP_VERSION}"
|
||||
install_rebar3
|
||||
|
||||
log "toolchain ready in $PREFIX"
|
||||
log "rust $(rustc --version), node $(node --version), pnpm $(pnpm --version), $(go version), OTP $(otp_version), $(rebar3 version)"
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
set -euo pipefail
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
die() {
|
||||
printf 'valkey.sh: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ "$#" -eq 1 ] || {
|
||||
printf 'usage: valkey.sh <dist-dir>\n' >&2
|
||||
exit 64
|
||||
}
|
||||
|
||||
mkdir -p "$1"
|
||||
dist="$(cd "$1" && pwd)"
|
||||
tarball="$("$here/fetch-thirdparty.sh" fetch valkey any)"
|
||||
version="$(basename "$tarball" .tar.gz)"
|
||||
jobs="${JOBS:-$(nproc)}"
|
||||
|
||||
case "$(uname -m)" in
|
||||
x86_64 | amd64) lg_page=12 ;;
|
||||
*) lg_page=16 ;;
|
||||
esac
|
||||
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
|
||||
tar -xzf "$tarball" -C "$work" --strip-components=1
|
||||
grep -qF 'cd jemalloc && ./configure ' "$work/deps/Makefile" \
|
||||
|| die "deps/Makefile no longer configures the bundled jemalloc the expected way"
|
||||
sed -i "s!cd jemalloc && ./configure !&--with-lg-page=${lg_page} --with-lg-hugepage=21 !" "$work/deps/Makefile"
|
||||
|
||||
make -C "$work" -j"$jobs" BUILD_TLS=no USE_SYSTEMD=no USE_FAST_FLOAT=yes all
|
||||
|
||||
install -D -m 0755 "$work/src/valkey-server" "$dist/bin/valkey-server"
|
||||
install -D -m 0755 "$work/src/valkey-cli" "$dist/bin/valkey-cli"
|
||||
"$dist/bin/valkey-server" --version | grep -qF " v=${version} " \
|
||||
|| die "built valkey-server does not report version ${version}"
|
||||
|
||||
licenses="$dist/share/LICENSES/valkey"
|
||||
rm -rf "$licenses"
|
||||
install -D -m 0644 "$work/COPYING" "$licenses/COPYING"
|
||||
while IFS= read -r file; do
|
||||
install -D -m 0644 "$file" "$licenses/${file#"$work/"}"
|
||||
done < <(find "$work/deps" -maxdepth 2 -type f \( -iname 'COPYING*' -o -iname 'LICENSE*' \) | sort)
|
||||
Reference in new issue
Block a user