Skip to content

Commit

Permalink
update to startos template
Browse files Browse the repository at this point in the history
  • Loading branch information
islandbitcoin committed Oct 20, 2023
1 parent 0023458 commit dabe845
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.s9pk
scripts/*.js
.DS_Store
.vscode/
docker-images/
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

[submodule "mutiny-web"]
path = mutiny-web
url = https://github.com/MutinyWallet/mutiny-web.git
[submodule "ln-websocket-proxy"]
path = ln-websocket-proxy
url = https://github.com/MutinyWallet/ln-websocket-proxy
[submodule "vss-rs"]
path = vss-rs
url = https://github.com/MutinyWallet/vss-rs
24 changes: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ FROM rust:1.72.0-bookworm AS rust-builder

WORKDIR /build

RUN apt update && apt install -y git python3 make build-essential clang cmake libsnappy-dev openssl libpq-dev pkg-config libc6
RUN apt update && apt install -y git python3 make build-essential clang cmake libsnappy-dev openssl libpq-dev pkg-config libc6 git

# Install vss-rs
RUN git clone -b v0.1.0 https://github.com/MutinyWallet/vss-rs
# removing this and using submodules instead -- Dread
# RUN git clone -b v0.1.0 https://github.com/MutinyWallet/vss-rs
WORKDIR /build/vss-rs
COPY ./vss-rs .
RUN cargo build --release

WORKDIR /build
# Install ln-websocket-proxy
RUN git clone -b v0.3.1 https://github.com/MutinyWallet/ln-websocket-proxy
# removing this and using submodules instead -- Dread
# RUN git clone -b v0.3.1 https://github.com/MutinyWallet/ln-websocket-proxy
WORKDIR /build/ln-websocket-proxy
COPY ./ln-websocket-proxy .
RUN cargo build --release --features="server"

# Use Node.js for building the site
Expand All @@ -24,7 +28,9 @@ WORKDIR /app

RUN apt update && apt install -y git python3 make build-essential

RUN git clone --b v0.4.21 https://github.com/MutinyWallet/mutiny-web .
# removing this and using submodules instead -- Dread
# RUN git clone --b v0.4.21 https://github.com/MutinyWallet/mutiny-web .
COPY ./mutiny-web .

# This is the cooler way to run pnpm these days (no need to npm install it)
RUN corepack enable
Expand All @@ -44,10 +50,10 @@ ARG VITE_SELFHOSTED="true"
RUN pnpm install --frozen-lockfile

# IDK why but it gets mad if you don't do this
RUN git config --global --add safe.directory /app
# RUN git config --global --add safe.directory /app

# Build the static site
RUN pnpm run build
# RUN pnpm run build

FROM nginx:bookworm

Expand All @@ -58,16 +64,14 @@ COPY --from=rust-builder /build/vss-rs/target/release/vss-rs /app/vss-rs
COPY --from=rust-builder /build/ln-websocket-proxy/target/release/ln_websocket_proxy /app/ln-websocket-proxy

# Copy static assets
COPY --from=web-builder /app/dist/public /usr/share/nginx/html
# COPY --from=web-builder /app/dist/public /usr/share/nginx/html

COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY docker_entrypoint.sh /app/docker_entrypoint.sh
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh

EXPOSE 80

STOPSIGNAL SIGINT

ENV DATABASE_URL="postgres://postgres:docker@localhost/vss"
ENV SELF_HOST="true"

CMD ["/app/docker_entrypoint.sh"]
62 changes: 55 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,69 @@ TS_FILES := $(shell find ./ -name \*.ts)
all: verify

verify: $(PKG_ID).s9pk
embassy-sdk verify s9pk $(PKG_ID).s9pk
@start-sdk verify s9pk $(PKG_ID).s9pk
@echo " Done!"
@echo " Filesize: $(shell du -h $(PKG_ID).s9pk) is ready"

install:
embassy-cli package install $(PKG_ID).s9pk
ifeq (,$(wildcard ~/.embassy/config.yaml))
@echo; echo "You must define \"host: http://start-server-name.local\" in ~/.embassy/config.yaml config file first"; echo
else
start-cli package install $(PKG_ID).s9pk
endif

clean:
rm -f image.tar
rm -rf docker-images
rm -f $(PKG_ID).s9pk
rm -f scripts/*.js
rm -f image.tar

clean-manifest:
@sed -i '' '/^[[:blank:]]*#/d;s/#.*//' manifest.yaml
@echo; echo "Comments successfully removed from manifest.yaml file."; echo

# BEGIN REBRANDING
rebranding:
@read -p "Enter new package ID name (must be a single word): " NEW_PKG_ID; \
read -p "Enter new package title: " NEW_PKG_TITLE; \
find . \( -name "*.md" -o -name ".gitignore" -o -name "manifest.yaml" -o -name "*Service.yml" \) -type f -not -path "./mutiny-startos/*" -exec sed -i '' -e "s/mutiny-startos/$$NEW_PKG_ID/g; s/Mutiny/$$NEW_PKG_TITLE/g" {} +; \
echo; echo "Rebranding complete."; echo " New package ID name is: $$NEW_PKG_ID"; \
echo " New package title is: $$NEW_PKG_TITLE"; \
sed -i '' -e '/^# BEGIN REBRANDING/,/^# END REBRANDING/ s/^#*/#/' Makefile
@echo; echo "Note: Rebranding code has been commented out in Makefile"; echo
# END REBRANDING

scripts/embassy.js: $(TS_FILES)
deno bundle scripts/embassy.ts scripts/embassy.js

image.tar: Dockerfile docker_entrypoint.sh
docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --platform=linux/arm64 -o type=docker,dest=image.tar .
arm:
@rm -f docker-images/x86_64.tar
ARCH=aarch64 $(MAKE)

x86:
@rm -f docker-images/aarch64.tar
ARCH=x86_64 $(MAKE)

docker-images/aarch64.tar: Dockerfile docker_entrypoint.sh
ifeq ($(ARCH),x86_64)
else
mkdir -p docker-images
docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --build-arg ARCH=aarch64 --platform=linux/arm64 -o type=docker,dest=docker-images/aarch64.tar .
endif

docker-images/x86_64.tar: Dockerfile docker_entrypoint.sh
ifeq ($(ARCH),aarch64)
else
mkdir -p docker-images
docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --build-arg ARCH=x86_64 --platform=linux/amd64 -o type=docker,dest=docker-images/x86_64.tar .
endif

$(PKG_ID).s9pk: manifest.yaml instructions.md icon.png LICENSE scripts/embassy.js image.tar
embassy-sdk pack
$(PKG_ID).s9pk: manifest.yaml instructions.md icon.png LICENSE scripts/embassy.js docker-images/aarch64.tar docker-images/x86_64.tar
ifeq ($(ARCH),aarch64)
@echo "start-sdk: Preparing aarch64 package ..."
else ifeq ($(ARCH),x86_64)
@echo "start-sdk: Preparing x86_64 package ..."
else
@echo "start-sdk: Preparing Universal Package ..."
endif
@start-sdk pack
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Wrapper for Mutiny

Mutiny Wallet is a lightning wallet that runs in the web. Mutiny is unlike other lightning apps on Start9, it is not a
server that you run on your Embassy. Instead, it is a web app that you can access from any device on your local network.
This means that you can access your wallet from your phone, tablet, or laptop.

This repository creates the `s9pk` package that is installed to run `Mutiny` on [StartOS](https://github.com/Start9Labs/start-os/). Learn more about service packaging in the [Developer Docs](https://start9.com/latest/developer-docs/).

## Dependencies

Install the system dependencies below to build this project by following the instructions in the provided links. You can also find detailed steps to setup your environment in the service packaging [documentation](https://github.com/Start9Labs/service-pipeline#development-environment).

- [docker](https://docs.docker.com/get-docker)
- [docker-buildx](https://docs.docker.com/buildx/working-with-buildx/)
- [yq](https://mikefarah.gitbook.io/yq)
- [deno](https://deno.land/)
- [make](https://www.gnu.org/software/make/)
- [start-sdk](https://github.com/Start9Labs/start-os/tree/master/backend)

## Build environment
Prepare your StartOS build environment. In this example we are using Ubuntu 20.04.
1. Install docker
```
curl -fsSL https://get.docker.com | bash
sudo usermod -aG docker "$USER"
exec sudo su -l $USER
```
2. Set buildx as the default builder
```
docker buildx install
docker buildx create --use
```
3. Enable cross-arch emulated builds in docker
```
docker run --privileged --rm linuxkit/binfmt:v0.8
```
4. Install yq
```
sudo snap install yq
```
5. Install deno
```
sudo snap install deno
```
6. Install essentials build packages
```
sudo apt-get install -y build-essential openssl libssl-dev libc6-dev clang libclang-dev ca-certificates
```
7. Install Rust
```
curl https://sh.rustup.rs -sSf | sh
# Choose nr 1 (default install)
source $HOME/.cargo/env
```
8. Build and install start-sdk
```
cd ~/ && git clone --recursive https://github.com/Start9Labs/start-os.git --branch sdk
cd start-os/backend/
./install-sdk.sh
start-sdk init
```
Now you are ready to build the `mutiny` package!

## Cloning

Clone the project locally:

```
git clone https://github.com/benthecarman/mutiny-startos.git
cd mutiny-startos
git submodule update --init --recursive
```

## Building

To build the `mutiny` package for all platforms using start-sdk, run the following command:

```
make
```

To build the `mutiny` package for a single platform using start-sdk, run:

```
# for amd64
make x86
```
or
```
# for arm64
make arm
```

## Installing (on StartOS)

Run the following commands to determine successful install:
> :information_source: Change server-name.local to your Start9 server address
```
start-cli auth login
# Enter your StartOS password
start-cli --host https://server-name.local package install mutiny.s9pk
```

If you already have your `start-cli` config file setup with a default `host`, you can install simply by running:

```
make install
```

> **Tip:** You can also install the mutiny.s9pk using **Sideload Service** under the **System > Manage** section.
### Verify Install

Go to your StartOS Services page, select **Mutiny**, configure and start the service. Then, verify its interfaces are accessible.

**Done!**
5 changes: 5 additions & 0 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ RUST_LOG=debug
POSTGRES_DATADIR="/var/lib/postgresql/15"
POSTGRES_CONFIG="/etc/postgresql/15"

# Pulling this in from Dockerfile
# IDK why but it gets mad if you don't do this
git config --global --add safe.directory /app
pnpm run build

#Start and Configure PostgreSQL
echo 'Starting PostgreSQL database server for the first time...'
chown -R postgres:postgres $POSTGRES_DATADIR
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ This comes pre-packaged with VSS and the websocket proxy, so everything you need

The only external dependency is esplora, which is used to get blockchain data. This can be configured in the settings
page if you have your own esplora instance running.

## Additional instructions TBD
1 change: 1 addition & 0 deletions ln-websocket-proxy
Submodule ln-websocket-proxy added at 82e669
6 changes: 3 additions & 3 deletions manifest.yml → manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ release-notes: "Initial release"
# The type of license for the project. Include the LICENSE in the root of the project directory. A license is required for a Start9 package.
license: mit
# The Start9 wrapper repository URL for the package. This repo contains the manifest file (this), any scripts necessary for configuration, backups, actions, or health checks (more below). This key must exist. But could be embedded into the source repository.
wrapper-repo: "https://github.com/Start9Labs/hello-world-wrapper"
wrapper-repo: "https://github.com/benthecarman/mutiny-startos"
# The original project repository URL. There is no upstream repo in this example
upstream-repo: "https://github.com/MutinyWallet/mutiny-web"
# URL to the support site / channel for the project. This key can be omitted if none exists, or it can link to the original project repository issues.
Expand Down Expand Up @@ -85,12 +85,12 @@ interfaces:
tor-config:
# Port mappings are from the external port to the internal container port
port-mapping:
80: "80"
80: "8080"
# Port mappings are from the external port to the internal container port
lan-config:
443:
ssl: true
internal: 80
internal: 8080
# Denotes if the service has a user interface to display
ui: true
# Denotes the protocol specifications used by this interface
Expand Down
1 change: 1 addition & 0 deletions mutiny-web
Submodule mutiny-web added at 5e1b97
2 changes: 2 additions & 0 deletions scripts/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "https://deno.land/x/[email protected]/mod.ts";
export * from "https://deno.land/x/[email protected]/util.ts";
5 changes: 5 additions & 0 deletions scripts/embassy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { setConfig } from "./procedures/setConfig.ts";
export { getConfig } from "./procedures/getConfig.ts";
export { properties } from "./procedures/properties.ts";
export { migration } from "./procedures/migrations.ts";
export { main } from "./procedures/main.ts";
5 changes: 5 additions & 0 deletions scripts/procedures/getConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// To utilize the default config system built, this file is required. It defines the *structure* of the configuration file. These structured options display as changeable UI elements within the "Config" section of the service details page in the StartOS UI.

import { compat, types as T } from "../deps.ts";

export const getConfig: T.ExpectedExports.getConfig = compat.getConfig({});
7 changes: 7 additions & 0 deletions scripts/procedures/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { types as T, util } from "../deps.ts";

export const main = async (effects: T.Effects) => {
// args defaulted to [] - not necessary to include if empty
await effects.runDaemon({ command: "docker_entrypoint.sh", args: [] }).wait();
return util.ok;
}
3 changes: 3 additions & 0 deletions scripts/procedures/migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { compat, types as T } from "../deps.ts";

export const migration: T.ExpectedExports.migration = compat.migrations.fromMapping({}, "0.4.21");
3 changes: 3 additions & 0 deletions scripts/procedures/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { compat, types as T } from "../deps.ts";

export const properties: T.ExpectedExports.properties = compat.properties;
5 changes: 5 additions & 0 deletions scripts/procedures/setConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This is where any configuration rules related to the configuration would go. These ensure that the user can only create a valid config.

import { compat, } from "../deps.ts";

export const setConfig = compat.setConfig;
1 change: 1 addition & 0 deletions vss-rs
Submodule vss-rs added at 380831

0 comments on commit dabe845

Please sign in to comment.