0

Was following the conversation in this thread Conditional COPY/ADD in Dockerfile?.

I have a requirement to check AND conditions like this:

IF Environment = development and Region = East : Do this
IF Environment = development and Region = West : Do this
IF Environment = production and Region = East : Do this
IF Environment = production and Region = East : Do this

How would I achieve this?

  • I did not find anything with AND Condition SO. IF you are marking this as DUP at least let me know the post where this is answered – Dorian McAllister Dec 11 '18 at 16:41
  • Just a sidenote: I would strongly advise against building different images for different environments. Build a single image and use it in all environments instead. Environment specific config should be provided at runtime via environment variables. See https://12factor.net/dev-prod-parity and https://12factor.net/config – Fabian Braun Dec 11 '18 at 16:43
  • Unfortunately - the corporate world i am in enforces this. There are different builds in different environments. GOing back to my original question - is there a way I can use AND conditions in the question stated? – Dorian McAllister Dec 11 '18 at 17:26
  • 1
    You can, check the first answer on [the duplicate](https://stackoverflow.com/questions/43654656/dockerfile-if-else-condition-with-external-arguments/43656644#43656644). However that only works if your "Do this" is actually a `RUN` instruction. Otherwise you might ask a more specific question. – Fabian Braun Dec 11 '18 at 17:33
  • thanks. I saw that but the syntax was confusing. Since it mentions && Is this considered a valid syntax? `RUN if [ "$arg1" = "x" && "$arg2" ="y" ]; then echo "Works";` – Dorian McAllister Dec 11 '18 at 17:40
  • 1
    The syntax is just regular bash syntax. Try to search how you can achieve what you want to do with bash (string comparison, conditions, environment var Checks) – Fabian Braun Dec 11 '18 at 17:50

0 Answers0