How do I change the Jib repo per environment when using the Gradle plugin?

74 Views Asked by At

I have the following...

id 'com.google.cloud.tools.jib' version '3.1.4'
...
jib {
    
  from {
        
    image = 'amazoncorretto:20'
    
  }
    
  to {
        
    image = 'cbusha-backend:latest'

  }

}

This allows me to build and store the image locally. Now I want another "profile" or task where if I provide a flag it deploys to AWS ECR. This works if I manually change it like this...

jib {
    
  from {
        
    image = 'amazoncorretto:20'
    
  }
    
  to {
        
    image = '660315312345.dkr.ecr.us-east-2.amazonaws.com/cbusha-backend:latest'

  }

}

I don't want to upload to ECR until I have tested locally. How would I configure Gradle to handle this?

1

There are 1 best solutions below

0
Chanseok Oh On

There are really many different ways to achieve this goal, but how about using a simple property?

if (project.hasProperty('prod')) {
  image = '...'
} else {
  image = '...'
}

or

image = project.hasProperty('dev') ? '...' : '...'

See https://blog.mrhaki.com/2016/05/gradle-goodness-get-property-or-default.html to understand Gradle properties.