From 87f5a7bc9ed2834673325684a1d945eeb3e116d0 Mon Sep 17 00:00:00 2001 From: Nate Meyer <672246+notnmeyer@users.noreply.github.com> Date: Thu, 22 Feb 2024 12:06:33 -0800 Subject: [PATCH] chore: report docker upgrade command correctly (#2745) --- Dockerfile | 1 + projects/optic/src/init.ts | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b6b3c29c2f..719cc8c5aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,5 @@ RUN apk --no-cache add git curl RUN echo "optic-docker" > /etc/machine-id RUN set -e; sh -c "$(curl -s --location https://install.useoptic.com/install.sh)" -- $OPTIC_CLI_VERSION /usr/local/bin +ENV INSTALLATION_METHOD="docker" ENTRYPOINT ["/usr/local/bin/optic"] diff --git a/projects/optic/src/init.ts b/projects/optic/src/init.ts index 9efda89fbd..de94d86083 100644 --- a/projects/optic/src/init.ts +++ b/projects/optic/src/init.ts @@ -35,17 +35,30 @@ import path from 'path'; const packageJson = require('../package.json'); -function getInstallMethod(): 'binary' | 'npm/yarn' { - return process.env.INSTALLATION_METHOD === 'binary' ? 'binary' : 'npm/yarn'; +type installMethod = 'binary' | 'npm/yarn' | 'docker'; +const allowedMethods = ['binary', 'npm/yarn', 'docker']; +function getInstallMethod(): installMethod { + if ( + process.env.INSTALLATION_METHOD !== undefined && + allowedMethods.includes(process.env.INSTALLATION_METHOD) + ) { + return process.env.INSTALLATION_METHOD as installMethod; + } + + return 'npm/yarn'; } const getInstallInstruction = (): string => { - if (getInstallMethod() === 'binary') { - const binDir = path.dirname(process.execPath); - return `sh -c "$(curl -s --location https://install.useoptic.com/install.sh)" -- latest ${binDir}`; - } else { - return 'npm i -g @useoptic/optic'; + const installMethod = getInstallMethod(); + + // TODO: distinguish between 'binary' and 'npm/yarn' installations + // vercel/pkg is deprecated. waiting on node's native packaging to explore this more + + if (installMethod === 'docker') { + return 'docker pull docker.io/useoptic/optic:latest'; } + + return 'npm i -g @useoptic/optic'; }; export const initCli = async (