diff --git a/.gitignore b/.gitignore index dcf4c72..70593b2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ image.tar *.s9pk tri-push.sh .vscode/ -scripts/embassy.js \ No newline at end of file +scripts/embassy.js +docker-images/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 17a5476..0a793dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,10 @@ FROM node:16-buster-slim AS builder +# arm64 or amd64 +ARG PLATFORM +# aarch64 or x86_64 +ARG ARCH + WORKDIR /build COPY mempool/ . # because just a submodule in wrapper project @@ -20,11 +25,16 @@ RUN cp docker/backend/mempool-config.json backend/ FROM node:16-buster-slim +# arm64 or amd64 +ARG PLATFORM +# aarch64 or x86_64 +ARG ARCH + WORKDIR /backend -RUN apt-get update && apt-get install wget netcat jq pwgen vim procps nginx curl mariadb-server mariadb-client -y \ - && wget https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_arm.tar.gz -O - |\ - tar xz && mv yq_linux_arm /usr/bin/yq +RUN apt-get update && apt-get install wget netcat jq pwgen vim procps nginx curl mariadb-server mariadb-client -y +RUN wget https://github.com/mikefarah/yq/releases/download/v4.6.3/yq_linux_${PLATFORM}.tar.gz -O - |\ + tar xz && mv yq_linux_${PLATFORM} /usr/bin/yq USER root @@ -50,18 +60,8 @@ RUN cp wait-for-it.sh /usr/local/bin && chmod +x start.sh && chmod +x /backend/w # BUILD S9 CUSTOM ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh ADD assets/utils/health-check.sh /usr/local/bin/health-check.sh -RUN chmod +x /usr/local/bin/health-check.sh ADD assets/utils/check-synced.sh /usr/local/bin/check-synced.sh -RUN chmod +x /usr/local/bin/check-synced.sh -RUN mkdir -p /usr/local/bin/migrations -ADD ./scripts/migrations/2_3_1_4_down_temp.sh /usr/local/bin/migrations -RUN chmod a+x /usr/local/bin/migrations/* +RUN chmod +x /usr/local/bin/*.sh # remove to we can manually handle db initalization RUN rm -rf /var/lib/mysql/ - -# USER 1000 -EXPOSE 8080 8999 80 - -ENTRYPOINT ["/usr/local/bin/docker_entrypoint.sh"] -# CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/Makefile b/Makefile index 205e3c5..84781ca 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,35 @@ -EMVER := $(shell yq e ".version" manifest.yaml) -MEMPOOL_SRC := $(shell find ./mempool) -MEMPOOL_GIT_REF := $(shell cat .git/modules/mempool/HEAD) -MEMPOOL_GIT_FILE := $(addprefix .git/modules/mempool/,$(if $(filter ref:%,$(MEMPOOL_GIT_REF)),$(lastword $(MEMPOOL_GIT_REF)),HEAD)) -S9PK_PATH=$(shell find . -name mempool.s9pk -print) +PKG_ID := $(shell yq e ".id" manifest.yaml) +PKG_VERSION := $(shell yq e ".version" manifest.yaml) +TS_FILES := $(shell find ./ -name \*.ts) +# delete the target of a rule if it has changed and its recipe exits with a nonzero exit status .DELETE_ON_ERROR: all: verify -verify: mempool.s9pk $(S9PK_PATH) - embassy-sdk verify s9pk $(S9PK_PATH) +verify: $(PKG_ID).s9pk + embassy-sdk verify s9pk $(PKG_ID).s9pk -install: mempool.s9pk - embassy-cli package install mempool.s9pk - -mempool.s9pk: manifest.yaml assets/utils/* image.tar docs/instructions.md scripts/embassy.js - embassy-sdk pack - -instructions.md: README.md - cp README.md instructions.md - -image.tar: Dockerfile docker_entrypoint.sh assets/utils/* $(MEMPOOL_GIT_FILE) - DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --tag start9/mempool/main:${EMVER} --platform=linux/arm64/v8 -o type=docker,dest=image.tar -f ./Dockerfile . +install: $(PKG_ID).s9pk + embassy-cli package install $(PKG_ID).s9pk clean: - rm -f mempool.s9pk + rm -rf docker-images rm -f image.tar - rm scripts/embassy.js + rm -f $(PKG_ID).s9pk + rm -f scripts/*.js -scripts/embassy.js: scripts/**/*.ts - deno cache --reload scripts/embassy.ts +scripts/embassy.js: $(TS_FILES) deno bundle scripts/embassy.ts scripts/embassy.js + +docker-images/x86_64.tar: Dockerfile docker_entrypoint.sh assets/utils/* + mkdir -p docker-images + docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --platform=linux/amd64 --build-arg PLATFORM=amd64 -o type=docker,dest=docker-images/x86_64.tar . + +docker-images/aarch64.tar: Dockerfile docker_entrypoint.sh assets/utils/* + mkdir -p docker-images + docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --platform=linux/arm64 --build-arg PLATFORM=arm64 -o type=docker,dest=docker-images/aarch64.tar . + +$(PKG_ID).s9pk: manifest.yaml instructions.md LICENSE icon.png scripts/embassy.js docker-images/aarch64.tar docker-images/x86_64.tar + if ! [ -z "$(ARCH)" ]; then cp docker-images/$(ARCH).tar image.tar; fi + embassy-sdk pack diff --git a/assets/utils/check-synced.sh b/assets/utils/check-synced.sh index c8c25ce..a884790 100644 --- a/assets/utils/check-synced.sh +++ b/assets/utils/check-synced.sh @@ -2,6 +2,8 @@ set -e +sleep 15 + b_type=$(yq e '.bitcoind.type' /root/start9/config.yaml) if [ "$b_type" = "internal" ]; then b_host="bitcoind.embassy" diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index b5fe48e..10e37ec 100755 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -41,7 +41,7 @@ fi sed -i "s/CORE_RPC_HOST:=127.0.0.1/CORE_RPC_HOST:=$bitcoind_host/" start.sh sed -i "s/CORE_RPC_USERNAME:=mempool/CORE_RPC_USERNAME:=$bitcoind_user/" start.sh sed -i "s/CORE_RPC_PASSWORD:=mempool/CORE_RPC_PASSWORD:=$bitcoind_pass/" start.sh -if [ "$(yq ".enable-electrs" /root/start9/config.yaml)" = "true" ]; then +if [ "$(yq e ".enable-electrs" /root/start9/config.yaml)" = "true" ]; then sed -i 's/ELECTRUM_HOST:=127.0.0.1/ELECTRUM_HOST:=electrs.embassy/' start.sh sed -i 's/ELECTRUM_PORT:=50002/ELECTRUM_PORT:=50001/' start.sh else diff --git a/docs/instructions.md b/instructions.md similarity index 100% rename from docs/instructions.md rename to instructions.md diff --git a/manifest.yaml b/manifest.yaml index 0dfd615..0d57583 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,7 +1,8 @@ id: mempool title: Mempool -version: 2.4.0.2 -release-notes: Fix migrations to ensure successful updates to the latest version +version: 2.4.0.3 +release-notes: | + * Updated Mempool to run x86_64 architecture license: AGPL wrapper-repo: "https://github.com/Start9Labs/mempool-wrapper" upstream-repo: "https://github.com/mempool/mempool" @@ -15,12 +16,11 @@ description: assets: license: LICENSE icon: icon.png - instructions: docs/instructions.md - docker-images: image.tar + instructions: instructions.md main: type: docker image: main - entrypoint: "docker_entrypoint.sh" + entrypoint: docker_entrypoint.sh args: [] mounts: main: /root @@ -28,14 +28,7 @@ health-checks: web-ui: name: Web Interface success-message: The Mempool UI is ready to visit in a web browser - type: docker - image: main - system: false - entrypoint: health-check.sh - args: ["web"] - mounts: {} - io-format: json - inject: true + type: script api: name: API success-message: The Mempool API is reachable and responsive. @@ -43,10 +36,10 @@ health-checks: image: main system: false entrypoint: health-check.sh + inject: true args: ["api"] mounts: {} io-format: json - inject: true synced: name: Transaction Indexer success-message: Bitcoin is fully indexed. You may now launch Mempool. @@ -54,10 +47,10 @@ health-checks: image: main system: false entrypoint: check-synced.sh + inject: true args: ["sync"] mounts: {} io-format: json - inject: true config: get: type: script @@ -67,7 +60,7 @@ properties: type: script dependencies: bitcoind: - version: ">=0.21.1.2 <24.0.0" + version: ">=0.21.1.2 <26.0.0" requirement: type: "opt-out" how: Can alternatively configure proxy or bitcoin core node. @@ -78,7 +71,7 @@ dependencies: auto-configure: type: script btc-rpc-proxy: - version: ">=0.3.2.1 <0.4.0" + version: ">=0.3.2.5 <0.4.0" requirement: type: "opt-in" how: Can alternatively configure proxy or bitcoin core node. @@ -149,23 +142,6 @@ migrations: from: "*": type: script - # @TODO the reason this migration is here and not in scripts is due to this possible OS bug: https://github.com/Start9Labs/embassy-os/pull/1663. When an eOS version is released with this fix, adjust this migration to type:script, uncomment the downgrade code in scripts/migrations.ts, delete scripts/migrations/2_3_1_4_down_temp.sh and remove it from the Dockerfile. to: - "<2.3.1.4": - type: docker - image: main - entrypoint: /usr/local/bin/migrations/2_3_1_4_down_temp.sh - args: [] - io-format: json - mounts: - main: /root - inject: false - ">=2.3.1.4": - type: docker - image: main - entrypoint: sh - args: ["-c", 'json=''{"configured": true }'' && echo "$json"'] - io-format: json - mounts: - main: /root - inject: false + "*": + type: script diff --git a/scripts/deps.ts b/scripts/deps.ts index 7066280..2f274d9 100644 --- a/scripts/deps.ts +++ b/scripts/deps.ts @@ -1,2 +1,4 @@ -export * from "https://deno.land/x/embassyd_sdk@v0.3.1.0.6/mod.ts"; +export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.4/mod.ts"; +export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.4/util.ts"; +export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.4/healthUtil.ts"; export * from "https://deno.land/x/embassyd_sdk@v0.3.1.0.12/emvar-lite/mod.ts"; \ No newline at end of file diff --git a/scripts/embassy.ts b/scripts/embassy.ts index 7c248ad..534239b 100644 --- a/scripts/embassy.ts +++ b/scripts/embassy.ts @@ -2,4 +2,6 @@ export { setConfig } from "./services/setConfig.ts"; export { properties } from "./services/properties.ts"; export { getConfig } from "./services/getConfig.ts"; export { dependencies } from "./services/dependencies.ts"; -export { migration } from "./services/migrations.ts"; \ No newline at end of file +export { migration } from "./services/migrations.ts"; +export { health } from "./services/healthChecks.ts"; +// export { main } from "./services/main.ts"; \ No newline at end of file diff --git a/scripts/migrations/2_3_1_4_down_temp.sh b/scripts/migrations/2_3_1_4_down_temp.sh deleted file mode 100644 index 08c477a..0000000 --- a/scripts/migrations/2_3_1_4_down_temp.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -ea - yq -i 'del(."enable-electrs")' /root/start9/config.yaml - echo '{"configured": true }' - exit 0 -fi diff --git a/scripts/services/healthChecks.ts b/scripts/services/healthChecks.ts new file mode 100644 index 0000000..bb2e137 --- /dev/null +++ b/scripts/services/healthChecks.ts @@ -0,0 +1,8 @@ +import { types as T, checkWebUrl, catchError } from "../deps.ts"; + +export const health: T.ExpectedExports.health = { + // deno-lint-ignore require-await + async "web-ui"(effects, duration) { + return checkWebUrl("http://mempool.embassy:8080")(effects, duration).catch(catchError(effects)) + }, +}; \ No newline at end of file diff --git a/scripts/services/main.ts b/scripts/services/main.ts new file mode 100644 index 0000000..33e809f --- /dev/null +++ b/scripts/services/main.ts @@ -0,0 +1,11 @@ +// import { types as T, util } from "../deps.ts"; + +// export const main: T.ExpectedExports.main = async (effects) => { +// await effects.runDaemon( +// { +// command: "docker_entrypoint.sh", +// args: [], +// }, +// ).wait(); +// return util.ok; +// }; \ No newline at end of file diff --git a/scripts/services/migrations.ts b/scripts/services/migrations.ts index f62e084..f1fdda0 100644 --- a/scripts/services/migrations.ts +++ b/scripts/services/migrations.ts @@ -10,12 +10,11 @@ export const migration: T.ExpectedExports.migration = async (effects, version) = return result } - // @TODO uncomment below and change to migration in manifest to type: script when eOS bugfix is released to production: https://github.com/Start9Labs/embassy-os/pull/1663 // to migrations (downgrades) - // if (rangeOf('>2.3.1.4').check(version)) { - // const result = await migration_down_2_3_1_4(effects, version) - // return result - // } + if (rangeOf('>2.3.1.4').check(version)) { + const result = await migration_down_2_3_1_4(effects, version) + return result + } return { result: { configured: true } }