diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 00000000..224bf932 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..9fd64232 --- /dev/null +++ b/.github/workflows/main.yml @@ -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 diff --git a/Ekart b/Ekart new file mode 160000 index 00000000..c8318aa3 --- /dev/null +++ b/Ekart @@ -0,0 +1 @@ +Subproject commit c8318aa375b44364808f0017e9d61a75bef38f25 diff --git a/README.md b/README.md index 8aff33f2..bac2609e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index 6a43a357..eb535eab 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ FROM openjdk:8u151-jdk-alpine3.7 -EXPOSE 8070 +EXPOSE 8080 ENV APP_HOME /usr/src/app @@ -8,4 +8,4 @@ COPY target/shopping-cart-0.0.1-SNAPSHOT.jar $APP_HOME/app.jar WORKDIR $APP_HOME -ENTRYPOINT exec java -jar app.jar \ No newline at end of file +ENTRYPOINT exec java -jar app.jar