Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CI/CD - Build, Test, and Deploy

on:
pull_request:
branches:
- main
- dev
push:
branches:
- main
- dev
workflow_dispatch:

permissions:
id-token: write
contents: read

env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: first-ticket/program-service
GITHUB_USER: ${{ secrets.GH_USER }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v6

- name: Grant execute permission to gradlew
run: chmod +x gradlew

- name: Build & Test
run: ./gradlew build --no-daemon

- name: Upload test report (on failure)
if: failure()
uses: actions/upload-artifact@v5
with:
name: test-report
path: build/reports/tests/
retention-days: 7

push-to-ecr:
needs: build-and-test
if: |
github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build, tag, and push image to ECR
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker buildx build --platform linux/amd64 \
--build-arg GITHUB_USER=${{ secrets.GH_USER }} \
--secret id=github_token,env=GITHUB_TOKEN \
-t $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
-t $REGISTRY/$ECR_REPOSITORY:latest \
--push \
.

- name: Show pushed image
run: |
echo "✅ Pushed: $ECR_REPOSITORY:${{ github.sha }}"
echo "✅ Pushed: $ECR_REPOSITORY:latest"

- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition program-service \
--query taskDefinition > task-definition.json

- name: Deploy to ECS
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: task-definition.json
service: program-service
cluster: first-ticket-cluster
wait-for-service-stability: false
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WORKDIR /app
COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle ./
RUN chmod +x gradlew

# 2. 의존성 미리 다운로드
ARG GITHUB_USER
Expand Down Expand Up @@ -44,7 +45,7 @@ COPY --from=builder --chown=spring:spring /app/application/ ./
# [중요] 7. 런타임 환경에 .env 파일 주입
# docker-compose에서 env_file을 사용하더라도,
# 애플리케이션 내부에서 직접 파일을 읽는 설정을 위해 복사해두는 것이 안전합니다.
COPY --chown=spring:spring .env .env
#COPY --chown=spring:spring .env .env

USER spring

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ spring:
discovery:
enabled: true
service-id: config-server
inetutils:
preferred-networks:
- 10\.
- 172\.
- 192\.168\.

profiles:
active: local # 기본 로컬 실행
Expand Down

This file was deleted.