将Angular应用部署到Azure静态Web应用,使用GitLab CI/CD流水线。

huangapple go评论59阅读模式
英文:

Deploying Angular app to Azure static web app from gitlab CI/CD pipeline

问题

我有一个在GitLab中的存储库,用于我的Angular应用程序。

我正在尝试使用Gitlab中的CI/CD将Angular应用程序部署到Azure静态Web应用程序。

我找不到与此相关的适当文档或博客,请注意,我不是DevOps专家,我是一名开发人员正在学习。

我尝试编写了用于构建和部署的.yml脚本,
构建成功了,但部署步骤有点棘手并且没有成功。

所以我遵循了Microsoft的这个链接:-

https://learn.microsoft.com/en-us/azure/static-web-apps/gitlab?tabs=angular

在遵循上述链接中提供的步骤之后,管道成功了,但出现了一些错误,比如

无法检测源目录中的任何平台。
错误:无法从存储库检测语言。
---Oryx构建日志的末尾---

任务成功,当我访问链接时,我看到一个空白的网页,但标签显示了项目的名称和图标(附上了一张图片)。

我在这里做错了什么?
我怀疑是应用程序路径,但不确定

这是我从链接中使用的.yml脚本,并进行了一些更改

阶段:
   - 构建
   - 部署

变量:
  API令牌:$ DEPLOYMENT_TOKEN
  APP_PATH:' $ CI_PROJECT_DIR / src'
  OUTPUT_PATH:' $ CI_PROJECT_DIR / dist / hero'

构建:
  阶段:构建
  图像:node:18.15.0-bullseye
  脚本:
    - npm安装
    - npm运行构建--prod
    - ls
  工件:
    路径:
      - $ OUTPUT_PATH

部署:
  阶段:部署
  图像:registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy
  脚本:
    - echo “应用程序成功部署。”
    - ls

以下是部署步骤中管道构建的一些日志:-

Azure Static Web Apps使用Oryx来构建静态应用程序和Azure函数。您可以在这里找到有关Oryx的更多详细信息:https://github.com/microsoft/Oryx
---Oryx构建日志---
Microsoft Oryx执行的操作,https://github.com/Microsoft/Oryx
您可以在https://github.com/Microsoft/Oryx/issues上报告问题
Oryx版本:0.2.20221103.1,提交:a2c65dde152b749fea395f4d1242ea9350942258,ReleaseTagName:20221103.1
构建操作ID:| RWFxHLm8/Jk=.8298183e_
存储库提交:eebef19bd060ae45bb50710be46a56b052fc83d4
检测平台...
无法检测源目录中的任何平台。
错误:无法从存储库检测语言。
---Oryx构建日志的末尾---
Oryx无法确定构建步骤。 继续假设此文件夹中的资产已经构建完毕。 如果这是意外的行为,请联系支持。
使用Oryx完成构建
未指定Api目录。 将不会创建Azure函数。
要么没有指定Api目录,要么指定的目录未找到。 Azure函数将不会创建。
压缩应用程序工件
已完成应用程序工件的压缩
上传构建工件。
完成上传。 在部署中轮询。
英文:

I have repository in GitLab for my angular application.

I'm trying to deploy Angular app to Azure Static Web App using CI/CD in Gitlab.

I'm not able to find a proper documentation or blog related to this, Please note I'm not a DevOps guy, I'm a developer trying to learn.

I tried writing the .yml script for build and deploy,
the build succeeded but the deploy step was somewhat tricky and did not succeed.

so followed this link from Microsoft :-

https://learn.microsoft.com/en-us/azure/static-web-apps/gitlab?tabs=angular

After following the steps provided in the above mentioned link
the pipeline succeeded but with some errors like this

Could not detect any platform in the source directory.
Error: Could not detect the language from repo.
---End of Oryx build logs---

the job succeeded & when I followed the link I see blank web page but with tab showing the name and icon of the project(attached an image).

What am I doing wrong here?
I suspected it to be the application path but not sure

Here is the .yml script I used from the link with some changes

stages:
   - build
   - deploy

variables:
  API_TOKEN: $DEPLOYMENT_TOKEN
  APP_PATH: '$CI_PROJECT_DIR/src'
  OUTPUT_PATH: '$CI_PROJECT_DIR/dist/hero'

build:
  stage: build
  image: node:18.15.0-bullseye
  script:
    - npm install
    - npm run build --prod
    - ls
  artifacts:
    paths:
      - $OUTPUT_PATH

deploy:
  stage: deploy
  image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy
  script:
    - echo "App deployed successfully."
    - ls

Here is some log of the pipeline build during deploy step:-

Azure Static Web Apps utilizes Oryx to build both static applications and Azure Functions. You can find more details on Oryx here: https://github.com/microsoft/Oryx
---Oryx build logs---
Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
You can report issues at https://github.com/Microsoft/Oryx/issues
Oryx Version: 0.2.20221103.1, Commit: a2c65dde152b749fea395f4d1242ea9350942258, ReleaseTagName: 20221103.1
Build Operation ID: |RWFxHLm8/Jk=.8298183e_
Repository Commit : eebef19bd060ae45bb50710be46a56b052fc83d4
Detecting platforms...
Could not detect any platform in the source directory.
Error: Could not detect the language from repo.
---End of Oryx build logs---
Oryx was unable to determine the build steps. Continuing assuming the assets in this folder are already built. If this is an unexpected behavior please contact support.
Finished building app with Oryx
No Api directory specified. Azure Functions will not be created.
Either no Api directory was specified, or the specified directory was not found. Azure Functions will not be created.
Zipping App Artifacts
Done Zipping App Artifacts
Uploading build artifacts.
Finished Upload. Polling on deployment.

将Angular应用部署到Azure静态Web应用,使用GitLab CI/CD流水线。

答案1

得分: 2

找到了一个可行的解决方案,在围绕代码调整了一段时间后,我的同事帮助我找到了解决方案。

我必须更改变量APP_PATH: '$CI_PROJECT_DIR/src',删除/src,只保留$CI_PROJECT_DIR。

更新后的YAML如下:

stages:
   - build
   - deploy

variables:
  API_TOKEN: $DEPLOYMENT_TOKEN
  APP_PATH: '$CI_PROJECT_DIR'
  OUTPUT_PATH: '$CI_PROJECT_DIR/dist/hero'

build:
  stage: build
  image: node:18.15.0-bullseye
  script:
    - npm install
    - npm run build
    - ls
  artifacts:
    paths:
      - $OUTPUT_PATH

deploy:
  stage: deploy
  image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy:latest
  script:
    - echo "App deployed successfully."
    - ls

对于新手,请确保在GitLab中添加了变量$DEPLOYMENT_TOKEN。

希望这有所帮助。

英文:

Found a working solution,
after tweaking around the code for a while my colleague helped me find the solution

I had to change variable APP_PATH: '$CI_PROJECT_DIR/src'
remove the /src and only keep the $CI_PROJECT_DIR

The updated Yaml looks like this:-

stages:
   - build
   - deploy

variables:
  API_TOKEN: $DEPLOYMENT_TOKEN
  APP_PATH: '$CI_PROJECT_DIR'
  OUTPUT_PATH: '$CI_PROJECT_DIR/dist/hero'

build:
  stage: build
  image: node:18.15.0-bullseye
  script:
    - npm install
    - npm run build
    - ls
  artifacts:
    paths:
      - $OUTPUT_PATH

deploy:
  stage: deploy
  image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy:latest
  script:
    - echo "App deployed successfully."
    - ls

for newbies make sure you have added the variable $DEPLOYMENT_TOKEN in GitLab.

Hope this helps.

huangapple
  • 本文由 发表于 2023年4月10日 20:06:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定