跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Node.js] 分享一下在 node.js 项目里打包 docker 镜像的小技巧.

发表于

在实际的项目开发时,打包 Docker 镜像,其实还是有些细节需要注意

例如,镜像的 name 、tag 如何更准确的表达当前代码的信息。

我认为,镜像的名字以这种格式会比较好 : 私有仓库/项目/产品-git 分支:时间-git hash

当然, 这个观点,大家可能有不同的意见,只是这个格式比较适合我们。

基于以上的想法, 可以在 package.json 的 scripts 里, 增加:

// package.json
{
    ...
    "scripts": {
        ...
        "build-img": "docker build -t registry.xxxxx.com/$(pwd | rev | cut -d / -f 1-2 - | rev)-$(git rev-parse --abbrev-ref HEAD):$(git log --pretty=%ad-%h --date=format:'%y%m%d%H%M' -n 1) ."
        ...
    }
    ...
}

使用时, 直接 npm run build-img 即可, 打包出来的镜像名称类似: registry.xxxxx.com/上级目录名/当前目录名-分支名:yyMMddmmss-hash

上面的脚本,其实有个关于代码目录的约定: 在项目的目录下,clone 各个 git 仓库的代码 .

通过上面这种方式打包镜像,好处是从镜像名称就能知道 这个镜像属于哪个项目,哪个产品,所属 git 分支,最后一次签入的时间和 hash (即代码的当前状态) 。

并且,只要代码没有变动(或者应该说,没有进行 git commit),任何时候从 仓库 clone 代码,再次打包镜像时,名称都是一致的。

简单来说, 可以保持镜像名称和 git 仓库的关系。

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.