Integration/3.2.1 (#40)

* updates

* db migration working

* prohibit downgrades

* update migrations

* update migrations
This commit is contained in:
Lucy 2025-04-21 20:34:40 -04:00 committed by GitHub
parent 89a7f34095
commit b9756f57eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 193 additions and 77 deletions

View File

@ -1,8 +1,6 @@
# Use a multi-stage build to combine the specific images
FROM mempool/frontend:v3.0.1 AS frontend
FROM mempool/backend:v3.0.1 AS backend
FROM mariadb:10.5.8 AS db
FROM node:lts-buster-slim AS runner
FROM mempool/frontend:v3.2.1 AS frontend
FROM mempool/backend:v3.2.1 AS backend
ENV MEMPOOL_CLEAR_PROTECTION_MINUTES="20"
ENV MEMPOOL_INDEXING_BLOCKS_AMOUNT="52560"
@ -18,36 +16,48 @@ ARG PLATFORM
ARG ARCH
# Install necessary packages
RUN apt-get update && \
apt-get install -y nginx wait-for-it wget curl netcat \
build-essential python3 pkg-config rsync gettext \
mariadb-server mariadb-client libaio1 iproute2 pwgen \
&& 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 \
&& apt-get clean
# RUN groupadd -r mysql && useradd -r -g mysql mysql
apt-get install -y --allow-downgrades nginx wait-for-it wget netcat-traditional \
build-essential python3 pkg-config rsync gettext iproute2 pwgen \
&& 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 \
&& apt-get clean
WORKDIR /patch
# Create mysql user and group
RUN groupadd -r mysql && useradd -r -g mysql mysql
# Install required base libraries
RUN apt-get update && \
apt-get install -y curl gnupg lsb-release ca-certificates libncurses5 libjemalloc2 socat
# Install libssl1.1 from Buster (needed by MariaDB 10.4)
RUN echo "deb http://archive.debian.org/debian buster main" > /etc/apt/sources.list.d/buster.list && \
echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until && \
apt-get update && \
apt-get install -y libssl1.1
# Install MariaDB 10.4 via .deb packages
RUN set -eux; \
export MARIADB_VERSION=10.4.32; \
export DISTRO=deb10; \
export BASE_URL=https://archive.mariadb.org/mariadb-${MARIADB_VERSION}/repo/debian/pool/main/m/mariadb-10.4; \
mkdir -p /tmp/mariadb && cd /tmp/mariadb && \
curl -LO ${BASE_URL}/mariadb-common_${MARIADB_VERSION}+maria~${DISTRO}_all.deb && \
curl -LO ${BASE_URL}/libmariadb3_${MARIADB_VERSION}+maria~${DISTRO}_${PLATFORM}.deb && \
curl -LO ${BASE_URL}/mariadb-client-core-10.4_${MARIADB_VERSION}+maria~${DISTRO}_${PLATFORM}.deb && \
curl -LO ${BASE_URL}/mariadb-client-10.4_${MARIADB_VERSION}+maria~${DISTRO}_${PLATFORM}.deb && \
curl -LO ${BASE_URL}/mariadb-server-core-10.4_${MARIADB_VERSION}+maria~${DISTRO}_${PLATFORM}.deb && \
curl -LO ${BASE_URL}/mariadb-server-10.4_${MARIADB_VERSION}+maria~${DISTRO}_${PLATFORM}.deb && \
dpkg -i *.deb || apt-get install -f -y && \
apt-mark hold mariadb-server mariadb-client && \
rm -rf /var/lib/apt/lists/* /tmp/mariadb
# Copy frontend files
COPY --from=frontend /patch/entrypoint.sh .
COPY --from=frontend /patch/wait-for .
COPY --from=frontend /patch/entrypoint.sh /patch/entrypoint.sh
COPY --from=frontend /patch/wait-for /patch/wait-for
COPY --from=frontend /var/www/mempool /var/www/mempool
COPY --from=frontend /etc/nginx/nginx.conf /etc/nginx/
COPY --from=frontend /etc/nginx/conf.d/nginx-mempool.conf /etc/nginx/conf.d/
WORKDIR /backend
# Copy backend files
COPY --from=backend /backend/package ./package/
COPY --from=backend /backend/GeoIP ./GeoIP/
COPY --from=backend /backend/mempool-config.json /backend/start.sh /backend/wait-for-it.sh ./
# Create data folder for cache and MySQL data
RUN mkdir -p /build/data/cache /var/lib/mysql/data
# Set user and group for the folders
RUN chown -R mysql:mysql /build/data /var/lib/mysql/data
# BUILD S9 CUSTOM
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
ADD assets/utils/*.sh /usr/local/bin/

View File

@ -75,25 +75,28 @@ else
fi
# DATABASE SETUP
if [ -d "/run/mysqld" ]; then
MYSQL_DATADIR="/var/lib/mysql"
UPGRADE_MARKER="$MYSQL_DATADIR/.upgrade_done"
MYSQL_DIR="/var/run/mysqld"
MYSQL_SOCKET="$MYSQL_DIR/mysqld.sock"
if [ -d "$MYSQL_DIR" ]; then
echo "[i] mysqld already present, skipping creation"
chown -R mysql:mysql /run/mysqld
chown -R mysql:mysql $MYSQL_DIR
else
echo "[i] mysqld not found, creating...."
mkdir -p /run/mysqld
chown -R mysql:mysql /run/mysqld
mkdir -p $MYSQL_DIR
chown -R mysql:mysql $MYSQL_DIR
fi
if [ -d /var/lib/mysql/mysql ]; then
echo "[i] MySQL directory already present, skipping creation"
chown -R mysql:mysql /var/lib/mysql
else
echo "[i] MySQL data directory not found, creating initial DBs"
mkdir -p /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
mysql_install_db --user=mysql --ldata=/var/lib/mysql > /dev/null
# Initialize the database if not already initialized
if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
echo "Initializing MariaDB data directory..."
mariadb-install-db --user=mysql --datadir="$MYSQL_DATADIR" > /dev/null
chown -R mysql:mysql "$MYSQL_DATADIR"
chmod -R 755 "$MYSQL_DATADIR"
touch "$UPGRADE_MARKER" # Skip upgrade on initial boot
if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then
MYSQL_ROOT_PASSWORD=`pwgen 16 1`
@ -151,7 +154,36 @@ EOF
echo
fi
/usr/bin/mysqld_safe --user=mysql --datadir='/var/lib/mysql' &
chown -R mysql:mysql "$MYSQL_DATADIR"
chmod -R 755 "$MYSQL_DATADIR"
# Run mysql_upgrade once
if [ -d "$MYSQL_DATADIR/mysql" ] && [ ! -f "$UPGRADE_MARKER" ]; then
echo "Starting MariaDB for upgrade..."
mariadbd --user=mysql --datadir="$MYSQL_DATADIR" --skip-grant-tables &
# Wait for server to start up
echo "Waiting for MariaDB to start..."
until mysqladmin -u root ping; do
sleep 2
done
# Switch to unix socket for auth
mysql --socket="$MYSQL_SOCKET" <<EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED VIA unix_socket;
ALTER USER 'root'@'%' IDENTIFIED VIA unix_socket;
FLUSH PRIVILEGES;
EOF
echo "Running mysql_upgrade..."
mysql_upgrade -u root --protocol=SOCKET --socket=/run/mysqld/mysqld.sock
touch "$UPGRADE_MARKER"
echo "Shutting down MariaDB post upgrade..."
mysqladmin -u root shutdown
else
echo "No upgrade needed or already completed."
fi
# Start MariaDB
mariadbd --user=mysql --datadir="$MYSQL_DATADIR" &
db_process=$!
# START UP

View File

@ -1,8 +1,10 @@
id: mempool
title: Mempool
version: 3.0.1
version: 3.2.1
release-notes: |
* Updates upstream, which includes a fix to save CPU on lower powered hardware
* Updates to latest upstream [release](https://github.com/mempool/mempool/releases/tag/v3.2.1)
* Hotfix for the latest release [v3.2.0](https://github.com/mempool/mempool/releases/tag/v3.2.0), which includes some awesome new features, such as Stratum job data visualizations, DATUM miner tags, and support for v3 transactions.
* Updates MariaDB to next minor version
license: AGPL
wrapper-repo: "https://github.com/Start9Labs/mempool-wrapper"
upstream-repo: "https://github.com/mempool/mempool"
@ -166,8 +168,10 @@ migrations:
from:
"<2.3.1.4":
type: script
args: ["from"]
">=2.3.1.4 <2.5.0":
type: script
args: ["from"]
">=2.5.0 <=3.0.0.3":
type: docker
image: main
@ -175,16 +179,19 @@ migrations:
entrypoint: /usr/local/bin/migrations/gt_2_5_0_lt_3_0_0_2.sh
args: ["from"]
io-format: json
mounts:
mounts:
main: /root
inject: false
">3.0.0.3":
type: script
args: ["from"]
to:
"<2.3.1.4":
type: script
args: ["to"]
">=2.3.1.4 <2.5.0":
type: script
args: ["to"]
">=2.5.0 <=3.0.0.3":
type: docker
image: main
@ -192,8 +199,9 @@ migrations:
entrypoint: /usr/local/bin/migrations/gt_2_5_0_lt_3_0_0_2.sh
args: ["to"]
io-format: json
mounts:
mounts:
main: /root
inject: false
">3.0.0.3":
type: script
args: ["to"]

View File

@ -11,7 +11,7 @@ const matchLightningType = shape({
export const migration_up_2_5_0: T.ExpectedExports.migration = async (
effects,
_version,
_version
) => {
try {
await effects.createDir({

View File

@ -1,33 +1,99 @@
import { types as T, rangeOf } from "../deps.ts"
import { migration_down_2_3_1_4 } from "../migrations/2_3_1_4_down_migration.ts";
import { migration_up_2_3_1_4 } from "../migrations/2_3_1_4_up_migration.ts";
import { migration_down_2_5_0 } from "../migrations/2_5_0_down_migration.ts";
import { migration_up_2_5_0 } from "../migrations/2_5_0_up_migration.ts";
import { types as T, compat, matches } from "../deps.ts";
export const migration: T.ExpectedExports.migration = async (effects, version) => {
const { shape, boolean, string } = matches;
// from migrations (upgrades)
if (rangeOf('<2.3.1.4').check(version)) {
const result = await migration_up_2_3_1_4(effects, version)
return result
}
const current = "3.2.1";
if (rangeOf('<2.5.0').check(version)) {
const result = await migration_up_2_5_0(effects, version)
return result
}
// 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.5.0').check(version)) {
const result = await migration_down_2_5_0(effects, version)
return result
}
return { result: { configured: true } }
}
export const migration: T.ExpectedExports.migration = (
effects: T.Effects,
version: string,
...args: unknown[]
) => {
return compat.migrations.fromMapping(
{
"2.3.1.4": {
up: compat.migrations.updateConfig(
(config) => {
const matchElectrs = shape({
"enable-electrs": boolean,
});
if (!matchElectrs.test(config)) {
config["enable-electrs"] = true;
return config;
}
return config;
},
false,
{ version: "2.3.1.4", type: "up" }
),
down: compat.migrations.updateConfig(
(config) => {
const matchElectrs = shape(
{
"enable-electrs ": boolean,
},
["enable-electrs "]
);
if (matchElectrs.test(config)) {
delete config["enable-electrs "];
return config;
}
return config;
},
true,
{ version: "2.3.1.4", type: "down" }
),
},
"2.5.0": {
up: compat.migrations.updateConfig(
(config) => {
const matchLightningType = shape({
lightning: shape({
type: string,
}),
});
if (!matchLightningType.test(config)) {
(config as typeof matchLightningType._TYPE).lightning.type =
"lnd";
return config;
}
return config;
},
false,
{ version: "2.5.0", type: "up" }
),
down: compat.migrations.updateConfig(
(config) => {
const matchLightningType = shape({
lightning: shape({
type: string?.optional(),
}),
});
if (matchLightningType.test(config)) {
if (config.lightning) {
delete config.lightning["type"];
return config;
}
}
return config;
},
true,
{ version: "2.5.0", type: "down" }
),
},
"3.2.1": {
up: compat.migrations.updateConfig(
(config) => {
return config;
},
true,
{ version: "3.2.1", type: "up" }
),
down: () => {
throw new Error("Downgrades are prohibited from this version");
},
},
},
current
)(effects, version, ...args);
};