diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..aa2ec13a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,183 @@ +# Maven +target/ +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# Maven +.mvn/ +mvnw +mvnw.cmd + +# IDE +.idea/ +*.iws +*.iml +*.ipr +.vscode/ +.classpath +.project +.settings/ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Logs +logs/ +*.log +*.log.* + +# Runtime +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage/ +*.lcov + +# Dependency directories +node_modules/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Temporary folders +tmp/ +temp/ + +# Git +.git/ +.gitignore + +# GitHub +.github/ + +# Docker +docker-compose*.yml +Dockerfile* +.dockerignore + +# Documentation +README.md +LICENSE +*.md +docs/ + +# Testing +src/test/ +**/test/ +**/tests/ +pom.xml.test +*.test + +# Build artifacts +*.tar.gz +*.zip +*.rar +*.7z + +# Spring Boot +.gradle/ +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +# Gradle +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +# Java +*.class +*.log + +# Package Files +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# Virtual Machine crash logs +hs_err_pid* +replay_pid* + +# Eclipse +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# NetBeans +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +# IntelliJ +.idea/ +*.iws +*.iml +*.ipr + +# Visual Studio Code +.vscode/ + +# Mac +.DS_Store +.AppleDouble +.LSOverride + +# Windows +Thumbs.db +ehthumbs.db +Desktop.ini + +# Linux +*~ + +# Backup files +*.bak +*.backup +*.old +*.orig + +# Build directories +build/ +dist/ +out/ + +# CI/CD +.travis.yml +.gitlab-ci.yml +circleci/ +.github/ \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..1895d395 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,132 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - master + - develop + tags: + - 'v*.*.*' + pull_request: + branches: + - main + - master + - develop + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + + - name: Log in to Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha,prefix={{branch}}- + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + BUILD_DATE=${{ steps.meta.outputs.created }} + VERSION=${{ steps.meta.outputs.version }} + REVISION=${{ github.sha }} + + # 验证任务:测试构建 + validate: + runs-on: ubuntu-latest + needs: build-and-push + if: github.event_name == 'pull_request' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + + - name: Validate Maven build + run: | + mvn clean compile -B + + - name: Run unit tests + run: | + mvn test -B + continue-on-error: true + + - name: Test Docker image build + run: | + docker build -t efak-test:build --progress=plain . + + # 发布任务:用于版本发布 + release: + runs-on: ubuntu-latest + needs: build-and-push + if: startsWith(github.ref, 'refs/tags/v') + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download release asset + run: | + # 创建发布包 + mkdir -p release + # 这里可以添加构建安装包等步骤 + echo "Creating release assets..." + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + files: release/* + generate_release_notes: true + draft: false + prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5ead50ac..feefa281 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ RUN mvn clean package -DskipTests -B # ======================================== # 第二阶段:运行阶段 # ======================================== -FROM openjdk:17-jdk-slim +FROM eclipse-temurin:17-jdk # 设置维护者信息 LABEL maintainer="Mr.SmartLoli "