gpt4 book ai didi

node.js - 比特桶管道 : Adding NodeJS for Gulp on the microsoft/dotnet:sdk image

转载 作者:太空宇宙 更新时间:2023-11-04 10:03:58 25 4
gpt4 key购买 nike

我有一个 ASP.NET Core 应用程序。它使用 Gulp 将 Sass 转换为 CSS 等。我已经修改了我的 .csproj 文件,让 Gulp 任务在 publish 之前运行。这是为了确保我的所有 JS 和 CSS 都在工件中。

<Target Name="PrePublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="npm install" />
<Exec Command="gulp" />
</Target>

这是我的 BitBucket 管道文件:

pipelines:
branches:
master:
- step:
name: Build
image: microsoft/dotnet:sdk
caches:
- dotnetcore
script:
- export PROJECT_NAME=YeGods.sln
- dotnet restore
- dotnet build $PROJECT_NAME
- dotnet publish $PROJECT_NAME --configuration Release --output dist --verbosity minimal
artifacts:
- YeGods.Web/dist/**
- step:
name: Deploy
image: alpine:3.8
script:
- apk add --update openssh
- ssh deploy@$SERVER_HOST 'bash -s' < $BITBUCKET_CLONE_DIR/pre-deploy-script.sh
- scp -r YeGods.Web/dist/* deploy@$SERVER_HOST:$SERVER_PATH_TO_SITE_DIRECTORY
- ssh deploy@$SERVER_HOST 'bash -s' < $BITBUCKET_CLONE_DIR/post-deploy-script.sh

这目前失败了,因为 npm install 脚本调用失败,因为 microsoft/dotnet:sdk 图像中没有安装 NodeJS。我怀疑我所要做的就是在这个 - export PROJECT_NAME=YeGods.sln 之前的另一个脚本调用中安装 NodeJS。所以我添加了 apt-get install nodejs 但这没有用。它说找不到 nodejs

如果哪种思路是正确的,那么将 NodeJS 安装到 microsoft/dotnet:sdk 图像上的正确方法是什么?

最佳答案

I have an article on this exact issue ,这里是一个总结:

解决方案一:

您需要一个同时安装了 dotnet 和 Node 的 docker 镜像。这可以通过安装 nodejs 扩展来自微软的官方 dotnet 图像来轻松完成。但是您确实需要知道如何使用 docker。

如果您还没有学习 docker,这可能是一个很好的机会,网上有很多教程。

我之前这样做过,并将我的 docker 镜像上传到 docker hub,以便 Pipelines 可以使用它。它在 dockerhub 上公开可用,但你真的不应该使用不信任的人的图像,但如果你仍然想测试更改 image: microsoft/dotnet:sdkimage:peterekepeter/dotnet-node-sdk:最新

这是一个 Dockerfile 示例,说明如何获取 dotnet 镜像并在其上安装 nodejs:

FROM microsoft/dotnet:2-sdk

# install nodejs for building & testing frontend

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get -y install nodejs
RUN node -v

方案二:

将前端构建分离到一个单独的管道步骤,并在安装了 nodejs 的 docker 图像上运行 gulp 任务。如果您在这两个步骤之间建立了依赖关系,请使用工件持久化它们。

但要使其正常工作,您需要修改构建脚本,从 csproj 项目中删除 gulp 命令,并将它们作为管道脚本的一部分运行。

这是一个如何做到这一点的例子:

pipelines:
default:
- step:
name: .NET Core build & test
image: microsoft/dotnet:2-sdk
caches:
- dotnetcore
script:
- dotnet restore
- dotnet build --no-restore
- dotnet test --no-build --no-restore
- step:
name: Frontend build & test
image: node:6.9.4
caches:
- node
script:
- npm install
- npm run build
- npm run test

关于node.js - 比特桶管道 : Adding NodeJS for Gulp on the microsoft/dotnet:sdk image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53931174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com