diff --git a/.github/workflows/store-ci.yml b/.github/workflows/store-ci.yml new file mode 100644 index 0000000..219ff64 --- /dev/null +++ b/.github/workflows/store-ci.yml @@ -0,0 +1,186 @@ +name: Store CI + +on: + push: + branches: [ main, develop ] + paths: + - 'store/**' + - 'common/**' + - 'build.gradle' + - 'settings.gradle' + pull_request: + branches: [ main ] + paths: + - 'store/**' + - 'common/**' + - 'build.gradle' + - 'settings.gradle' + workflow_dispatch: + +env: + ACR_NAME: acrdigitalgarage03 + IMAGE_NAME: hiorder/store + MANIFEST_REPO: dg04-hi/hi-manifest + MANIFEST_FILE_PATH: store/deployment.yml + +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: Generate Gradle Wrapper + run: | + echo "Generating gradle wrapper..." + gradle wrapper --gradle-version 8.13 + chmod +x gradlew + echo "Testing gradle wrapper..." + ./gradlew --version + + - name: Build store module with dependencies + run: ./gradlew store:build -x test + + - name: Run store tests + run: ./gradlew store: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: ./store/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 + + - 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" + + # πŸš€ Manifest λ ˆν¬μ§€ν† λ¦¬ μ—…λ°μ΄νŠΈ 단계 μΆ”κ°€ + - name: Checkout manifest repository + uses: actions/checkout@v4 + with: + repository: ${{ env.MANIFEST_REPO }} + token: ${{ secrets.MANIFEST_REPO_TOKEN }} + path: manifest-repo + + - name: Install yq + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + + - name: Update deployment image tag + run: | + cd manifest-repo + NEW_IMAGE="${{ env.ACR_NAME }}.azurecr.io/${{ env.IMAGE_NAME }}:${{ steps.timestamp.outputs.BUILD_TIME }}" + echo "Updating image tag to: $NEW_IMAGE" + + # deployment.ymlμ—μ„œ 이미지 νƒœκ·Έ μ—…λ°μ΄νŠΈ + yq eval '.spec.template.spec.containers[0].image = "'$NEW_IMAGE'"' -i ${{ env.MANIFEST_FILE_PATH }} + + # 변경사항 확인 + echo "Updated deployment.yml:" + cat ${{ env.MANIFEST_FILE_PATH }} + + - name: Commit and push changes + run: | + cd manifest-repo + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + git add ${{ env.MANIFEST_FILE_PATH }} + + if git diff --staged --quiet; then + echo "No changes to commit" + else + git commit -m "πŸš€ Update store image tag to ${{ steps.timestamp.outputs.BUILD_TIME }} + + - Updated by: ${{ github.actor }} + - Triggered by: ${{ github.event_name }} + - Source commit: ${{ github.sha }} + - Build time: ${{ steps.timestamp.outputs.BUILD_TIME }}" + + git push + echo "βœ… Successfully updated manifest repository" + fi + + - name: Upload test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: store-test-results + path: store/build/reports/tests/test/ + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + if: success() + with: + name: store-jar + path: store/build/libs/*.jar + + # 🎯 배포 μ™„λ£Œ μ•Œλ¦Ό + - name: Deployment summary + if: success() + run: | + echo "## πŸš€ Store Service Deployment Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### πŸ“¦ Container Image" >> $GITHUB_STEP_SUMMARY + echo "- **Registry**: ${{ env.ACR_NAME }}.azurecr.io" >> $GITHUB_STEP_SUMMARY + echo "- **Image**: ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY + echo "- **Tag**: ${{ steps.timestamp.outputs.BUILD_TIME }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### πŸ”„ ArgoCD Sync" >> $GITHUB_STEP_SUMMARY + echo "- **Manifest Repo**: https://github.com/${{ env.MANIFEST_REPO }}" >> $GITHUB_STEP_SUMMARY + echo "- **Updated File**: ${{ env.MANIFEST_FILE_PATH }}" >> $GITHUB_STEP_SUMMARY + echo "- **ArgoCD will automatically sync the new image**" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### ⏱️ Build Info" >> $GITHUB_STEP_SUMMARY + echo "- **Build Time**: $(date)" >> $GITHUB_STEP_SUMMARY + echo "- **Triggered By**: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY + echo "- **Event**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### πŸͺ Store Service Features" >> $GITHUB_STEP_SUMMARY + echo "- **External API Integration**: 넀이버, 카카였, ꡬ글, ν•˜μ΄μ˜€λ”" >> $GITHUB_STEP_SUMMARY + echo "- **Architecture**: Hexagonal Architecture" >> $GITHUB_STEP_SUMMARY + echo "- **Port**: 8082" >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/store/Dockerfile b/store/Dockerfile new file mode 100644 index 0000000..1e91d88 --- /dev/null +++ b/store/Dockerfile @@ -0,0 +1,59 @@ +# Multi-stage build for store service +FROM gradle:8.13-jdk21 AS builder + +WORKDIR /app + +# Copy gradle files +COPY build.gradle settings.gradle gradlew ./ +COPY gradle/ ./gradle/ + +# Copy common module first (for better caching) +COPY common/ ./common/ + +# Copy store service source +COPY store/ ./store/ + +# Build the application +RUN ./gradlew store:build -x test --no-daemon + +# Runtime stage +FROM openjdk:21-jdk-slim + +# Create app user +RUN groupadd -r appgroup && useradd -r -g appgroup appuser + +# Install necessary packages for external API calls +RUN apt-get update && apt-get install -y \ + curl \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && update-ca-certificates + +# Create app directory +RUN mkdir -p /app && \ + chown -R appuser:appgroup /app + +WORKDIR /app + +# Copy jar file from builder stage +COPY --from=builder /app/store/build/libs/store-*.jar app.jar + +# Change ownership +RUN chown appuser:appgroup app.jar + +# Switch to non-root user +USER appuser + +# Expose port +EXPOSE 8082 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:8082/actuator/health || exit 1 + +# Environment variables +ENV JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:+UseStringDeduplication" +ENV SPRING_PROFILES_ACTIVE=docker + +# Run the application +ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"] \ No newline at end of file