dockertravis-cignu-make

I want to use shell script output as a input to the makefile variable and pass that as the build parameter in docker build


makefile looks like below

BASE_JOB_IMAGE := $(shell ./fetchimageversion.sh >> image.txt)
FILE ?= image.txt
BASE_JOB_IMAGE_NAME=`cat $(FILE)`


docker build \
    --pull \
    --no-cache \
    -t ${APPLICATION}_${TF_VER} \
    --build-arg baseimage=$(BASE_JOB_IMAGE_NAME)

But I am not getting the expected output in travis logs.

docker build \
    --pull \
    --no-cache \
    --build-arg baseimage=`cat image.txt` \

When used as BASE_JOB_IMAGE := $(shell ./fetchimageversion.sh) I do see the output of the script output but whole script execution result is set to the variable which also result in error in travis log wihth --build-arg baseimage= \ being blank


Solution

  • First, that can't be the makefile; you have a target with no recipe. I assume that the docker command is in a recipe.

    Second, why do you write the output to a static file but then set a variable and refer to the variable for the rest of the makefile?

    Third, why do you use ?= to define the filename? Do you expect to want to allow an environment variable to override the filename? That won't work if you're writing to a static filename in the previous command.

    Fourth, why are you using append-to >> when writing the file? If the file already exists, this means you'll have multiple lines of content in it.

    Try writing your makefile like this:

    FILE = input.txt
    BASE_JOB_IMAGE := $(shell ./fetchimageversion.sh >$(FILE))
    BASE_JOB_IMAGE_NAME = `cat $(FILE)`
    
    ...rest of makefile...
    

    ETA

    But, I don't know why you're going through this extra effort of writing to a file. Why not just keep the output in a variable?

    BASE_JOB_IMAGE_NAME := $(shell ./fetchimageversion.sh)
    
    ...rest of makefile...