https://github.com/GoogleContainerTools/jib/tree/master/examples/multi-module
Try.
--I think it's common to use com.palantir.docker
for gradle, but I didn't know how to make it work with multi project.
――In addition, ECR registration was very troublesome for com.palantir.docker
.
――I wanted to use jib.
rootProject--sample1 ← This is the repository that pushes to ECR
--sample2
https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin#quickstart Correct it like that while watching. It is important to put apply false in the rootProject plugins. If you do not enter this, an error will occur.
build.gradle(Excerpt from rootProject)
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version "1.0.10.RELEASE"
id 'com.google.cloud.tools.jib' version '2.6.0' apply false
}
ext {
artifactGroup = 'prototype.app'
artifactVersion = '1.0.0'
springBootDependenciesVersion = '2.3.4.RELEASE'
}
/*Common to all projects*/
allprojects {
ext {
set('extention', 'jar')
set('artifactVersion', "${artifactVersion}")
}
repositories {
mavenCentral()
jcenter()
gradlePluginPortal()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
/*Common to Java projects*/
configure(subprojects) {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
// Spring Boot
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootDependenciesVersion}"
}
imports {
// AWS SDK ver 2.X.X
mavenBom "software.amazon.awssdk:bom:2.14.14"
}
}
dependencies {
// for Develop
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
}
}
/*Common to Docker projects*/
configure(subprojects - project('sample2') ) {
apply plugin: "com.google.cloud.tools.jib"
}
build.gradle(sample1 excerpt)
plugins {
id 'com.google.cloud.tools.jib'
}
jib {
from {
image = 'amazoncorretto:11'
}
to {
image = "XXXXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/prototype"
// tags = ["${artifactVersion}"]
}
container {
environment = [SPRING_PROFILES_ACTIVE:"prod"]
}
}
Codebuild is also used, so create buildspec.yml. If you do not create an ECR repository, an error will occur, so I created it with terraform in advance. Also, I usually don't do this, but I added a docker pull and run in the post_build phase to see if it works.
buildspec.yml
version: 0.2
env:
variables:
# FIXME:
AWS_ACCOUNT : "XXXXXXXXXXXXX"
IMAGE_REPO : "prototype"
TAG : "latest"
phases:
install:
runtime-versions:
java: corretto11
commands:
- chmod +x ./gradlew
- touch gradle.properties
- |
cat <<EOL >> gradle.properties
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
EOL
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay&
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
pre_build:
commands:
- echo build start on `date`
- $(aws ecr get-login --no-include-email)
build:
commands:
- ./gradlew build
- ./gradlew :sample1:jib --info
post_build:
commands:
#For operation check
- docker pull ${AWS_ACCOUNT}.dkr.ecr.ap-northeast-1.amazonaws.com/${IMAGE_REPO}:${TAG}
- docker run -p 8080:8080 ${AWS_ACCOUNT}.dkr.ecr.ap-northeast-1.amazonaws.com/${IMAGE_REPO}:${TAG}
- echo build end on `date`
cache:
paths:
- /root/.gradle/caches/**/*
- /root/.gradle/wrapper/**/*
At first, I was hit by the ECR specifications, but it worked. (The log has been modified like that)
Status: Downloaded newer image for XXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/prototype:latest
XXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/prototype:latest
[Container] 2020/11/14 04:44:20 Running command docker run -p 8080:8080 ${AWS_ACCOUNT}.dkr.ecr.ap-northeast-1.amazonaws.com/${IMAGE_REPO}:${TAG}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.4.RELEASE)
2020-11-14 04:44:24.281 INFO 1 --- [ main] p.b.transfer.BeforeTransferApplication : Starting BeforeTransferApplication on f2ceab1be0d6 with PID 1 (/app/classes started by root in /)
2020-11-14 04:44:24.283 INFO 1 --- [ main] p.b.transfer.BeforeTransferApplication : The following profiles are active: prod
2020-11-14 04:44:25.481 INFO 1 --- [ main] p.b.transfer.BeforeTransferApplication : Started BeforeTransferApplication in 1.636 seconds (JVM running for 2.084)
[Container] 2020/11/14 04:44:25 Running command echo build end on `date`
build end on Sat Nov 14 04:44:25 UTC 2020
Recommended Posts