diff --git a/.github/workflows/himanshu.yml b/.github/workflows/himanshu.yml new file mode 100644 index 0000000..c71092c --- /dev/null +++ b/.github/workflows/himanshu.yml @@ -0,0 +1,47 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "feature" ] + pull_request: + branches: [ "feature" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + cache: maven + - name: Build with Maven + run: ./mvnw -B package + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + #- name: Update dependency graph + # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + + - name: Build Docker image + run: docker build -t himanshudxm/github-actions-docker-java-app:0.0.1.Release . + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push Docker Image + run: docker push himanshudxm/github-actions-docker-java-app:0.0.1.Release diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..973fb6a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# syntax=docker/dockerfile:1 + +FROM eclipse-temurin:17-jdk-jammy as base +WORKDIR /app +COPY .mvn/ .mvn +COPY mvnw pom.xml ./ +RUN ./mvnw dependency:resolve +COPY src ./src + +FROM base as test +RUN ["./mvnw", "test"] + +FROM base as development +CMD ["./mvnw", "spring-boot:run", "-Dspring-boot.run.profiles=mysql", "-Dspring-boot.run.jvmArguments='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000'"] + +FROM base as build +RUN ./mvnw package + +FROM eclipse-temurin:17-jre-jammy as production +EXPOSE 8080 +COPY --from=build /app/target/spring-petclinic-*.jar /spring-petclinic.jar +CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/spring-petclinic.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ef62437 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: "2.2" + +services: + my-app: + image: himanshudxm/github-actions-docker-java-app:0.0.1.Release + ports: + - "5000:5000" + mysql: + image: mysql:8.0 + ports: + - "3306:3306" + environment: + - MYSQL_ROOT_PASSWORD= + - MYSQL_ALLOW_EMPTY_PASSWORD=true + - MYSQL_USER=petclinic + - MYSQL_PASSWORD=petclinic + - MYSQL_DATABASE=petclinic + volumes: + - "./conf.d:/etc/mysql/conf.d:ro" + profiles: + - mysql + postgres: + image: postgres:15.3 + ports: + - "5432:5432" + environment: + - POSTGRES_PASSWORD=petclinic + - POSTGRES_USER=petclinic + - POSTGRES_DB=petclinic + profiles: + - postgres