-
Notifications
You must be signed in to change notification settings - Fork 0
CI/CD 파이프라인 구성 추가 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
175eb5e
ba78090
cd817cc
d280c4d
a145a9f
9a8bd2f
63b7323
8d58f71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| name: CD | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| env: | ||
| REGISTRY: ghcr.io | ||
| IMAGE_NAME: ${{ github.repository }} | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| name: Build & Push Docker Image | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| outputs: | ||
| image-tag: ${{ steps.meta.outputs.tags }} | ||
| image-digest: ${{ steps.push.outputs.digest }} | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract Docker metadata | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=sha,prefix=,format=short | ||
| type=raw,value=latest | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Build and push | ||
| id: push | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| deploy: | ||
| name: Deploy to Server | ||
| runs-on: ubuntu-latest | ||
| needs: build-and-push | ||
| environment: production | ||
|
|
||
| steps: | ||
| - name: Deploy via SSH | ||
| uses: appleboy/ssh-action@v1 | ||
| with: | ||
| host: ${{ secrets.DEPLOY_HOST }} | ||
| username: ${{ secrets.DEPLOY_USER }} | ||
| key: ${{ secrets.DEPLOY_SSH_KEY }} | ||
| envs: ENVFILE,GITHUB_TOKEN,ACTOR | ||
| script: | | ||
| IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" | ||
|
|
||
| echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin | ||
|
|
||
| echo "$ENVFILE" > /home/${{ secrets.DEPLOY_USER }}/.aikon.env | ||
| chmod 600 /home/${{ secrets.DEPLOY_USER }}/.aikon.env | ||
|
|
||
| docker pull $IMAGE | ||
|
|
||
| docker stop aikon-app || true | ||
| docker rm aikon-app || true | ||
|
|
||
| docker run -d \ | ||
| --name aikon-app \ | ||
| --restart unless-stopped \ | ||
| -p 8080:8080 \ | ||
| --env-file /home/${{ secrets.DEPLOY_USER }}/.aikon.env \ | ||
| $IMAGE | ||
|
|
||
| docker image prune -f | ||
| env: | ||
| ENVFILE: ${{ secrets.ENVFILE }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| ACTOR: ${{ github.actor }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # ---- Build Stage ---- | ||
| FROM gradle:9.4.1-jdk21 AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY gradlew . | ||
| COPY gradle gradle | ||
| COPY build.gradle.kts . | ||
| COPY settings.gradle.kts . | ||
|
|
||
| # 의존성만 먼저 캐싱 | ||
| RUN ./gradlew dependencies --no-daemon --parallel -q || true | ||
|
|
||
| COPY src src | ||
|
|
||
| RUN ./gradlew bootJar --no-daemon --parallel -x test | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spring Boot 2.5 버전 이상부터는 기본적으로 일반 jar( |
||
|
|
||
| # ---- Runtime Stage ---- | ||
| FROM eclipse-temurin:21-jre-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN addgroup -S aikon && adduser -S aikon -G aikon | ||
|
|
||
| COPY --from=builder /app/build/libs/*.jar app.jar | ||
|
|
||
| RUN chown aikon:aikon app.jar | ||
|
Comment on lines
+25
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| USER aikon | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| ENTRYPOINT ["java", "-jar", "app.jar"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gradlew파일이 복사될 때 실행 권한(+x)이 유실될 수 있습니다. 특히 Windows 환경에서 git 설정(core.filemode)에 따라 권한이 유지되지 않은 채 커밋된 경우, 빌드 단계에서Permission denied에러가 발생하며 빌드가 실패할 수 있습니다.\n\n안전한 빌드를 위해gradlew복사 후 실행 권한을 명시적으로 부여하는 것을 권장합니다.