UNPKG

@catladder/pipeline

Version:

Panter workflow for cloud CI/CD and DevOps

79 lines (78 loc) 4.57 kB
"use strict"; var __read = this && this.__read || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = this && this.__spreadArray || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDockerAppCopyAndBuildScript = exports.getYarnInstall = exports.ensureNodeVersion = void 0; var BashExpression_1 = require("../../bash/BashExpression"); var utils_1 = require("../../utils"); var gitlab_1 = require("../../utils/gitlab"); var YARN_INSTALL_CLASSIC = "yarn install --frozen-lockfile"; var YARN_BERRY_PROD_INSTALL = "yarn workspaces focus --production"; // FIXME: check why and when rebuild is needed var YARN_BERRY_PROD_REBUILD = "yarn rebuild"; var getYarnInstallCommand = function (context) { if (context.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"; }; var ensureNodeVersion = function (context) { return (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; var getYarnInstall = function (context, options) { var postInstall = context.type !== "workspace" && context.build.type !== "disabled" && "postInstall" in context.build.config ? context.build.config.postInstall : null; return __spreadArray(__spreadArray(__spreadArray([], __read((0, exports.ensureNodeVersion)(context)), false), __read((0, gitlab_1.collapseableSection)("yarninstall", "Yarn install")([getYarnInstallCommand(context)])), false), __read(postInstall && !(options === null || options === void 0 ? void 0 : options.noCustomPostInstall) ? (0, gitlab_1.collapseableSection)("postinstall", "Custom post install")((0, utils_1.ensureArray)(postInstall)) : []), false); }; exports.getYarnInstall = getYarnInstall; var DOCKER_COPY_FILES = "COPY --chown=node:node $APP_DIR ."; var getDockerAppCopyAndBuildScript = function (context) { var _a, _b, _c; if (context.packageManagerInfo.isClassic) { return new BashExpression_1.BashExpression("\nRUN ".concat(YARN_INSTALL_CLASSIC, " --production --ignore-scripts\n").concat(DOCKER_COPY_FILES, "\nRUN ").concat(YARN_INSTALL_CLASSIC, " --production \n ").trim()); } var 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; var 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 var doesNotShipWithBuiltInPlugins = ["2", "3"].some(function (v) { return context.packageManagerInfo.version.startsWith(v); }); var 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("\n ENV YARN_ENABLE_INLINE_BUILDS=1\n".concat(DOCKER_COPY_FILES, "\n").concat(maybeAddWorkspaceToolsCommand, "\nRUN ").concat(YARN_BERRY_PROD_INSTALL, "\n").concat(yarnRebuildEnabled ? "RUN ".concat(YARN_BERRY_PROD_REBUILD) : "", "\n\n ").trim()); }; exports.getDockerAppCopyAndBuildScript = getDockerAppCopyAndBuildScript;