AWS 管道;下一个JS;并非所有工件都上传到 EC2 实例上; GitHub -> CodeBuild -> CodeDeploy

问题描述 投票:0回答:1

我正在使用 NextJS 构建前端应用程序。

我的代码库存储在 GitHub 上。 我使用 codepipeline 创建管道并将其部署在运行 Ubuntu 的 EC2 实例上。

问题: 在我的管道触发后,它会成功构建并成功部署,但我可以看到并非构建工件中的所有文件都被上传。

即使我可以看到它在代码构建步骤中生成,但未上传的文件夹是

build
文件夹。因此,我无法运行我的服务器,因为我没有部署构建文件。

我的

buildspec.yml
文件:

version: 0.2

phases:

  install:
    runtime-versions:
      nodejs: 20
    commands:
      - echo "📦 Installing packages..."
      - npm install
      - echo "✅ Packages installed successfully; Current repository:"
      - ls -al

  build:
    commands:
      - echo "🚧 Starting building packages..."
      - npm run build

  post_build:
    commands:
      - echo "✅ Built successfully"
      - echo `date`
      - echo `Repository after build:`
      - ls -al

artifacts:
  files:
    - '**/*'
  discard-paths: no

我的

appspec.yml

version: 0.0
os: linux

files:
  - source: /
    destination: /home/ubuntu/example

file_exists_behavior: OVERWRITE

hooks:
  ApplicationStart:
    - location: deploy/application_start.sh
      timeout: 300
      runas: root

我的

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  distDir: 'build'
};

module.exports = nextConfig;

我的

application_start.sh

#!/bin/bash

cd /home/ubuntu/example

pm2 stop example_server
pm2 delete example_server
pm2 start npm --name "example_server" -- start

Build Logs

amazon-web-services next.js aws-codebuild aws-code-deploy aws-pipeline
1个回答
0
投票

所以问题出在 CodeDeploy 配置中。这些工件被指向“SourceArtifacts”而不是“BuildArtifacts”,因此构建文件夹无法到达 ec2 服务器。

© www.soinside.com 2019 - 2024. All rights reserved.