Guest User

Untitled

a guest
Dec 7th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. class EcrLoginTask extends DefaultTask {
  2. String accessKey
  3. String secretCode
  4. String region
  5. String registryId
  6.  
  7. @TaskAction
  8. String getPassword() {
  9. AmazonECR ecrClient = AmazonECRClient.builder()
  10. .withRegion(Regions.fromName(region))
  11. .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretCode))).build()
  12. GetAuthorizationTokenResult authorizationToken = ecrClient.getAuthorizationToken(
  13. new GetAuthorizationTokenRequest().withRegistryIds(registryId))
  14. String token = authorizationToken.getAuthorizationData().get(0).getAuthorizationToken()
  15. System.setProperty("DOCKER_PASS", token) // Will this work ?
  16. return token
  17. }
  18.  
  19. }
  20.  
  21. buildscript {
  22. repositories {
  23. mavenCentral()
  24. }
  25. dependencies {
  26. classpath 'com.amazonaws:aws-java-sdk-ecr:1.11.244'
  27. classpath 'com.bmuschko:gradle-docker-plugin:3.2.1'
  28. }
  29. }
  30.  
  31.  
  32.  
  33. docker {
  34. url = "tcp://remote-docker-host:2375"
  35. registryCredentials {
  36. username = 'AWS'
  37. password = System.getProperty("DOCKER_PASS") // Need to provide at runtime !!!
  38. url = 'https://123456789123.dkr.ecr.eu-west-1.amazonaws.com'
  39. }
  40. }
  41.  
  42. task getECRPassword(type: EcrLoginTask) {
  43. accessKey AWS_KEY
  44. secretCode AWS_SECRET
  45. region AWS_REGION
  46. registryId '139539380579'
  47. }
  48.  
  49. task dbuild(type: DockerBuildImage) {
  50. dependsOn build
  51. inputDir = file(".")
  52. tag "139539380579.dkr.ecr.eu-west-1.amazonaws.com/n6duplicator"
  53. }
  54.  
  55. task dpush(type: DockerPushImage) {
  56. dependsOn dbuild, getECRPassword
  57. imageName "123456789123.dkr.ecr.eu-west-1.amazonaws.com/n6duplicator"
  58. }
Add Comment
Please, Sign In to add comment