How can I scrap code from the Dockerfile?

I have an app running on Heroku. I don’t want anyone to copy my repo. So ı want to put if to main file from Dockerfile.

Here is my Dockerfile:

FROM fu***/wha****:latest

RUN git clone https://github.com/phaticusthiccy/WhatsAsenaDuplicated/ root/WhatsAsenaDuplicated
WORKDIR /root/WhatsAsenaDuplicated/
ENV TZ=Europe/Istanbul
RUN npm install deepai
RUN npm install supervisor -g
RUN npm install

CMD ["node", "bot.js"]

Bot can be cloned if the change “RUN git clone”

So ı want to scrap this line and add to bot.js
Using if / else

if (xxx == 'phaticusthiccy/WhatsAsenaDuplicated') {
...

And

}
else {
...

How can I do that? What should I add where it says xxx?

Hi,

the declarative language in a Dockerfile does not support conditional statements. One way of solving this can be to have an entrypoint.sh script (or run.sh, name does not matter) in your repository next to the Dockerfile which you copy into the image.

FROM fu***/wha****:latest

RUN git clone https://github.com/phaticusthiccy/WhatsAsenaDuplicated/ root/WhatsAsenaDuplicated
WORKDIR /root/WhatsAsenaDuplicated/
ENV TZ=Europe/Istanbul
ENV MYAPP_ENV="PROD"
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh

RUN npm install deepai
RUN npm install supervisor -g
RUN npm install

CMD ["entrypoint.sh"]

You can parametrize the shell script with environment variables, setting the value to PROD from the outside, and execute commands based on that. Below is an untested example, bash syntax might not be a 100% correct.

scripts/entrypoint.sh

if [ "$MYAPP_ENV" == "PROD" ]; then
  node bot.js
else
  # something else to execute
fi

Cheers,
Michael

Hi, i tried but it didn’t affect.

Here is my dockerfile

FROM fu**/what***:latest

RUN git clone https://github.com/phaticusthiccy/WhatsAsenaDuplicated /root/WhatsAsenaDuplicated
WORKDIR /root/WhatsAsenaDuplicated/
ENV TZ=Europe/Istanbul
ENV REPO_ENV="test"
COPY scripts/run.sh /root/scripts/run.sh

RUN npm install deepai
RUN npm install supervisor -g
RUN npm install

CMD ["run.sh"]

And here is my scripts/run.sh

if [ "$REPO_ENV" == "phaticusthiccy/WhatsAsenaDuplicated" ]; then
  node bot.js
else
  echo -n "🛡️ Dont Clone Original Repository!"
fi

But it doesn’t stop no matter what I do. :confused:

Hi,

this tries to execute a script in PATH (e.g. /usr/local/bin). Your script lives in /root/scripts/run.sh.

Try calling the script by its full path.

Cheers,
Michael

Okey so ı will try like this:

CMD ["/root/scripts/run.sh"]

It this right?

1 Like