From b768ca99734b4bf832b22a4e0887c853c9039246 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 15 Sep 2021 12:50:22 +0200 Subject: [PATCH] fix transitioning to cli command --- packages/health-check/Dockerfile | 7 +++++-- packages/health-check/{ => bin}/cli | 13 ++++++++----- packages/health-check/cli/disable | 3 +++ packages/health-check/cli/enable | 3 +++ packages/health-check/cli/run | 3 +++ setup-scripts/setup-docker-services.sh | 2 +- 6 files changed, 23 insertions(+), 8 deletions(-) rename packages/health-check/{ => bin}/cli (87%) create mode 100755 packages/health-check/cli/disable create mode 100755 packages/health-check/cli/enable create mode 100755 packages/health-check/cli/run diff --git a/packages/health-check/Dockerfile b/packages/health-check/Dockerfile index 9ce4068d..bb4e1a05 100644 --- a/packages/health-check/Dockerfile +++ b/packages/health-check/Dockerfile @@ -4,11 +4,13 @@ RUN apk update && apk add dnsmasq WORKDIR /usr/app +ENV PATH="/usr/app/bin:${PATH}" + # schedule critical checks to run every 5 minutes (any failures will disable server) -RUN echo '*/5 * * * * /usr/app/cli/run critical > /dev/stdout' >> /etc/crontabs/root +RUN echo '*/5 * * * * /usr/app/bin/cli run critical > /dev/stdout' >> /etc/crontabs/root # schedule extended checks to run on every hour (optional checks, report only) -RUN echo '0 * * * * /usr/app/cli/run extended > /dev/stdout' >> /etc/crontabs/root +RUN echo '0 * * * * /usr/app/bin/cli run extended > /dev/stdout' >> /etc/crontabs/root COPY package.json yarn.lock ./ @@ -16,6 +18,7 @@ RUN yarn --frozen-lockfile COPY src src COPY cli cli +COPY bin bin EXPOSE 3100 ENV NODE_ENV production diff --git a/packages/health-check/cli b/packages/health-check/bin/cli similarity index 87% rename from packages/health-check/cli rename to packages/health-check/bin/cli index 8e7ee861..176ed23c 100755 --- a/packages/health-check/cli +++ b/packages/health-check/bin/cli @@ -3,12 +3,15 @@ process.env.NODE_ENV = process.env.NODE_ENV || "production"; require("yargs/yargs")(process.argv.slice(2)) + .help() + .demandCommand() + .strict(true) .command( "enable", "Mark portal as enabled", () => {}, () => { - const db = require("./src/db"); + const db = require("../src/db"); db.set("disabled", false).write(); } @@ -18,7 +21,7 @@ require("yargs/yargs")(process.argv.slice(2)) "Mark portal as disabled (provide meaningful reason)", () => {}, ({ reason }) => { - const db = require("./src/db"); + const db = require("../src/db"); db.set("disabled", reason).write(); } @@ -49,9 +52,9 @@ require("yargs/yargs")(process.argv.slice(2)) process.env.STATE_DIR = stateDir; const util = require("util"); - const { getYesterdayISOString } = require("./src/utils"); - const createMiddleware = require("./src/checks/middleware"); - const db = require("./src/db"); + const { getYesterdayISOString } = require("../src/utils"); + const createMiddleware = require("../src/checks/middleware"); + const db = require("../src/db"); const checks = require(`./src/checks/${type}`); const middleware = await createMiddleware(); diff --git a/packages/health-check/cli/disable b/packages/health-check/cli/disable new file mode 100755 index 00000000..ac83f874 --- /dev/null +++ b/packages/health-check/cli/disable @@ -0,0 +1,3 @@ +#!/bin/ash + +cli disable $@ diff --git a/packages/health-check/cli/enable b/packages/health-check/cli/enable new file mode 100755 index 00000000..f1687407 --- /dev/null +++ b/packages/health-check/cli/enable @@ -0,0 +1,3 @@ +#!/bin/ash + +cli enable $@ diff --git a/packages/health-check/cli/run b/packages/health-check/cli/run new file mode 100755 index 00000000..c8fd2ef0 --- /dev/null +++ b/packages/health-check/cli/run @@ -0,0 +1,3 @@ +#!/bin/ash + +cli run $0 diff --git a/setup-scripts/setup-docker-services.sh b/setup-scripts/setup-docker-services.sh index a616509d..679ca135 100755 --- a/setup-scripts/setup-docker-services.sh +++ b/setup-scripts/setup-docker-services.sh @@ -16,7 +16,7 @@ docker --version # sanity check sudo usermod -aG docker user # Install docker-compose -sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose --version # sanity check