diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..31001b5 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,35 @@ +name: Build Docker Image + +on: + push: + pull_request: + +jobs: + build: + runs-on: self-hosted + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Java + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: '17' + + - name: Build with Maven + run: mvn clean package -DskipTests + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: anusha0509/builddockerimage:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0358982 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Use official OpenJDK 17 image as base image +FROM maven:3.9.9-eclipse-temurin-17-alpine AS build + +# Set working directory +WORKDIR /app + +# Copy the jar built by Maven/Gradle +COPY target/*.jar app.jar + +# Expose port (adjust if needed) +EXPOSE 8080 + +# Run the application +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/pom.xml b/pom.xml index 823a73d..9c90446 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ SpringBootMavenExample SpringBootMavenExample SpringBootMavenExample - war + jar org.springframework.boot spring-boot-starter-parent @@ -12,7 +12,7 @@ - 1.7 + 17 @@ -41,4 +41,5 @@ - \ No newline at end of file + +