diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a429a2a98..1c316102b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,28 @@ # This workflow will build a Java project with Gradle # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - +# name - optional name: Java CI with Gradle - +# Events (required) on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - + workflow_dispatch: + inputs: + environment: + description: 'CI' + required: true + default: 'dev' +# push: +# branches: +# - master +# - sanchitavrm-patch-1 +# pull_request: +# branches: [ master ] + +# Include set of actions jobs: build-java: runs-on: ubuntu-latest + environment: dev # this line enables access to the secrets steps: - uses: actions/checkout@v2 @@ -26,13 +36,19 @@ jobs: run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew build + run: | + ./gradlew build + ls build/libs/ + +# marketplace actions - name: Build and Push Docker Image uses: mr-smithers-excellent/docker-build-push@v4 with: - image: nanajanashia/demo-app + image: sanchitavrm/demo-app registry: docker.io username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + + diff --git a/.github/workflows/ci_ecr b/.github/workflows/ci_ecr new file mode 100644 index 000000000..1e1e5276a --- /dev/null +++ b/.github/workflows/ci_ecr @@ -0,0 +1,78 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle +# name - optional +name: Java CI with Gradle, Push to ECR +# Events (required) +on: + workflow_dispatch: + inputs: + environment: + description: 'CI' + required: true + default: 'dev' +env: + AWS_REGION: us-east-1 # Change to your region + ECR_REPOSITORY: dev/github-action # Change to your ECR repo name + IMAGE_TAG: latest # Can be dynamic (e.g., Git SHA or version) + + +push: + branches: + - master + - sanchitavrm-patch-1 +# pull_request: +# branches: [ master ] + +# Include set of actions +jobs: + build-java: + + runs-on: ubuntu-latest + environment: dev # this line enables access to the secrets + + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: | + ./gradlew build + ls build/libs/ + + + - 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: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + + - name: Build Docker Image + run: | + docker build -t $ECR_REPOSITORY:$IMAGE_TAG . + + - name: Tag Docker Image for ECR + run: | + ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) + IMAGE_URI=$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$IMAGE_TAG + docker tag $ECR_REPOSITORY:$IMAGE_TAG $IMAGE_URI + echo "IMAGE_URI=$IMAGE_URI" >> $GITHUB_ENV + + - name: Push Docker Image to ECR + run: | + docker push $IMAGE_URI + + + diff --git a/settings.gradle b/settings.gradle index 16c6008c0..630eba3a6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -rootProject.name = 'java-app' +rootProject.name = 'my-app'