ap.singh
ap.singh

Reputation: 1160

Dockerfile Copy command is not working with IF/Else

I am new to Docker. I am using the Copy command to copy some files and its working fine. But when I add those Copy Commands to IF/ElSE statement it stopped working and showing an error returned a non-zero code: 127. Please find below the code I am using.

RUN if [ "$FRONT_END_BUILD" = "false" ]; then \
      echo "front resources need not to copy" $FRONT_END_BUILD; \
  else \
    COPY --from=build /application/test.php /application/test.php;\
    COPY --from=build /application/reactPage.blade.php /application/reactPage.blade.php;\
    COPY --from=build /application/reactPageBlank.blade.php /application/reactPageBlank.blade.php;\
  fi 

Upvotes: 1

Views: 5772

Answers (2)

gaganshera
gaganshera

Reputation: 2639

You can do something like this (dummy Dockerfile):

FROM node:10.8-stretch as build

RUN mkdir -p /application/
WORKDIR /application
RUN touch .emptyfile
RUN ls -l

FROM alpine:3.4 

ENV TEMP = "false" 
ENV First = ""

RUN if [ "TEMP" = "false" ]; then \
      echo "front end is not required"; \
  else \
      echo "helo";\
  fi 


COPY --from=build /application/.emptyfile /application/resources/views/admin/master.blade.php* /bin/

The line to focus is

COPY --from=build /application/.emptyfile /application/resources/views/admin/master.blade.php* /bin/

What this line does is it'll copy the /application/.emptyfile which is just a dummy placeholder file, and keep this /application/resources/views/admin/master.blade.php* optional.

Upvotes: 1

bykebyn
bykebyn

Reputation: 85

Maybe you can do this.

COPY --from=build /application/test.php /application/test.php.backup
COPY --from=build /application/reactPage.blade.php /application/reactPage.blade.php.backup
COPY --from=build /application/reactPageBlank.blade.php /application/reactPageBlank.blade.php.backup

RUN if [ "$FRONT_END_BUILD" = "false" ]; then \
      echo "front resources need not to copy" $FRONT_END_BUILD; \
  else \
    mv /application/test.php.backup /application/test.php;\
    mv /application/reactPage.blade.php.backup /application/reactPage.blade.php;\
    mv /application/reactPageBlank.blade.php.backup /application/reactPageBlank.blade.php;\
  fi 

Upvotes: 1

Related Questions