Skip to content
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
51 changes: 51 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Java CI/CD with Docker and AWS ECR

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-push:
runs-on: ubuntu-latest

env:
ECR_REGISTRY: 794038257373.dkr.ecr.ap-south-1.amazonaws.com
ECR_REPOSITORY: test-repo

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Build project with Maven
run: mvn clean package --file pom.xml

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-south-1

- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build Docker image
run: |
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
MERGE_ID=$(echo "${{ github.sha }}" | cut -c1-7)
IMAGE_TAG="${TIMESTAMP}-${MERGE_ID}"
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .

- name: Push image to ECR
run: |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI/CD - Java Maven Docker to ECR

on:
push:
branches:
- main
# Trigger on merge (PR closed and merged)
types: [closed]

jobs:
build-and-deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

env:
IMAGE_TAG: ${{ github.sha }}

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Maven
run: mvn clean package -DskipTests

- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set Image Tag with Timestamp and Merge ID
id: set-tag
run: |
DATE=$(date +%Y-%m-%d)
TIME=$(date +%H-%M)
MERGE_ID=${{ github.event.pull_request.merge_commit_sha }}
TAG="${DATE}-${TIME}-${MERGE_ID}"
echo "TAG=$TAG" >> $GITHUB_ENV
echo "Final tag will be: $TAG"

- name: Build Docker Image
run: |
docker build -t ${{ secrets.ECR_REPOSITORY }}:$TAG .

- name: Push Docker Image to ECR
run: |
docker push ${{ secrets.ECR_REPOSITORY }}:$TAG
1 change: 1 addition & 0 deletions Ekart
Submodule Ekart added at c8318a
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ There is a login and registration functionality included.
Users can shop for products. Each user has his own shopping cart (session functionality).
Checkout is transactional.

## Configuration

## Configurationfeature/home-ui-fix

### Configuration Files

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM openjdk:8u151-jdk-alpine3.7

EXPOSE 8070
EXPOSE 8080

ENV APP_HOME /usr/src/app

COPY target/shopping-cart-0.0.1-SNAPSHOT.jar $APP_HOME/app.jar

WORKDIR $APP_HOME

ENTRYPOINT exec java -jar app.jar
ENTRYPOINT exec java -jar app.jar