@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
57 lines (55 loc) • 3.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDockerAppCopyAndBuildScript = exports.getYarnInstall = exports.ensureNodeVersion = void 0;
const BashExpression_1 = require("../../bash/BashExpression");
const utils_1 = require("../../utils");
const gitlab_1 = require("../../utils/gitlab");
const YARN_INSTALL_CLASSIC = `yarn install --frozen-lockfile`;
const YARN_BERRY_PROD_INSTALL = `yarn workspaces focus --production`;
// FIXME: check why and when rebuild is needed
const YARN_BERRY_PROD_REBUILD = `yarn rebuild`;
const getYarnInstallCommand = async context => {
const packageManagerInfo = await context.packageManagerInfo;
if (packageManagerInfo.isClassic) {
return YARN_INSTALL_CLASSIC;
}
// inline builds make debugging easier as it prints it out in the logs, instead of writing it in temp files
return `yarn install --immutable --inline-builds`;
};
const ensureNodeVersion = context => (0, gitlab_1.collapseableSection)("nodeinstall", "Ensure node version")(["if [ -f ~/.nvm/nvm.sh ]; then source ~/.nvm/nvm.sh; fi", "if command -v nvm &> /dev/null && [ -f ./.nvmrc ]; then nvm install; fi"]);
exports.ensureNodeVersion = ensureNodeVersion;
const getYarnInstall = async (context, options) => {
const postInstall = context.type !== "workspace" && context.build.type !== "disabled" && "postInstall" in context.build.config ? context.build.config.postInstall : null;
return [...(0, exports.ensureNodeVersion)(context), ...(0, gitlab_1.collapseableSection)("yarninstall", "Yarn install")([await getYarnInstallCommand(context)]), ...(postInstall && !(options === null || options === void 0 ? void 0 : options.noCustomPostInstall) ? (0, gitlab_1.collapseableSection)("postinstall", "Custom post install")((0, utils_1.ensureArray)(postInstall)) : [])];
};
exports.getYarnInstall = getYarnInstall;
const DOCKER_COPY_FILES = `COPY --chown=node:node $APP_DIR .`;
const getDockerAppCopyAndBuildScript = async context => {
var _a, _b, _c;
const packageManagerInfo = await context.packageManagerInfo;
if (packageManagerInfo.isClassic) {
return new BashExpression_1.BashExpression(`
RUN ${YARN_INSTALL_CLASSIC} --production --ignore-scripts
${DOCKER_COPY_FILES}
RUN ${YARN_INSTALL_CLASSIC} --production
`.trim());
}
const yarnRebuildEnabledDefault = context.build.type === "fromWorkspace" ? (_b = (_a = context.build.workspaceBuildConfig.dockerDefaults) === null || _a === void 0 ? void 0 : _a.yarnRebuildEnabled) !== null && _b !== void 0 ? _b : true : true;
const yarnRebuildEnabled = "docker" in context.build.config && context.build.config.docker && "yarnRebuildEnabled" in context.build.config.docker ? (_c = context.build.config.docker.yarnRebuildEnabled) !== null && _c !== void 0 ? _c : yarnRebuildEnabledDefault : yarnRebuildEnabledDefault;
// yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253
// trying to import those fail on this version
const doesNotShipWithBuiltInPlugins = ["2", "3"].some(v => packageManagerInfo.version.startsWith(v));
const maybeAddWorkspaceToolsCommand = doesNotShipWithBuiltInPlugins ? "RUN yarn plugin import workspace-tools" : "";
// copy first everything and then install
// rebuild first does not work as it will run postinstall and that might require files in the app
return new BashExpression_1.BashExpression(`
ENV YARN_ENABLE_INLINE_BUILDS=1
${DOCKER_COPY_FILES}
${maybeAddWorkspaceToolsCommand}
RUN ${YARN_BERRY_PROD_INSTALL}
${yarnRebuildEnabled ? `RUN ${YARN_BERRY_PROD_REBUILD}` : ""}
`.trim());
};
exports.getDockerAppCopyAndBuildScript = getDockerAppCopyAndBuildScript;