diff --git a/.github/workflows/eksdeployment.yml b/.github/workflows/eksdeployment.yml new file mode 100644 index 0000000..7f23c5a --- /dev/null +++ b/.github/workflows/eksdeployment.yml @@ -0,0 +1,65 @@ +name: Deploy to ECR + +on: + + push: + branches: [ main ] + +env: + ECR_REPOSITORY: tessolve-ecr + EKS_CLUSTER_NAME: tessolve-eks + AWS_REGION: us-east-1 + +jobs: + + build: + + name: Deployment + runs-on: ubuntu-latest + + steps: + + - name: Set short git commit SHA + id: commit + uses: prompt/actions-commit-hash@v2 + + - name: Check out code + uses: actions/checkout@v2 + - name: Set up JDK 14 + uses: actions/setup-java@v1 + with: + java-version: 14 + + - name: Build project with Maven + run: mvn -B package --file pom.xml + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{env.AWS_REGION}} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ steps.commit.outputs.short }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Update kube config + run: aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region $AWS_REGION + + - name: Deploy to EKS + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ steps.commit.outputs.short }} + run: | + kubectl apply -f k8s-resources/deployment.yaml + kubectl apply -f k8s-resources/service.yaml + kubectl apply -f k8s-resources/config-map.yaml diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml new file mode 100644 index 0000000..638cbbe --- /dev/null +++ b/.github/workflows/pullrequest.yml @@ -0,0 +1,19 @@ +name: Pull Request Action +on: + push: + branches: + - main + +jobs: + create-pull-request: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - name: pull-request + uses: actions/checkout@v3 + with: + destination_branch: "develop" + github_token: ${{ secrets.GGITHUB_TOKEN }} + pr_label: "feature, automated pr" + pr_title: "[Example] Simple demo" diff --git a/.github/workflows/terraformdeploy.yml b/.github/workflows/terraformdeploy.yml new file mode 100644 index 0000000..9e7b959 --- /dev/null +++ b/.github/workflows/terraformdeploy.yml @@ -0,0 +1,55 @@ +name: Terraform AWS Workflow + +on: + workflow_call: + workflow_dispatch: + # Inputs the workflow accepts. + inputs: + tfpath: + description: 'TF File Path' + required: false + default: Terraform/terraform_AWs + push: + branches: [ main ] + + +jobs: + tf_code_check: + name: Terraform Validation and Build + runs-on: ubuntu-latest + + if: ${{ inputs.tfpath }} + steps: + - name: Checkout tf code in runner environment + uses: actions/checkout@v3.5.2 + + - name: Configure AWS Credentials Action For GitHub Actions + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Setup Terraform CLI + uses: hashicorp/setup-terraform@v2.0.2 + + - name: Terraform init and validate + run: | + echo `pwd` + echo "tfpath ${{ github.event.inputs.tfpath }}" + echo "** Running Terraform Init**" + terraform init + + echo "** Running Terraform Validate**" + terraform validate + working-directory: ${{ github.event.inputs.tfpath }} + - name: Terraform plan and apply + run: | + echo `pwd` + echo "tfpath ${{ github.event.inputs.tfpath }}" + echo "** Running Terraform Plan**" + terraform plan + + echo "** Running Terraform Apply**" + terraform apply -auto-approve + working-directory: ${{ github.event.inputs.tfpath }} diff --git a/Dockerfile b/Dockerfile index 788134f..5ffcf23 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,13 @@ VOLUME /target RUN addgroup -S demo-app && adduser -S demo-app -G demo-app USER demo-app:demo-app ARG DEPENDENCY=target/dependency -COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib -COPY ${DEPENDENCY}/META-INF /app/META-INF -COPY ${DEPENDENCY}/BOOT-INF/classes /app -COPY ${DEPENDENCY}/org /app/org +COPY . /app +#COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib +#COPY ${DEPENDENCY}/META-INF /app/META-INF +#COPY ${DEPENDENCY}/BOOT-INF/classes /app +#COPY ${DEPENDENCY}/org /app/org EXPOSE 8080 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-cp","app:app/lib/*", "com/amazon/aws/SpringBootSessionApplication"] +##ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-cp","app:app/lib/*"] diff --git a/k8s-resources/config-map.yaml b/k8s-resources/config-map.yaml index 324e84c..7397ae1 100644 --- a/k8s-resources/config-map.yaml +++ b/k8s-resources/config-map.yaml @@ -4,5 +4,7 @@ metadata: name: java-ms namespace: default data: - host: "***.***.9vakxk.0001.euc1.cache.amazonaws.com" + + #host: "***.***.9vakxk.0001.euc1.cache.amazonaws.com" + host: "redisaws.19uty9.clustercfg.use1.cache.amazonaws.com" port: "6379" diff --git a/k8s-resources/deployment.yaml b/k8s-resources/deployment.yaml index e576b8b..63cf912 100644 --- a/k8s-resources/deployment.yaml +++ b/k8s-resources/deployment.yaml @@ -6,7 +6,7 @@ metadata: labels: app: java-ms spec: - replicas: 3 + replicas: 1 selector: matchLabels: app: java-ms @@ -17,15 +17,15 @@ spec: spec: containers: - name: java-ms - image: bastianklein/java-ms:1.2 + image: 975050223236.dkr.ecr.us-east-1.amazonaws.com/tessolve-ecr:569b40c imagePullPolicy: Always resources: requests: cpu: "500m" #half the CPU free: 0.5 Core memory: "256Mi" limits: - cpu: "1000m" #max 1.0 Core - memory: "512Mi" + cpu: "700m" #max 1.0 Core + memory: "412Mi" env: - name: SPRING_REDIS_HOST valueFrom: diff --git a/terraformECR.tf b/terraformECR.tf new file mode 100644 index 0000000..5615d6f --- /dev/null +++ b/terraformECR.tf @@ -0,0 +1,17 @@ + + + + + + + + + +resource "aws_ecr_repository" "foo" { + name = "jave-app-ecr2" + image_tag_mutability = "MUTABLE" + + image_scanning_configuration { + scan_on_push = true + } +}