diff --git a/.github/workflows/analytics-ci.yml b/.github/workflows/analytics-ci.yml new file mode 100644 index 0000000..1bfb406 --- /dev/null +++ b/.github/workflows/analytics-ci.yml @@ -0,0 +1,109 @@ +name: Analytics CI + +on: + push: + branches: [ main, develop ] + paths: + - 'analytics/**' + - 'common/**' + - 'build.gradle' + - 'settings.gradle' + pull_request: + branches: [ main ] + paths: + - 'analytics/**' + - 'common/**' + - 'build.gradle' + - 'settings.gradle' + +env: + ACR_NAME: acrdigitalgarage03 + IMAGE_NAME: hiorder/analytics + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-version: '8.13' + + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build common module + run: ./gradlew common:build -x test + + - name: Build analytics module + run: ./gradlew analytics:build -x test + + - name: Run analytics tests + run: ./gradlew analytics:test + + - name: Generate build timestamp + id: timestamp + run: echo "BUILD_TIME=$(date +'%y%m%d%H%M')" >> $GITHUB_OUTPUT + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Azure Container Registry + uses: azure/docker-login@v1 + with: + login-server: ${{ env.ACR_NAME }}.azurecr.io + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./analytics/Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }} + ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Output image tags + run: | + echo "๐ŸŽ‰ Image pushed successfully!" + echo "๐Ÿ“ฆ Image: ${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}" + echo "๐Ÿท๏ธ Tags: ${{ steps.timestamp.outputs.BUILD_TIME }}, latest" + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: analytics-test-results + path: analytics/build/reports/tests/test/ + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + if: success() + with: + name: analytics-jar + path: analytics/build/libs/*.jar \ No newline at end of file diff --git a/analytics/Dockerfile b/analytics/Dockerfile new file mode 100644 index 0000000..d9002e9 --- /dev/null +++ b/analytics/Dockerfile @@ -0,0 +1,51 @@ +# Analytics ์„œ๋น„์Šค์šฉ Dockerfile +FROM eclipse-temurin:21-jdk-alpine AS builder + +# ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ • +WORKDIR /app + +# Gradle Wrapper์™€ ์„ค์ • ํŒŒ์ผ ๋ณต์‚ฌ +COPY gradlew . +COPY gradle/wrapper gradle/wrapper +COPY build.gradle . +COPY settings.gradle . + +# ์†Œ์Šค ์ฝ”๋“œ ๋ณต์‚ฌ +COPY common common/ +COPY analytics analytics/ + +# ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ ๋ฐ ๋นŒ๋“œ +RUN chmod +x ./gradlew +RUN ./gradlew analytics:build -x test --no-daemon + +# ์‹คํ–‰ ๋‹จ๊ณ„ +FROM eclipse-temurin:21-jre-alpine + +# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‚ฌ์šฉ์ž ์ƒ์„ฑ +RUN addgroup -g 1001 -S appgroup && \ + adduser -u 1001 -S appuser -G appgroup + +# ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ • +WORKDIR /app + +# ๋นŒ๋“œ๋œ JAR ํŒŒ์ผ ๋ณต์‚ฌ +COPY --from=builder /app/analytics/build/libs/analytics-*.jar app.jar + +# ํŒŒ์ผ ์†Œ์œ ๊ถŒ ๋ณ€๊ฒฝ +RUN chown -R appuser:appgroup /app + +# ์‚ฌ์šฉ์ž ๋ณ€๊ฒฝ +USER appuser + +# ํฌํŠธ ๋…ธ์ถœ +EXPOSE 8080 + +# ํ—ฌ์Šค์ฒดํฌ ์ถ”๊ฐ€ +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1 + +# JVM ์˜ต์…˜ ์„ค์ • +ENV JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:+UseStringDeduplication" + +# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ +ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"] \ No newline at end of file