From 9d515e0b6c6116cd65c0a9ffb1f210ebc7963350 Mon Sep 17 00:00:00 2001 From: Mariusz Kogen Date: Tue, 5 Dec 2023 15:52:05 +0100 Subject: [PATCH] entrypoint refactor * version bump * clean manifest --- docker_entrypoint.sh | 75 +++++++++++++++++++++++++------------------- manifest.yaml | 63 +------------------------------------ 2 files changed, 44 insertions(+), 94 deletions(-) diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 502ec3e..992429d 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -3,38 +3,49 @@ LN_PROXY_PORT=3001 RUST_LOG=debug - POSTGRES_DATADIR="/var/lib/postgresql/15" - POSTGRES_CONFIG="/etc/postgresql/15" - - #Start and Configure PostgreSQL - echo 'Starting PostgreSQL database server for the first time...' - mkdir -p $POSTGRES_DATADIR $POSTGRES_CONFIG - mv /var/lib/main $POSTGRES_DATADIR - chown -R postgres:postgres $POSTGRES_DATADIR - chown -R postgres:postgres $POSTGRES_CONFIG - chmod -R 700 $POSTGRES_DATADIR - chmod -R 700 $POSTGRES_CONFIG - su - postgres -c "pg_createcluster 15 lib" - su - postgres -c "pg_ctlcluster 15 lib start" - - POSTGRES_USER=postgres - POSTGRES_PASSWORD=docker - POSTGRES_DB=vss - - # Start db server - service postgresql start - echo 'Creating user...' - su - postgres -c "createuser $POSTGRES_USER" - echo 'Creating db...' - su - postgres -c "createdb $POSTGRES_DB" - echo 'Setting password...' - su - postgres -c 'psql -c "ALTER USER '$POSTGRES_USER' WITH ENCRYPTED PASSWORD '"'"$POSTGRES_PASSWORD"'"';"' - echo 'Granting db permissions...' - su - postgres -c 'psql -c "grant all privileges on database '$POSTGRES_DB' to '$POSTGRES_USER';"' - echo 'Creating .pgpass file...' - echo "localhost:5432:'$POSTGRES_USER':'$POSTGRES_PASSWORD'" > $POSTGRES_DATADIR/../.pgpass - chmod -R 0600 $POSTGRES_DATADIR/../.pgpass - chown postgres:postgres $POSTGRES_DATADIR/../.pgpass +POSTGRES_DATADIR="/var/lib/postgresql/15" +POSTGRES_CONFIG="/etc/postgresql/15" +CLUSTER_NAME="main" + +# Start and Configure PostgreSQL +echo 'Starting PostgreSQL database server...' + +# Move main directory if it doesn't exist in the target +if [ ! -d "$POSTGRES_DATADIR/$CLUSTER_NAME" ]; then + echo 'Moving PostgreSQL data directory...' + mkdir -p "$POSTGRES_DATADIR" "$POSTGRES_CONFIG" + mv /var/lib/main "$POSTGRES_DATADIR" +else + echo "Target directory '$POSTGRES_DATADIR/$CLUSTER_NAME' already exists. Skipping move operation." +fi + +# Set ownership and permissions +chown -R postgres:postgres "$POSTGRES_DATADIR" "$POSTGRES_CONFIG" +chmod -R 700 "$POSTGRES_DATADIR" "$POSTGRES_CONFIG" + +# Start PostgreSQL cluster +su - postgres -c "pg_ctlcluster 15 $CLUSTER_NAME start" + +POSTGRES_USER=postgres +POSTGRES_PASSWORD=docker +POSTGRES_DB=vss + +# Create user if not exists +su - postgres -c "createuser $POSTGRES_USER" 2>/dev/null || true + +# Create database if not exists +su - postgres -c "createdb --encoding=UTF8 $POSTGRES_DB" 2>/dev/null || true + +echo 'Setting password...' +su - postgres -c 'psql -c "ALTER USER '$POSTGRES_USER' WITH ENCRYPTED PASSWORD '"'"$POSTGRES_PASSWORD"'"';"' + +echo 'Granting db permissions...' +su - postgres -c 'psql -c "grant all privileges on database '$POSTGRES_DB' to '$POSTGRES_USER';"' + +echo 'Creating .pgpass file...' +echo "localhost:5432:$POSTGRES_DB:$POSTGRES_USER:$POSTGRES_PASSWORD" >"$POSTGRES_DATADIR/../.pgpass" +chmod 0600 "$POSTGRES_DATADIR/../.pgpass" +chown postgres:postgres "$POSTGRES_DATADIR/../.pgpass" /app/vss-rs & /app/ln-websocket-proxy & diff --git a/manifest.yaml b/manifest.yaml index 3ea1999..5151eb8 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,73 +1,32 @@ -# Example written in yaml (toml and json are also acceptable) -# The package identifier used by the OS. This must be unique amongst all other known packages id: mutiny-wallet -# A human readable service title title: "Mutiny Wallet" -# Service version - accepts up to four digits, where the last confirms to revisions necessary for StartOS - see documentation: https://github.com/Start9Labs/emver-rs. This value will change with each release of the service. -version: 0.4.39 -# Release notes for the update - can be a string, paragraph or URL +version: 0.4.39-1 release-notes: | - Dynamic Channel Fees, setting up your channels should be cheaper now - General backend improvements - Bug fixes -# 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/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. support-site: "https://matrix.to/#/#mutiny-community:lightninghackers.com/" -# URL to the marketing site for the project. This key can be omitted if none exists, or it can link to the original project repository. marketing-site: "https://mutinywallet.com/" -# The series of commands to build the project into an s9pk for arm64/v8. In this case we are using a Makefile with the simple build command "make". build: ["make"] -# Human readable descriptors for the service. These are used throughout the StartOS user interface, primarily in the marketplace. description: - # This is the first description visible to the user in the marketplace. short: Mutiny is a self-custodial lightning wallet that runs in the web. - # This description will display with additional details in the service's individual marketplace page long: | Mutiny is a self-custodial lightning wallet that runs in the web. It is a not a traditional lightning node that is always online, but rather a wallet that runs in your browser of the device of you're accessing it from. Mutiny comes with full functionality for sending and receiving on-chain and lightning payments. It also supports many social features like Nostr integrations like Nostr Wallet Connect, Nostr Contacts, and a Zap Feed. WARNING: This is an beta software, don't put too much money in. -# These assets are static files necessary for packaging the service for Start9 (into an s9pk). Each value is a path to the specified asset. If an asset is missing from this list, or otherwise denoted, it will be defaulted to the values denoted below. assets: - # Default = LICENSE.md license: LICENSE - # Default = icon.png (.svg allowed) icon: icon.png - # Default = INSTRUCTIONS.md instructions: instructions.md - # Default = image.tar - # docker-images: image.tar -# ----- This section commented out until we support long-running containers ----- -# The main action for initializing the service. This can be script to utilize the eOS scripting apis, or docker. -# main: -# type: script -# # Defines the containers needed to run the main and mounted volumes -# containers: -# main: -# # Identifier for the main image volume, which will be used when other actions need to mount to this volume. -# image: main -# # Specifies where to mount the data volume(s), if there are any. Mounts for pointer dependency volumes are also denoted here. These are necessary if data needs to be read from / written to these volumes. -# mounts: -# # Specifies where on the service's file system its persistence directory should be mounted prior to service startup -# main: /root -# ----- END commented section ----- main: - # Docker is currently the only action implementation type: docker - # Identifier for the main image volume, which will be used when other actions need to mount to this volume. image: main - # The executable binary for starting the initialization action. For docker actions, this is typically a "docker_entrypoint.sh" file. See the Dockerfile and the docker_entrypoint.sh in this project for additional details. entrypoint: "docker_entrypoint.sh" - # Any arguments that should be passed into the entrypoint executable args: [] - # Specifies where to mount the data volume(s), if there are any. Mounts for pointer dependency volumes are also denoted here. These are necessary if data needs to be read from / written to these volumes. mounts: - # Specifies where on the service's file system its persistence directory should be mounted prior to service startup main: "/var/lib/postgresql" -# This is where health checks would be defined - see a more advanced example in https://github.com/Start9Labs/start-pages-wrapper health-checks: main: name: Web UI @@ -80,59 +39,39 @@ health-checks: inject: true config: ~ properties: ~ -# type: script -# This denotes any data, asset, or pointer volumes that should be connected when the "docker run" command is invoked volumes: - # This is the image where files from the project asset directory will go main: type: data -# This specifies how to configure the port mapping for exposing the service over TOR and LAN (if applicable). Many interfaces can be specified depending on the needs of the service. If it can be launched over a Local Area Network connection, specify a `lan-config`. Otherwise, at minimum, a `tor-config` must be specified. interfaces: - # This key is the internal name that the OS will use to configure the interface main: - # A human readable name for display in the UI name: User Interface - # A descriptive description of what the interface does description: The UI for Mutiny Wallet tor-config: - # Port mappings are from the external port to the internal container port port-mapping: 80: "80" - # Port mappings are from the external port to the internal container port lan-config: 443: ssl: true internal: 80 - # Denotes if the service has a user interface to display ui: true - # Denotes the protocol specifications used by this interface protocols: - tcp - http dependencies: {} -# Specifies how backups should be run for this service. The default StartOS provided option is to use the duplicity backup library on a system image (compat) backup: create: - # Currently, only docker actions are supported. type: docker - # The docker image to use. In this case, a pre-loaded system image called compat image: compat - # Required if the action uses a system image. The default value is false. system: true - # The executable to run the command to begin the backup create process entrypoint: compat - # Arguments to pass into the entrypoint executable. In this example, the full command run will be: `compat duplicity hello-world /mnt/backup /root/data` args: - duplicity - create - /mnt/backup - /var/lib/postgresql mounts: - # BACKUP is the default volume that is used for backups. This is whatever backup drive is mounted to the device, or a network filesystem. - # The value here donates where the mount point will be. The backup drive is mounted to this location. BACKUP: "/mnt/backup" main: "/var/lib/postgresql" - # The action to execute the backup restore functionality. Details for the keys below are the same as above. restore: type: docker image: compat