Thursday, January 5, 2023

How to Build Java app on Github actions and deploy to S3 bucket

 

Step 1: Manually creating and deploying a Next.js project to a new S3 Bucket

To get started with our new S3 Bucket, first log in to your AWS account and navigate to the S3 service.


We’ll want to create a new bucket, using the name of our choice, which will be used for the S3 endpoint where our website is hosted. We’ll also want to configure our S3 bucket to be able to host a website.

Choose a bucket name of your choice
Also choose ACL enable
Uncheck the block all public access


Then click Create Bucket


After Bucket is created navigate to the bucket properties and click on properties. scroll al the way down and click on edit static web hosting


Then click enable


leave the option as host static website and in the index document type index.html


then click save changes.

then go to permission to edit the bucket policy with this code

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKETNAME/*"
        }
    ]
}


scroll down to the access control list and edit it to look like this 


 

After setting this go over to your github repository and create a new repo and in the new repo copy the folders you would like to build into the repository like we did in the previous classes and create a folder in the repository  called .github/workflows 

then in that folder create a file called deploy.yml and paste this code inside there



This code will help you run the package and deploys it into s3 bucket and you can view the static site with the link in the bucket.

Go to your Github repository -> settings -> secrets -> actions


Need to add two secrets: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (Secret access key) which will be used later in the workflow



Add AWS_SECRET  and also default region too in the same way.





Note: in the repository you have to add you AWS keys. This can be generated in the IAM console and you will input it in the repository settings.


No comments:

Post a Comment

Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, deploy WARs using Jenkins Pipeline - Build pipelines integrate with github, Sonarqube, Slack, JaCoCo, Nexus, Tomcat

  Jenkins Scripted Pipeline - Create Jenkins Pipeline for Automating Builds, Code quality checks, Deployments to Tomcat - How to build, depl...