Since faster Java development by Oracle, every tool we use these days need to follow up for every Java release or just support only LTS versions like Amazon. CodeBuild is AWS-hosted tool for building software applications and 3 months after stable Java 11 release still it does not support anything newer than Java 9. Time is up, now we will build our own build environment which will support Java 11 and Java 12 in future right after stable release.
- AWS CLI
- Amazon ECR
We are going to need nothing special for this. AWS CLI with AWS account obliviously. Installed docker on our local machine to build image and some basic knowledge how docker works and how proper Dockerfile should looks like. Basically we will create build environment which will be used during CodeBuild process using docker images. After that we will push created image to Amazon ECR. ECR is container registry like docker hub but managed by Amazon. Eventually we will use our image as build environment. Now it’s time to start “fixing” CodeBuild.
First of all we need to should create our own
Dockerfile with environment.
I used official
maven image from Docker Hub, we can choose there maven and Java version.
I added few environment variables and own
CMD to show
mvn --version on start instead running just
because this leads to failing CodeBuild process.
Pushing to ECR
Now we can create new repository on Amazon ECR
Sign in to ECR with
Build docker image with:
and try to run it using:
and ensure that maven displays installed version.
If everything work as expected, we can tag and push our image to ECR service.
Before we start using our container we need to setup proper access policy for CodeBuild service.
This need to be done using internal ECR policy management (not the standard AWS roles/policies!)
Amazon ECR > Repositories > Permissions > Edit policy JSON
We allow the CodeBuild service to get docker images, download them and check their availability.
The last step is to configure CodeBuild environment, like bellow.
And here we go! We can finally use latest Java features and push it to the production right away!
Next version is scheduled to March 2019, so we will go through this steps again but on
we will just change
maven:3.6-jdk-12. Even now we can do this because we can find docker images
with beta releases of Java 12.