Is it possible to create a multi-line string variable in a Makefile

后端 未结 19 2013
借酒劲吻你
借酒劲吻你 2020-11-28 20:27

I want to create a makefile variable that is a multi-line string (e.g. the body of an email release announcement). something like

ANNOUNCE_BODY=\"
Version $         


        
19条回答
  •  执念已碎
    2020-11-28 20:29

    Not completely related to the OP, but hopefully this will help someone in future. (as this question is the one that comes up most in google searches).

    In my Makefile, I wanted to pass the contents of a file, to a docker build command, after much consternation, I decided to:

     base64 encode the contents in the Makefile (so that I could have a single line and pass them as a docker build arg...)
     base64 decode the contents in the Dockerfile (and write them to a file)
    

    see example below.

    nb: In my particular case, I wanted to pass an ssh key, during the image build, using the example from https://vsupalov.com/build-docker-image-clone-private-repo-ssh-key/ (using a multi stage docker build to clone a git repo, then drop the ssh key from the final image in the 2nd stage of the build)

    Makefile

    ...
    MY_VAR_ENCODED=$(shell cat /path/to/my/file | base64)
    
    my-build:
        @docker build \
          --build-arg MY_VAR_ENCODED="$(MY_VAR_ENCODED)" \
          --no-cache \
          -t my-docker:build .
    ...
    

    Dockerfile

    ...
    ARG MY_VAR_ENCODED
    
    RUN mkdir /root/.ssh/  && \
        echo "${MY_VAR_ENCODED}" | base64 -d >  /path/to/my/file/in/container
    ... 
    

提交回复
热议问题