0

I am using NextJS to build a frontend application.

My code base is stored on GitHub. I use codepipeline to create a pipeline and deploy it on an EC2 instance with Ubuntu on it.

The issue: After my pipeline triggers it builds successfully, deploys successfully, but I can see that not all files from the build artifacts are being uploaded.

The folder that does not get uploaded even though I can see it being generated during the Code Build step is the build folder. Therefore I cannot run my server because I do not have build files deployed.

My buildspec.yml file:

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

My 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

My next.config.js:

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

module.exports = nextConfig;

My 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

1 Answer 1

0

So the issue was in the CodeDeploy configuration. The artifacts were pointed to the "SourceArtifacts" and not to "BuildArtifacts" therefore the build folder did not get to the ec2 server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.