0

I have a python script to update ECR images in my repo and keep a couple previous images as well in case of errors in new ones. I'm trying to run this from my buildspec yml file in Codebuild but it's not executing correctly. Below are the relevant lines in buildspec and in my py script.

  build:
    commands:
      - echo Updating previous images in ECR repo
      - python3 UpdateECRImages.py
        run(f"docker pull {image_string}grafana-1")

The run command is imported from subprocess and this whole script works as intended locally. I've also tried just running that ecr command in the buildspec file to verify the correct IAM permissions are in place as well and that executes without error. However when I run it, in Codebuild, throws an error: FileNotFoundError: [Errno 2] No such file or directory: 'docker pull ############.dkr.ecr.us-east-1.amazonaws.com/#########:grafana-1'

Once again I can run these docker commands from the buildspec file but not from the py script in the buildspec file and unsure why. Any help is appreciated.

frktclr
  • 1
  • 1
  • It's not related to CodeBuild, it's just wrong usage of subprocess. Try `subprocess.run(['docker', 'pull', f'{image_string}:grafana-1'])` instead. – STerliakov May 04 '23 at 19:44
  • Does this answer your question? [subprocess.Popen() error (No such file or directory) when calling command with arguments as a string](https://stackoverflow.com/questions/30010939/subprocess-popen-error-no-such-file-or-directory-when-calling-command-with-a) – STerliakov May 04 '23 at 19:47

1 Answers1

0

Thought I would post this here in case others come across the same problem. It was something with subprocess which this question helped me with: "OSError: [Errno 2] No such file or directory" while using python subprocess with command and arguments

Enabling shell=True in the args for subprocess.run solved it for me

frktclr
  • 1
  • 1