Skip to content

Commit

Permalink
chore: report docker upgrade command correctly (#2745)
Browse files Browse the repository at this point in the history
  • Loading branch information
notnmeyer authored Feb 22, 2024
1 parent 76c0427 commit 87f5a7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
27 changes: 20 additions & 7 deletions projects/optic/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 87f5a7b

Please sign in to comment.