Create maven.yml #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |