【Azure 应用服务】App Service 在使用GIt本地部署,上传代码的路径为/home/site/repository,而不是站点的根目录/home/site/wwwroot。 这个是因为什么?

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 【Azure 应用服务】App Service 在使用GIt本地部署,上传代码的路径为/home/site/repository,而不是站点的根目录/home/site/wwwroot。 这个是因为什么?

问题描述

App Service 在使用GIt本地部署,上传代码的路径为/home/site/repository,而不是站点的根目录/home/site/wwwroot。 这个是因为什么? 并且通过Git发布静态文件的时候不成功。出现“Could not detect any platform in the source directory.” 和 "Error: Couldn't detect a version for the platform 'php' in the repo."错误

 

查看日志

遇见发布时候的错误,除了在发布时候本地可以查看外,还可以在App Service的Kudu中查看。通过下列步骤来查看部署日志:

一:进入Kudu

 

二:进入发布日志(D:\home\site\deployments\temp-xxxx)

 

三:查看日志内容

2021-03-16T03:20:50  Updating branch 'master'.
2021-03-16T03:21:00  Updating submodules.
2021-03-16T03:21:00  Preparing deployment for commit id '208129ed8c'.
2021-03-16T03:21:00  Repository path is /home/site/repository
2021-03-16T03:21:00  Running oryx build...
2021-03-16T03:21:00    Command: oryx build /home/site/repository -o /home/site/wwwroot --platform php --platform-version 7.4 -i /tmp/8d8e82a85ff94d0 --log-file /tmp/build-debug.log 
2021-03-16T03:21:04    Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
2021-03-16T03:21:04    You can report issues at https://github.com/Microsoft/Oryx/issues
2021-03-16T03:21:04    
2021-03-16T03:21:04    Oryx Version: 0.2.20201105.1, Commit: 127d6a3c61a6c0eb67bcfeee0600c3fe71251839, ReleaseTagName: 20201105.1
2021-03-16T03:21:04    
2021-03-16T03:21:04    Build Operation ID: |wb65mFzxGQU=.83c35c89_
2021-03-16T03:21:04    Repository Commit : 208129ed8c6e3b88ee890d958000b1cd72b9bacc
2021-03-16T03:21:04    
2021-03-16T03:21:04    Detecting platforms...
2021-03-16T03:21:05    Could not detect any platform in the source directory.
2021-03-16T03:21:05    Error: Couldn't detect a version for the platform 'php' in the repo.
2021-03-16T03:21:08    Error: Couldn't detect a version for the platform 'php' in the repo.
/opt/Kudu/KuduConsole/Scripts/starter.sh oryx build /home/site/repository -o /home/site/wwwroot --platform php --platform-version 7.4 -i /tmp/8d8e82a85ff94d0 --log-file /tmp/build-debug.log 
2021-03-16T03:21:08

 

问题分析

根据日志总的错误消息,发现有这样两段日志:

 

2021-03-16T03:21:00  Repository path is /home/site/repository
2021-03-16T03:21:00  Running oryx build...
2021-03-16T03:21:00    Command: oryx build /home/site/repository -o /home/site/wwwroot --platform php --platform-version 7.4 -i /tmp/8d8e82a85ff94d0 --log-file /tmp/build-debug.log 

2021-03-16T03:21:05    Could not detect any platform in the source directory.
2021-03-16T03:21:05    Error: Couldn't detect a version for the platform 'php' in the repo.

错误原因是由于执行命令 oryx build /home/site/repository -o /home/site/wwwroot --platform php xxxxxx  时发现build目录中并没有php相关文件导致的。由于使用local git部署需要使用Orxy进行build,如果成功后才会将repository文件夹中的内容输出到wwwroot下,所以最初的问题为什么wwwroot中没有内容。

 

由于目前orxy不支持纯静态文件的部署,在Github中也有相对应的Issue存在:https://github.com/microsoft/Oryx/issues/623

Support for static files? #623


Hi,

I have an existing static site (just .html files) which is currently deployed to netlify.

What configuration do you have to use to just deploy these files? At the moment the build is failing with the error Error: Could not detect the language from repo.

Many thanks!

Howard


@HowardvanRooijen I was able to get a site that was 100% static html, css, and javascript to deploy. It was definitely a workaround style approach but it did work:

  1. remove everything from my repository except
  • git related files (.gitignore)
  • .github directory
  • directory (i called mines 'pregen') containing html, css, js, gifs, etc
  1. in the .github/azure-static-web-apps-*.yml file set the app_location to your html directory (I called mines 'pregen')

This worked for deploying truly static web site with no real build process to Azure Static Web Apps


@kichalla I think the main thing that is confusing here is that Oryx emits an error about detection. As discussed we probably want to have an option to not emit that error and just use the custom status code for saying detection failed. Static Web Apps assumes static content when we see that error code.

 

解决办法

可以在提交时,保证git仓储里面有一个php文件,这样可以保证orxy正常运行build。如增加一个简单的test.php,里面就放入非常简单的一句代码即可:

<?php
phpinfo();
?>

参考资料

从本地 Git 部署到 Azure 应用服务:https://docs.azure.cn/zh-cn/app-service/deploy-local-git

oryx build:https://github.com/Microsoft/Oryx#oryx-build

Support for static files? #623 : https://github.com/microsoft/Oryx/issues/623

相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
相关文章
|
1月前
|
开发工具 git
使用Git根据日期进行代码版本切换的方法
通过以上步骤,可以有效地根据日期进行Git代码版本的切换。这种方法在需要回溯历史版本进行bug修复或功能复查时特别有用。Git的灵活性和强大功能使其成为现代软件开发不可或缺的工具之一。
267 103
|
4月前
|
数据可视化 Java 测试技术
Git Flow 现代实操指南含从代码提交到 CI/CD 全流程的实用技巧与长尾关键词解析 Git Flow
本指南结合现代技术趋势,详解Git Flow工作流,涵盖GitHub Actions自动化、Conventional Commits规范、Gitmoji可视化等内容,助你实现代码到CI/CD的全流程管理,提升团队开发效率与代码质量。
353 2
|
开发工具 git C++
【App Service】VS Code直接部署App Service时候遇见 “fatal: not a git repository (or any of the parent directories): .git”
通过VS Code发布Python App Service的时候,遇见了发布失败错误: The deployment failed with error: fatal: not a git repository (or any of the parent directories): .git . Please take a few minutes to help us improve the deployment experience
257 24
|
6月前
|
JavaScript 前端开发 持续交付
实际工作中 Git Commit 代码提交规范是什么样的?
实际工作中 Git Commit 代码提交规范是什么样的?
437 7
|
6月前
|
网络安全 开发工具 git
Git仓库创建与代码上传指南
本教程介绍了将本地项目推送到远程Git仓库的完整流程,包括初始化本地仓库、添加和提交文件、创建远程仓库、关联远程地址及推送代码。同时,还提供了`.gitignore`配置、分支管理等可选步骤,并针对常见问题(如认证失败、分支不匹配、大文件处理及推送冲突)给出了解决方案。适合初学者快速上手Git版本控制。
|
5月前
|
开发工具 git 索引
如何使用Git的暂存区来管理代码更改?
如何使用Git的暂存区来管理代码更改?
967 0
|
10月前
|
Devops Shell 网络安全
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
476 16
git使用之如何将一套代码同时推送至github|gitee|gitcode|gitlab等多个仓库-含添加ssh-优雅草央千澈完美解决-提供整体提交代码
|
Shell 网络安全 开发工具
git与gitee结合使用,提交代码,文件到远程仓库
本文介绍了如何将Git与Gitee结合使用来提交代码文件到远程仓库。内容涵盖了Git的安装和环境变量配置、SSH公钥的生成和配置、在Gitee上创建仓库、设置Git的全局用户信息、初始化本地仓库、添加远程仓库地址、提交文件和推送到远程仓库的步骤。此外,还提供了如何克隆远程仓库到本地的命令。
git与gitee结合使用,提交代码,文件到远程仓库
|
开发工具 git
git如何修改提交代码时的名字和邮箱?
git如何修改提交代码时的名字和邮箱?
3864 4
|
Java Linux 开发工具
IDEA中git提交前如何关闭code analysis以及开启格式化代码
【10月更文挑战第12天】本文介绍了在 IntelliJ IDEA 中关闭代码分析和开启代码格式化的步骤。关闭代码分析可通过取消默认启用检查或针对特定规则进行调整实现,同时可通过设置 VCS 静默模式在提交时跳过检查。开启代码格式化则需在 `Settings` 中配置 `Code Style` 规则,并通过创建 Git 钩子实现提交前自动格式化。
4427 3