copilot-cli: docker version 18 in buildspec of test_commands gives 'Unknown runtime version'

Hello,

Today I upgraded from 1.20 to 1.27.0.

I use test_commands for some post deployment steps and that started failing.

The buildspec that fails is

version: 0.2
phases:
  install:
      runtime-versions:
        docker: 18
  build:
    commands:
      - yum install -y sudo && yum install -y expect
      - wget https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.27.0
      - mv ./copilot-linux-v1.27.0 ./copilot-linux
      - chmod +x ./copilot-linux
      - unbuffer ./copilot-linux svc exec -c "python manage.py collectstatic --no-input --skip-checks" -n app -e test --yes
      - unbuffer ./copilot-linux svc exec -c "python manage.py migrate" -n app -e test --yes

The error I’m getting with that:

[Container] 2023/03/31 18:53:17 Waiting for agent ping
--
2 | [Container] 2023/03/31 18:53:18 Waiting for DOWNLOAD_SOURCE
3 | [Container] 2023/03/31 18:53:21 Phase is DOWNLOAD_SOURCE
4 | [Container] 2023/03/31 18:53:21 CODEBUILD_SRC_DIR=/codebuild/output/src759560563/src
5 | [Container] 2023/03/31 18:53:21 YAML location is /codebuild/readonly/buildspec.yml
6 | [Container] 2023/03/31 18:53:21 No commands found for phase name: install
7 | [Container] 2023/03/31 18:53:21 Setting HTTP client timeout to higher timeout for S3 source
8 | [Container] 2023/03/31 18:53:21 Processing environment variables
9 | [Container] 2023/03/31 18:53:21 Selecting 'docker' runtime version '18' based on manual selections...
10 | [Container] 2023/03/31 18:53:24 Phase complete: DOWNLOAD_SOURCE State: FAILED
11 | [Container] 2023/03/31 18:53:24 Phase context status code: YAML_FILE_ERROR Message: Unknown runtime version named '18' of docker. This build image has the following versions: 20

Seems like it sets docker version 18 in the buildspec whereas version 20 is available in the build image.

Comparing that to the generated buildspec for the build stage generated by v1.27.0 that also sets docker to 20 like so:

version: 0.2
phases:
  install:
    runtime-versions:
      docker: 20
      ruby: 3.1
      nodejs: 16

I did run copilot pipeline update and all the changes for updating to v1.27.0 are committed to main.

Manually changing the buildspec of the build project to use docker: 20 solves the issue with logging:



[Container] 2023/03/31 20:13:20 Waiting for agent ping
--
2 | [Container] 2023/03/31 20:13:21 Waiting for DOWNLOAD_SOURCE
3 | [Container] 2023/03/31 20:13:25 Phase is DOWNLOAD_SOURCE
4 | [Container] 2023/03/31 20:13:25 CODEBUILD_SRC_DIR=/codebuild/output/src591659411/src
5 | [Container] 2023/03/31 20:13:25 YAML location is /codebuild/readonly/buildspec.yml
6 | [Container] 2023/03/31 20:13:25 No commands found for phase name: install
7 | [Container] 2023/03/31 20:13:25 Setting HTTP client timeout to higher timeout for S3 source
8 | [Container] 2023/03/31 20:13:25 Processing environment variables
9 | [Container] 2023/03/31 20:13:25 Selecting 'docker' runtime version '20' based on manual selections...
10 | [Container] 2023/03/31 20:13:25 Running command echo "Specifying docker version in buildspec is deprecated. Using docker $DOCKER_VERSION"
11 | Specifying docker version in buildspec is deprecated. Using docker 20.10.22

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@efekarakus Sorry for the confusion, I am still getting the original error:

image


Sorry that I am still a bit unclear. It would be great if you could help clarify the following statements again.

1) There is a buildspec.yml in copilot/pipelines/repo-main/buildspec.yml —> This file has NO docker entry (it had a old ruby version that I had to update to 3.1) —> This buildspec appears to be the buildspec that CodeBuild is pointing to. —> Question: Based on what you said earlier “the buildspec.yml for test_commands isn’t written to the disk”, so this is NOT the buildspec I should edit?

  1. If that is not the buildspec I should be editing… —> Question: Where can I find the correct buildpsec that I should be editing?

  2. If that is the correct buildspec… ----> Question: Why is it complaining about docker: 18 when the entry is not in it? ----> Manually adding docker: 20 does not help.


For reference, the buildspec.yml generated by copilot in copilot/pipelines/repo-main/buildspec.yml

# Buildspec runs in the build stage of your environment pipeline to generate the environment CloudFormation stack config.
version: 0.2
phases:
  install:
    runtime-versions:
      # docker: 20 ###### NOTE: This entry is not there. Adding docker: 20 does not help either.
      ruby: 3.1 ###### This was originally 2.7, had to update to 3.1
    commands:
      - echo "cd into $CODEBUILD_SRC_DIR"
      - cd $CODEBUILD_SRC_DIR
      # Download the copilot linux binary. You can update this version.
      - wget -q https://ecs-cli-v2-release.s3.amazonaws.com/copilot-linux-v1.27.0
      - mv ./copilot-linux-v1.27.0 ./copilot-linux
      - chmod +x ./copilot-linux
  build:
    commands:
      - echo "Run your tests"
      # - make test
  post_build:
    commands:
      - ls -l
      - export COLOR="false"
      - export CI="true"
      - pipeline=$(cat $CODEBUILD_SRC_DIR/copilot/pipelines/repo-main/manifest.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))')
      - stages=$(echo $pipeline | jq -r '.stages[].name')
      # Generate the cloudformation templates.
      - >
        for env in $stages; do
          ./copilot-linux env package -n $env --output-dir './infrastructure' --upload-assets --force;
          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;
      - ls -lah ./infrastructure
artifacts:
  files:
    - "infrastructure/*"

Hi @lennertcc !!

Thank you so much for reporting this issue. It looks like we have to update this section of the CloudFormation template for the pipeline: https://github.com/aws/copilot-cli/blob/e1afe3976229284a680ae59d6be4b6a6dd0478b5/internal/pkg/template/templates/cicd/pipeline_cfn.yml#L302-L304

and completely remove docker in runtime-versions as its no longer needed to specify

I figured out why I got the YAML file missing error, it is because when I was trying to edit the buildspec, I accidentially deleted the path to the YAML file.

This is the original config by copilot pipeline. It appears to point the buildspec.yml that is generated, but you were saying that that is not the buildspec to modify?

To recap, the file copilot/pipelines/repo-main/buildspec.yml that is originally generated does not have docker: 18 in the runtime-versions. Adding docker: 20 does not help either.

image