@abgov/nx-oc

中文文档
13.12.2发布于 2026/09/24Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 2201

Government of Alberta - Nx plugin for OpenShift.

原始使用文档
文档目录13 节
  1. Prerequisites
  2. Installation
  3. Quick Start
  4. Generators
  5. pipeline
  6. apply-infra
  7. deployment
  8. Executor: apply
  9. Options
  10. Sandbox deployment (local build)
  11. Typical workflow
  12. Production pipeline
  13. Sandbox iteration

@abgov/nx-oc

Nx plugin for generating and applying OpenShift manifests for Government of Alberta applications.

The plugin provides generators for CI/CD pipeline setup and per-application deployment configuration, and an executor for running oc apply against an OpenShift cluster.

Prerequisites

  • OpenShift CLI (oc) installed and on PATH
  • An active OpenShift login: oc login <url> --token=<token>
  • Separate OpenShift projects provisioned for build infrastructure and each runtime environment (dev, test, prod)

Installation

npm i -D @abgov/nx-oc

Quick Start

# 1. Create workspace and install plugin
npx create-nx-workspace my-workspace
npm i -D @abgov/nx-oc

# 2. Login to OpenShift
oc login <url> --token=<token>

# 3. Generate pipeline infrastructure manifests
npx nx g @abgov/nx-oc:pipeline my-pipeline \
  --infra my-infra-project \
  --envs "my-dev my-test my-prod" \
  --registry ghcr.io/my-org

# 4. Apply the generated infrastructure manifests to the cluster
npx nx g @abgov/nx-oc:apply-infra

# 5. Add deployment manifests to each application
npx nx g @abgov/nx-oc:deployment my-app --appType node --env dev

Generators

pipeline

Generates OpenShift manifests for a CI/CD pipeline, including shared build infrastructure resources used across all environments.

npx nx g @abgov/nx-oc:pipeline my-pipeline \
  --infra my-infra-project \
  --envs "my-dev my-test my-prod" \
  --registry ghcr.io/my-org \
  --type actions
OptionAliasRequiredDescription
pipeline—YesName of the OpenShift pipeline
infra-iYesOpenShift project name used for build infrastructure
envs-eYesSpace-separated names of the OpenShift environment projects (e.g., "my-dev my-test my-prod")
registry-rYesContainer registry to publish images to (e.g., ghcr.io/my-org)
type-tNoPipeline type: actions (default) or jenkins
apply-aNoApply the generated manifests to OpenShift immediately after generation

apply-infra

Applies the OpenShift infrastructure manifests that were generated by pipeline. Takes no options — reads the generated pipeline configuration from the workspace.

npx nx g @abgov/nx-oc:apply-infra

Use apply-infra as a follow-up to pipeline when you want to defer cluster provisioning, or as a re-apply step after editing the generated manifests.


deployment

Adds OpenShift deployment manifests (Deployment, Service, Route, etc.) to an existing Nx project for a specific environment.

npx nx g @abgov/nx-oc:deployment my-app --appType node --env dev
OptionAliasRequiredDescription
project—YesName of the existing Nx project to add deployment manifests to
appType-tYesApplication type: frontend, dotnet, or node
env-eYesADSP environment: dev, test, or prod
accessToken-atNoAccess token for non-interactive retrieval of ADSP configuration

Run the generator once per environment per application. For a typical three-environment setup, run it three times with --env dev, --env test, and --env prod.

deployment writes .openshift/<project>/<project>.yml; sandbox writes .openshift/<project>/<project>.sandbox.yml alongside it and shares the same .openshift/<project>/Dockerfile (identical either way). A project can have both — a real CI-driven pipeline deployment and a sandbox for local experimentation — at the same time; running one never touches the other's manifest. Every object either renders also carries a deployment-mode: pipeline/sandbox label (alongside the existing app label), so the teardown-<env> and sandbox-teardown targets' label-selector deletes can never remove the other mode's resources even if they ever land in the same namespace.


Executor: apply

Runs oc apply to deploy an application's OpenShift manifests. Configure it as a target in the project's project.json:

{
  "targets": {
    "deploy": {
      "executor": "@abgov/nx-oc:apply",
      "options": {
        "ocProject": "my-dev-project"
      }
    }
  }
}

Then run:

npx nx run my-app:deploy

Options

OptionRequiredDescription
ocProjectYesOpenShift project(s) to apply manifests to

ocProject accepts three forms:

// Single project
{ "ocProject": "my-dev" }

// Multiple projects
{ "ocProject": ["my-dev", "my-test"] }

// Tagged deployments
{ "ocProject": [{ "project": "my-dev", "tag": "v1.2.3" }] }

Sandbox deployment (local build)

For rapid iteration, the sandbox generator wires a per-app deploy that builds the image locally with podman, pushes it to a container registry (GHCR), and imports it into your OpenShift namespace — no git push or CI wait. (Requires the Nx 23 line, @abgov/nx-oc 13.x.)

sandbox writes .openshift/<project>/<project>.sandbox.yml, alongside deployment's .openshift/<project>/<project>.yml — the two share the same .openshift/<project>/Dockerfile (identical either way) but never touch each other's manifest. A project can have both — a real CI-driven pipeline deployment and a sandbox for local experimentation — at the same time.

# Add the sandbox targets to a project (run once per app)
npx nx g @abgov/nx-oc:sandbox my-app --sandboxProject=<namespace> --registry=ghcr.io/<org>

# Build → podman → push → import → roll out
npx nx run my-app:sandbox

# Tear down the sandbox resources + delete the pushed image
npx nx run my-app:sandbox-teardown

Prerequisites: podman (machine started on macOS), oc logged in to the cluster, and gh authenticated as an account with write:packages on the registry org (the deploy reads gh auth token for the push and pull secret — no PAT is stored, so that account must be the active gh account).

The deploy is the @abgov/nx-oc:sandbox executor, so its logic is versioned in the plugin (fixes reach every project on npm update). It:

  • preflights oc/gh/podman and fails fast with actionable messages before the build;
  • retries oc import-image to absorb the oc tag reconcile race;
  • auto-detects the database (from an adsp:database:* project tag, or a drizzle db:migrate target) and provisions a shared Postgres/Mongo instance + the per-app database + migrate init container — no --database flag needed;
  • for a frontend, ensures each paired backend's Service exists and warns if the backend has no running pods (proxied /api calls would 502); pass --deployBackend to deploy the backend in the same run;
  • supports --skipBuild / --skipPush to resume a partial deploy.

Running the generator also writes .openshift/<app>/SANDBOX.md — a deploy/troubleshooting runbook (preflight fixes, resume flags, a manual-completion sequence, quota/auth/CrashLoopBackOff guidance).


Typical workflow

Production pipeline

  1. Run pipeline once per workspace to generate shared build infrastructure manifests.
  2. Run apply-infra (or pass --apply to pipeline) to provision the resources on the cluster.
  3. Run deployment for each application and environment combination.
  4. Add an apply executor target to each application's project.json.
  5. In your GitHub Actions or Jenkins pipeline, call npx nx run my-app:deploy to apply manifests during CI/CD.

Sandbox iteration

  1. Run sandbox for each application, passing --sandboxProject and --database as needed.
  2. Run npx nx run my-app:sandbox to build, push, and deploy. Repeat on every change.

版本与发布记录

@abgov/nx-oc 共发布 130 个版本,首次发布于 2021/03/30;过去 12 个月发布了 60 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
13.12.2latest2026/09/241 个月前
13.12.12026/09/111 个月前
13.12.02026/09/022 个月前
13.11.12026/09/022 个月前
13.11.02026/09/012 个月前
13.10.12026/08/252 个月前

其他发布通道:beta → 13.8.1-beta.2。

关于 @abgov/nx-oc 的常见问题

@abgov/nx-oc 是什么?

Government of Alberta - Nx plugin for OpenShift.

如何安装 @abgov/nx-oc?

在项目目录运行 npm install @abgov/nx-oc,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:tslib(^2.0.0)、@nx/devkit(^23.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@abgov/nx-oc 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@abgov/nx-oc 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@abgov/nx-oc 可以商用吗?

@abgov/nx-oc 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@abgov/nx-oc 的下载量有多少?

根据 npm 官方下载统计,@abgov/nx-oc 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,201 次,日均约 73 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@abgov/nx-oc 还在维护吗?

最新版本 13.12.2 发布于 2026/09/24(1 个月前);至今共发布 130 个版本,其中过去 12 个月发布了 60 个;首次发布于 2021/03/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。