How it works...

  1. Open the AWS console and go to the AWS CodeBuild service. You will get the CodeBuild console. Click on Get started:
  1. You will get a page where you have to fill all the details that I  mentioned earlier. The page will look as follows:
  1. We will mention the Project name as CB-Build-Book in the Configure your project section:
  1. In the Source section, choose AWS CodeCommit as Source provider and select the Repository name where you have migrated the book application. In my case, the AWS CodeCommit repository name, where the book application code resides, is CB-MAVEN-Book:
  1. In the Environment section, Environment image will be Use an image managed by AWS CodeBuild. The Operating System will be Ubuntu, Runtime will be Java, Version will be aws/codebuild/java:openjdk8, Build specification will be Insert build commands and Build command will be mvn install:
  1. Now in the Artifacts section, we have to use AWS S3 to store the build output. So, Artifact type will be Amazon S3. The Artifacts name will be book, Bucket name where you want to put the artifact; in my case, its awsstar-s3 and the Output files field will contain the file name which will be the build output, in my case, it's target/books.war  (you should know in what way the  build output will come):
  1. Now, Service role is the most important section over here, which allows AWS Codebuild to access another AWS resources such as CodeCommit and S3. In the initial stage, you can create a new service role. Else, you can create a new IAM Role, which will have the following policy document:
    {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CloudWatchLogsPolicy",
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"*"
]
},
{
"Sid": "CodeCommitPolicy",
"Effect": "Allow",
"Action": [
"codecommit:GitPull"
],
"Resource": [
"*"
]
},
{
"Sid": "S3GetObjectPolicy",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"*"
]
},
{
"Sid": "S3PutObjectPolicy",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"*"
]
}
]
}
  1. Once we create the policy, we need to create the IAM role, in which AWS Service role will be AWS CodeBuild and we will attach the newly created policy with the IAM role. Post that, we have to select a service role in the AWS CodeBuild Service Role section:
  1. In the Advanced section, we can tweak the compute settings and pass the environment variables, but at this moment, it is not required.
  2. Finally, we click on Continue and review the configuration:
  1. Once you are done reviewing, then click on Save and Build. We will be asked which branch we want to build:
  1. Once you select the master, the source version will show up automatically. Then, click on >Start Build We will see that the build process will start:
  1. We will see different phases of Build as well:
  1. In Build details section, we can see Output artifacts. When we click on the Build artifacts, we will be redirected to the S3 bucket, where our artifact will reside after the successful build:
  1. The following diagram shows the artifact in the S3 bucket:
  1. When you click on book, you will get a folder called target. Click on the target folder to get the books.war file: 
  1. Now, we can download  books.war into the server or machine, and copy  books.war to your webserver webapp directory and restart the webserver and access it from the web browser:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.47.144