CI: store CI workflow 및 dockerfile 업로드

This commit is contained in:
UNGGU0704 2025-06-13 10:45:14 +09:00
parent b28cfc1e4f
commit 3c24e4cd47
2 changed files with 245 additions and 0 deletions

186
.github/workflows/store-ci.yml vendored Normal file
View File

@ -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

59
store/Dockerfile Normal file
View File

@ -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"]