diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0e48762 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: Java CI with Maven and Docker + +on: + push: + branches: [ "master", "main" ] + pull_request: + branches: [ "master", "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + cache: maven + + - name: Verify Java version + run: java -version + + - name: Build with Maven + run: mvn -B clean package --file pom.xml + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=sha + type=ref,event=branch + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index e3cb1a9..0000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,37 +0,0 @@ -# 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: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - 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 clean package --file pom.xml - #- name: DeepSeek CR - # uses: hustcer/deepseek-review@v1.12 - - # 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 diff --git a/Dockerfile b/Dockerfile index c001670..be581ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,26 @@ -FROM eclipse-temurin:17-jdk-alpine -MAINTAINER megadotnet -ENV TZ=Asia/Shanghai -VOLUME /tmp -ARG JAR_FILE -ADD target/*.jar app.jar -ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] - -HEALTHCHECK --start-period=30s --interval=30s --timeout=5s --retries=3 CMD curl -m 5 --silent --fail --request GET http://localhost:7080/actuator/health | jq --exit-status -n 'inputs | if has("status") then .status=="UP" else false end' > /dev/null || exit 1 +FROM eclipse-temurin:21-jdk-jammy AS build + +RUN apt-get update && apt-get install -y maven + +WORKDIR /app + +COPY pom.xml . +COPY src ./src + +RUN mvn clean package -DskipTests + +FROM eclipse-temurin:21-jre-jammy + +ENV SERVER_PORT=8080 + +RUN groupadd -r appuser && useradd -r -g appuser appuser + +USER appuser + +WORKDIR /app + +COPY --from=build /app/target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3bc83b1..8083ab4 100644 --- a/pom.xml +++ b/pom.xml @@ -7,8 +7,7 @@ jar spring-boot demo application - 21 - 21 + 21 2.14.0 3.14.0 0.6.0 @@ -30,8 +29,7 @@ maven-compiler-plugin 3.8.1 - 21 - 21 + 21 diff --git a/src/main/java/com/app/login/service/impl/MailServiceImpl.java b/src/main/java/com/app/login/service/impl/MailServiceImpl.java index 460b9c2..5d31069 100644 --- a/src/main/java/com/app/login/service/impl/MailServiceImpl.java +++ b/src/main/java/com/app/login/service/impl/MailServiceImpl.java @@ -56,7 +56,7 @@ public class MailServiceImpl implements IMailService { private String baseUrlValue; - public MailServiceImpl(JavaMailSender javaMailSender, MessageSource messageSource, SpringTemplateEngine templateEngine) { + public MailServiceImpl(JavaMailSender javaMailSender, @org.springframework.beans.factory.annotation.Qualifier("messageSource") MessageSource messageSource, SpringTemplateEngine templateEngine) { this.javaMailSender = javaMailSender; this.messageSource = messageSource;