0

我的 bitbucket 中有 reactjs 项目。我正在尝试将其部署在我的 EC2 服务器中,但在部署阶段遇到错误。并且在检查错误时......它没有如图所示部署......我正在分享文件和错误......你们可以帮帮我吗?

构建规范.yml

    # Do not change version. This is the version of aws buildspec, not the version of your buldspec file.
version: 0.2
phases:
  pre_build:
    commands:
      #installs dependencies into the node_modules/ directory
      - npm install
  build:
    commands:
      - echo Build started on `date`
      - echo Compiling
      - npm run build
  post_build:
    commands:
      - echo Build completed on `date`
# Include only the files required for your application to run.
artifacts:
  files:
    - public/**/*
    - src/**/*
    - package.json
    - appspec.yml
    - scripts/**/*

应用规范.yml

    version: 0.0
os: linux

files:
  - source: /
    destination: /home/ec2-user/server

permissions:
  - object: /
    pattern: "**"
    owner: ec2-user
    group: ec2-user 

hooks:

  BeforeInstall:
    - location: scripts/before_install.sh
      timeout: 300
      runas: root
  
  AfterInstall:
    - location: scripts/after_install.sh
      timeout: 300
      runas: root

  ApplicationStart:
    - location: scripts/app_start.sh
      timeout: 300
      runas: root

before_install.sh

   #!/bin/bash
cd /home/ec2-user/server
curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -
yum -y install nodejs npm

after_install.sh

#!/bin/bash
cd /home/ec2-user/server
npm install
npm install --save react react-dom react-scripts react-particles-js
npm install pm2 -g

app_start.sh

  #!/bin/bash
cd /home/ec2-user/server/src
npm start
pm2 start npm --name "econote-dashboard" -- start
pm2 startup
pm2 save
pm2 restart all

指定位置的错误 脚本:scripts/app_start.sh 未能在 300 秒内完成

Logs
[stdout] Line 41:12: Effect callbacks are synchronous to prevent race conditions. Put the async function inside:
[stdout]
[stdout]useEffect(() => {
[stdout] async function fetchData() {
[stdout] // You can await here
[stdout] const response = await MyAPI.getData(someId);
[stdout] // ...
[stdout] }
[stdout] fetchData();
[stdout]}, [someId]); // Or [] if effect doesn't need props or state
[stdout]
[stdout]Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching react-hooks/exhaustive-deps
[stdout]
[stdout]src/components/Cards.js
[stdout] Line 4:9: 'imageClick' is assigned a value but never used no-unused-vars
[stdout] Line 7:3: Anchors must have content and the content must be accessible by a screen reader jsx-a11y/anchor-has-content
[stdout] Line 13:6: Using target="_blank" without rel="noreferrer" is a security risk: see https://html.spec.whatwg.org/multipage/links.html#link-type-noopener react/jsx-no-target-blank
[stdout]
[stdout]src/components/Dashboard.js
[stdout] Line 2:23: 'EpubView' is defined but never used no-unused-vars
[stdout]
[stdout]src/components/login.js
[stdout] Line 30:24: The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
[stdout]
[stdout]Search for the keywords to learn more about each warning.
[stdout]To ignore, add // eslint-disable-next-line to the line before.
[stdout]
[stderr]Terminated
4

2 回答 2

0

您可以从 EC2 本身检查部署日志。

部署日志可用于:

/opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log

可以从以下位置找到各个部署日志。将部署组 ID部署 ID替换为您的实际值。

/opt/codedeploy-agent/deployment-root/deployment-group-ID/deployment-ID/logs/scripts.log

您可以从此处阅读有关 CodeDeploy 日志管理的更多信息。还有一个选项可以使用 CloudWatch 日志代理从 CloudWatch 控制台查看部署日志。有关更多信息,请参阅AWS 博客

于 2021-05-28T11:44:00.207 回答
0

编辑:在我们使用调试后看到更多脚本输出之后(见下文)

从输出看来,您的应用程序由于eslint发现错误而无法编译。create-react-app如果我没记错的话,这是使用创建的应用程序的默认行为。

我建议您首先尝试在您的开发环境中修复这些错误。只需通过运行app_start脚本启动应用程序即可。如果您遇到需要帮助的错误,请尝试在 SO 上提出新的具体问题。

(可选地,如果您不想修复 lint 错误,您可以告诉 eslint 通过添加// eslint-disable-next-line到脚本之前提到的行来忽略该行)。

调试提示遵循

不是直接回答您的问题,但您可以考虑将其添加到您的 bash 脚本中以查看更多输出:

#!/bin/bash
set -ex

Set -e 在出现错误时停止您的脚本,并且 -x 在运行它之前打印出每个命令,这样您就有了一些堆栈跟踪。

另请参阅:https ://stackoverflow.com/a/19622300/904465和https://stackoverflow.com/a/36273740/904465set -e以获取有关和的更多信息set -x

于 2021-05-28T11:57:44.593 回答