0

I'm running make for windows. ( choco install make )

pretty much everything is working out fine until i'm trying to build a docker container, specifically to deploy on Amazon ECS....

Part of the ECS deploy process is you get a login from AWS aws ecr get-login this returns a string containing a command that looks like docker login -u AWS -p AQEC...HGZSSUMX4ftIpo8gY2 -e none https://123456789.dkr.ecr.us-east-1.amazonaws.com

if i was just running this from the shell i would copy the output and past it onto the commandline and run - but I'm trying to put this into my makefile so i have @ECS_LOGIN =$(shell aws ecr get-login)

and then I'm trying to execute it on the next line $(ECS_LOGIN)

and thats where i get
process_begin: CreateProcess(NULL, ECS_LOGIN =docker login -u AWS -p AQEC...HGZSSUMX4ftIpo8gY2 -e none https://123456789.dkr.ecr.us-east-1.amazonaws.com, ...) failed. make (e=2): The system cannot find the file specified. make: *** [docker-deploy] Error 2

from researching other questions this seems like a pathing issue when running from windows Makefile error make (e=2): The system cannot find the file specified

but docker commands prior to my aws ecr get-login work just fine ie
docker build
so it seems specific to running the command out of the variable

So how do i run this command from make and have the path resolve?

full recipe
docker-deploy: docker-build @ECS_LOGIN =$(shell aws ecr get-login) $(ECS_LOGIN) docker tag mytag:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest

Community
  • 1
  • 1
Jeff Martin
  • 10,812
  • 7
  • 48
  • 74

2 Answers2

5

First, you need to decide which tool you want to use to run the "aws ecr get-login" command. In your recipe, Make runs it (and you assign the result to a shell variable without quoting the multi-word value, but I guess the Windows shell is fine with it?). In the next line you try to refer to the shell variable, but forget to dollar-quote the dollar sign, so make substitutes whatever the value of ECS_LOGIN is at the time of invoking the recipe (which is probably nothing).

Perhaps start by moving the first line (ECS_LOGIN=$(shell aws ecr get-login)) out of the shell recipe and see if that helps:

ECS_LOGIN =$(shell aws ecr get-login)
docker-deploy: docker-build
    @$(ECS_LOGIN)
    docker tag mytag:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest
    docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest
Michael Livshin
  • 401
  • 3
  • 4
1

Your makefile is confused about make variables vs. shell variables and how recipes are invoked; see Michael's answer.

If it were me I would just not bother to use a variable at all; is there a reason you want to do so?

You could use either:

docker-deploy: docker-build
        @$(shell aws ecr get-login)
        docker tag mytag:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest
        docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest

which will work but is a bit odd: running a shell function inside a recipe is confusing, because you're already in a shell, so an alternative is just to use the recipe shell completely and avoid make's shell function:

docker-deploy: docker-build
        @eval $$(aws ecr get-login)
        docker tag mytag:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest
        docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/mytag:latest
MadScientist
  • 92,819
  • 9
  • 109
  • 136