Skip to content

Cannot update nodejs runtime version in buildspec.yml for code pipeline? #5222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lominming opened this issue Aug 24, 2023 · 10 comments
Closed
Labels
guidance Issue requesting guidance or information about usage stale

Comments

@lominming
Copy link

lominming commented Aug 24, 2023

I've a codepipeline setup: code from github >>> test env >>> run tests >>> prod env.
I also have tests to run which depends on the host nodejs version.

I am trying to change the nodejs version in buildspec.yml:
image

But it throws this error:
image

My tests commands are in pipelines/.../manifest.yml:
image

Question 1: How can I update the nodejs version for my build pipeline?

Question 2: Can I just install a higher version of nodejs runtime at the test_commands section? Like apk add...

@iamhopaul123 iamhopaul123 added the guidance Issue requesting guidance or information about usage label Aug 25, 2023
@iamhopaul123
Copy link
Contributor

Hello @lominming. It seems like for aws/codebuild/amazonlinux2-x86_64-standard:4.0 which Copilot sets by default, only nodejs 16 is supported. You can get this around by installing a higher level version. For example:

    runtime-versions:
      nodejs: 16
    commands:
      - n 18

@lominming
Copy link
Author

@iamhopaul123 Do I add it at line 10 in the buildspec.yml?

Doesn't seem to work. It somehow complained that it needs Docker 20 when I add the line. I will double check again, just making sure where I should put n 18.

image

@iamhopaul123
Copy link
Contributor

Here's my full example

# Buildspec runs in the build stage of your pipeline.
version: 0.2
phases:
  install:
    runtime-versions:
      ruby: 3.1
      nodejs: 16
    commands:
      - n 18
      - echo "node -v" 
      - echo "cd into $CODEBUILD_SRC_DIR"
      - cd $CODEBUILD_SRC_DIR
      # Download the copilot linux binary.
      - wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.29.1 -O copilot-linux
      - chmod +x ./copilot-linux
  build:
    commands:
      - echo "Run your tests"
      # - make test

@lominming
Copy link
Author

lominming commented Aug 25, 2023

@iamhopaul123 It doesn't appear to work. I added it in the commands like you have with n 18.
It still shows the nodejs 16

image

Steps I took:

  1. edit copilot/pipelines/<pipeline-name>/buildspec.yml to add n 18
  2. copilot pipeline deploy
  3. push code to github to trigger change
  4. print node -v in my test commands (in copilot/pipelines/<pipeline-name>/manifest.yml
  5. node -v still shows nodejs v16

@iamhopaul123
Copy link
Contributor

iamhopaul123 commented Aug 28, 2023

Hello @lominming. Can you post your buildspec here? I use the buildspec below and in the log it shows node 18

# Buildspec runs in the build stage of your pipeline.
version: 0.2
phases:
  install:
    runtime-versions:
      ruby: 3.1
      nodejs: 16
    commands:
      - n 18
      - node -v 

@lominming
Copy link
Author

  1. I copied the front part of your buildspec.yml
  2. Then copilot pipeline deploy
  3. push code to github to trigger change
# Buildspec runs in the build stage of your pipeline.
version: 0.2
phases:
  install:
    runtime-versions:
      ruby: 3.1
      nodejs: 16
    commands:
      - n 18
      - echo "node -v" 
      - echo "cd into $CODEBUILD_SRC_DIR"
      - cd $CODEBUILD_SRC_DIR
      # Download the copilot linux binary.
      - wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.29.1 -O copilot-linux
      - chmod +x ./copilot-linux
  build:
    commands:
      - echo "Run your tests"
      # - make test
  post_build:
    commands:
      - ls -l
      - export COLOR="false"
      - pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/xyzxyz/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
      - pl_envs=$(echo $pipeline | jq -r '.stages[].name')
      # Find all the local services in the workspace.
      - svc_ls_result=$(./copilot-linux svc ls --local --json)
      - svc_list=$(echo $svc_ls_result | jq '.services')
      - >
        if [ ! "$svc_list" = null ]; then
          svcs=$(echo $svc_ls_result | jq -r '.services[].name');
        fi
      # Find all the local jobs in the workspace.
      - job_ls_result=$(./copilot-linux job ls --local --json)
      - job_list=$(echo $job_ls_result | jq '.jobs')
      - >
        if [ ! "$job_list" = null ]; then
          jobs=$(echo $job_ls_result | jq -r '.jobs[].name');
        fi
      # Raise error if no services or jobs are found.
      - >
        if [ "$svc_list" = null ] && [ "$job_list" = null ]; then
          echo "No services or jobs found for the pipeline to deploy. Please create at least one service or job and push the manifest to the remote." 1>&2;
          exit 1;
        fi
      # Generate the cloudformation templates.
      # The tag is the build ID but we replaced the colon ':' with a dash '-'.
      # We truncate the tag (from the front) to 128 characters, the limit for Docker tags
      # (https://docs.docker.com/engine/reference/commandline/tag/)
      # Check if the `svc package` commanded exited with a non-zero status. If so, echo error msg and exit.
      - >
        for env in $pl_envs; do
          tag=$(echo ${CODEBUILD_BUILD_ID##*:}-$env | sed 's/:/-/g' | rev | cut -c 1-128 | rev)
          for svc in $svcs; do
          ./copilot-linux svc package -n $svc -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
          if [ $? -ne 0 ]; then
            echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
            exit 1;
          fi
          done;
          for job in $jobs; do
          ./copilot-linux job package -n $job -e $env --output-dir './infrastructure' --tag $tag --upload-assets;
          if [ $? -ne 0 ]; then
            echo "Cloudformation stack and config files were not generated. Please check build logs to see if there was a manifest validation error." 1>&2;
            exit 1;
          fi
          done;
        done;
      - ls -lah ./infrastructure
artifacts:
  files:
    - "infrastructure/*"

@iamhopaul123
Copy link
Contributor

iamhopaul123 commented Aug 28, 2023

That's very interesting. This is what I got:

[Container] 2023/08/25 18:14:49 Running command n 18
--
27 | installing : node-v18.17.1
28 | mkdir : /usr/local/n/versions/node/18.17.1
29 | fetch : https://nodejs.org/dist/v18.17.1/node-v18.17.1-linux-x64.tar.xz
30 | copying : node/18.17.1
31 | node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
32 | node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)

Can you update your local Copilot version to the latest v1.29.1 and run copilot pipeline deploy to update the pipeline?

@iamhopaul123
Copy link
Contributor

iamhopaul123 commented Aug 29, 2023

Hello @lominming. So sorry about the confusion. Actually mine didn't work either because apparently according to aws/aws-codebuild-docker-images#580, aws/codebuild/amazonlinux2-x86_64-standard:4.0 can't work as well.

I am able to work it around by using build.image to use aws/codebuild/amazonlinux2-x86_64-standard:5.0 in the manifest and you will be able to specify

phases:
  install:
    runtime-versions:
      nodejs: 18

@dannyrandall dannyrandall added the area/override Issues related to overrides. label Aug 29, 2023
@iamhopaul123 iamhopaul123 removed the area/override Issues related to overrides. label Aug 29, 2023
@github-actions
Copy link

This issue is stale because it has been open 60 days with no response activity. Remove the stale label, add a comment, or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Oct 29, 2023
Copy link

This issue is closed due to inactivity. Feel free to reopen the issue if you have any further questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Issue requesting guidance or information about usage stale
Projects
None yet
Development

No branches or pull requests

3 participants