diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..3c74262 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,39 @@ +name: Build and Dockerize Java Application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build-and-dockerize: + runs-on: ubuntu-latest + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Build Docker image + run: docker build -t my-java-app:latest . + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.GITHUB_ACTOR }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push Docker image to Docker Hub + run: | + docker tag my-java-app:latest Olooce/my-java-app:latest + docker push Olooce/my-java-app:latest