Skip to content

change the description #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
target/
/bin/
**/*.jar
*.jar
.DS_Store

18 changes: 18 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DemoApplication</name>
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Dockerfile
FROM 338918620411.dkr.ecr.eu-west-1.amazonaws.com/openjdk8:latest
ARG ISSUE_FLAG
ARG IAM_ROLE
ARG SQS_URL
ARG S3_BUCKET
ENV ISSUE_FLAG_ENV=${ISSUE_FLAG}
ENV IAM_ROLE_ENV=${IAM_ROLE}
ENV SQS_URL_ENV=${SQS_URL}
ENV S3_BUCKET_ENV=${S3_BUCKET}
ENV DEMO_HOME=/usr/demo
COPY DemoApplication-1.0-jar-with-dependencies.jar $DEMO_HOME/
WORKDIR $DEMO_HOME
CMD java -jar DemoApplication-1.0-jar-with-dependencies.jar ${ISSUE_FLAG_ENV} ${IAM_ROLE_ENV} ${SQS_URL_ENV} ${S3_BUCKET_ENV}
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!bin/bash
mvn clean package
cp target/DemoApplication-1.0-jar-with-dependencies.jar .
aws s3 cp target/DemoApplication-1.0-jar-with-dependencies.jar s3://338918620411-account-bucket/DemoApplication-1.0-jar-with-dependencies.jar
51 changes: 51 additions & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
version: 0.2
phases:
install:
commands:
- curl -sS -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator
- curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- chmod +x ./kubectl ./aws-iam-authenticator
- export PATH=$PWD/:$PATH
- yum -y install jq python3-pip python3-dev && pip3 install --upgrade awscli
pre_build:
commands:
- $(aws ecr get-login --no-include-email)
- export KUBECONFIG=$HOME/.kube/config
- aws s3 cp s3://338918620411-account-bucket/DemoApplication-1.0-jar-with-dependencies.jar .

build:
commands:
- ls -xtra
- echo "Contents of Dockerfile"
- cat Dockerfile
- echo Got the following IAM_ROLE env $IAM_ROLE
- echo Got the following SQS_URL env $SQS_URL
- echo Got the following S3_BUCKET env $S3_BUCKET

# building Docker image without-issues
- docker build -f Dockerfile -t codeguru-java-app-deployment-without-issues --build-arg ISSUE_FLAG="without-issues" --build-arg IAM_ROLE=$IAM_ROLE --build-arg SQS_URL=$SQS_URL --build-arg S3_BUCKET=$S3_BUCKET .
- docker tag codeguru-java-app-deployment-without-issues:latest 338918620411.dkr.ecr.eu-west-1.amazonaws.com/codeguru-java-app-deployment-without-issues:latest
- docker push 338918620411.dkr.ecr.eu-west-1.amazonaws.com/codeguru-java-app-deployment-without-issues:latest
# building Docker image with-issues
- docker build -f Dockerfile -t codeguru-java-app-deployment-with-issues --build-arg ISSUE_FLAG="with-issues" --build-arg IAM_ROLE=$IAM_ROLE --build-arg SQS_URL=$SQS_URL --build-arg S3_BUCKET=$S3_BUCKET .
- docker tag codeguru-java-app-deployment-with-issues:latest 338918620411.dkr.ecr.eu-west-1.amazonaws.com/codeguru-java-app-deployment-with-issues:latest
- docker push 338918620411.dkr.ecr.eu-west-1.amazonaws.com/codeguru-java-app-deployment-with-issues:latest

post_build:
commands:
- CREDENTIALS=$(aws sts assume-role --role-arn $EKS_KUBECTL_ROLE_ARN --role-session-name codebuild-kubectl --duration-seconds 900)
- export AWS_ACCESS_KEY_ID="$(echo ${CREDENTIALS} | jq -r '.Credentials.AccessKeyId')"
- export AWS_SECRET_ACCESS_KEY="$(echo ${CREDENTIALS} | jq -r '.Credentials.SecretAccessKey')"
- export AWS_SESSION_TOKEN="$(echo ${CREDENTIALS} | jq -r '.Credentials.SessionToken')"
- export AWS_EXPIRATION=$(echo ${CREDENTIALS} | jq -r '.Credentials.Expiration')
- echo $AWS_ACCESS_KEY_ID $AWS_EXPIRATION
- aws eks update-kubeconfig --name $EKS_CLUSTER_NAME
- kubectl config get-contexts
- kubectl get nodes
- kubectl apply -f codeguru-java-app-deployment-without-issues.yaml
- kubectl apply -f codeguru-java-app-deployment-with-issues.yaml
- kubectl get all -n default
- echo $EKS_KUBECTL_ROLE_ARN:$EKS_CLUSTER_NAME > build.json
artifacts:
files: build.json
20 changes: 20 additions & 0 deletions codeguru-java-app-deployment-with-issues.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: codeguru-java-app-deployment-with-issues
labels:
app: codeguru-demo-app
spec:
replicas: 1
selector:
matchLabels:
app: codeguru-demo-app
template:
metadata:
labels:
app: codeguru-demo-app
spec:
serviceAccountName: codeguru-profiler
containers:
- name: codeguru-java-app-deployment-with-issues
image: 338918620411.dkr.ecr.eu-west-1.amazonaws.com/codeguru-java-app-deployment-with-issues:latest
20 changes: 20 additions & 0 deletions codeguru-java-app-deployment-without-issues.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: codeguru-java-app-deployment-without-issues
labels:
app: codeguru-demo-app
spec:
replicas: 1
selector:
matchLabels:
app: codeguru-demo-app
template:
metadata:
labels:
app: codeguru-demo-app
spec:
serviceAccountName: codeguru-profiler
containers:
- name: codeguru-java-app-deployment-without-issues
image: 338918620411.dkr.ecr.eu-west-1.amazonaws.com/codeguru-java-app-deployment-without-issues:latest
56 changes: 49 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<groupId>com.company.demoapplication</groupId>
<artifactId>DemoApplication</artifactId>
<version>1.0</version>
<repositories>
<repository>
<id>codeguru-profiler</id>
<name>codeguru-profiler</name>
<url>https://d1osg35nybn3tt.cloudfront.net</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -69,11 +76,6 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.747</version>
</dependency>
<dependency>
<groupId>org.imgscalr</groupId>
<artifactId>imgscalr-lib</artifactId>
Expand Down Expand Up @@ -104,5 +106,45 @@
<artifactId>log4j-jul</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.1018</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>1.11.1018</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sts</artifactId>
<version>2.16.62</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
<version>2.16.62</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>codeguru-profiler-java-agent</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>regions</artifactId>
<version>2.16.62</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
</dependencies>
</project>
</project>
29 changes: 29 additions & 0 deletions src/main/java/com/company/demoapplication/AwsCredsProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.company.demoapplication;

import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.services.sts.StsClient;
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider;
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest;



public class AwsCredsProvider {

public static AwsCredentialsProvider getCredentials(final String roleArn, final String sessionName) {

Main.logger().info("Building the STS request for roleArn: {} and session: {}", roleArn, sessionName);

final AssumeRoleRequest assumeRoleRequest = AssumeRoleRequest.builder()
.roleArn(roleArn)
.roleSessionName(sessionName)
.build();


return StsAssumeRoleCredentialsProvider.builder()
.stsClient(StsClient.builder().credentialsProvider(DefaultCredentialsProvider.create()).build())
.refreshRequest(assumeRoleRequest)
.build();
}

}
Loading