Skip to content

Commit

Permalink
[SVR-85] CI/CD 배포 파일 분리 (#103)
Browse files Browse the repository at this point in the history
* feat: ci-cd 배포 파일 분리

* feat: pr,push시에 영향받는 파일 내용 수정

* feat: ci-cd 변경 감지하는 파일 내용 수정

* feat: ci-cd redis 관련 속성 추가

* feat: ci-cd 파일 분리
  • Loading branch information
sam971114 authored Feb 16, 2025
1 parent 6b832dd commit d4d56b4
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 12 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/admin-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Admin-App CD

on:
push:
branches:
- main
- dev
paths-ignore:
- application/ticket-app-api/**
- application/queue-app-api/**

env:
DOCKER_REGISTRY_URL: ${{ secrets.ADMIN_DOCKER_REGISTRY_URL }}
DOCKER_IMAGE_NAME: admin-uket
DOCKER_CONTAINER_NAME: admin-uket

jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# Caching Gradle dependencies to speed up the build process
- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# Setting up JDK 21 for building the Java application
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'

# Ensuring the Gradle wrapper script is executable
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# Building the application with Gradle
- name: Build with Gradle
run: ./gradlew clean build -PmainClass=com.uket.AdminApiApplication

# Configuring AWS credentials for accessing AWS services
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_ADMIN }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ADMIN }}
aws-region: ap-northeast-2

# Logging in to Amazon ECR
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v1

# Building and pushing Docker image to ECR
- name: Docker build and push
run: |
cd ./application/admin-app-api
docker build --platform linux/amd64 -t ${{ env.DOCKER_IMAGE_NAME }} .
docker tag ${{ env.DOCKER_IMAGE_NAME }}:latest ${{ env.DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:latest
docker push ${{ env.DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:latest
echo "::set-output name=image::${{ env.DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:latest"
deploy:
needs: build-and-push-docker-image
runs-on: ubuntu-latest
steps:
# Deploying the Docker container via SSH
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST_ADMIN }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY_ADMIN }}
script: |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ env.DOCKER_REGISTRY_URL }}
docker-compose down
docker pull ${{ env.DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}
docker-compose up -d
# Cleaning up unused Docker images
docker image prune -f
21 changes: 13 additions & 8 deletions .github/workflows/ci-api.yml → .github/workflows/admin-ci.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: Java CI with Gradle
name: Admin-App CI

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
paths-ignore:
- application/ticket-app-api/**
- application/queue-app-api/**

env:
DOCKER_IMAGE_NAME: admin-uket

jobs:
build:
Expand Down Expand Up @@ -39,8 +41,11 @@ jobs:
java-version: '21'
distribution: 'temurin'

- name: Grant execute permisson for gradlew
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew clean build
- name: Build with Gradle (Without Deployment)
run: ./gradlew clean build -PmainClass=com.uket.AdminApiApplication -x test

- name: Run Tests
run: ./gradlew test -PmainClass=com.uket.AdminApiApplication
11 changes: 8 additions & 3 deletions .github/workflows/cicd-dev.yml → .github/workflows/ticket-cd.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
name: Java CI/CD with Gradle
name: Ticket-App CD

on:
push:
branches:
- main
- dev
paths-ignore:
- application/admin-app-api/**
- application/queue-app-api/**

env:
DOCKER_REGISTRY_URL: ${{ secrets.DOCKER_REGISTRY_URL }}
Expand All @@ -13,6 +17,7 @@ env:
jobs:
build-and-push-docker-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

Expand All @@ -27,7 +32,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
# Setting up JDK 17 for building the Java application
# Setting up JDK 21 for building the Java application
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
Expand All @@ -40,7 +45,7 @@ jobs:

# Building the application with Gradle
- name: Build with Gradle
run: ./gradlew build -x test
run: ./gradlew clean build -PmainClass=com.uket.TicketApiApplication

# Configuring AWS credentials for accessing AWS services
- name: Configure AWS credentials
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/ticket-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Ticket-App CI

on:
pull_request:
branches:
- main
- dev
paths-ignore:
- application/admin-app-api/**
- application/queue-app-api/**

env:
DOCKER_IMAGE_NAME: dev-uket

jobs:
build:
runs-on: ubuntu-latest

services:
redis:
image: redis
ports:
- 6379:6379

steps:
- uses: actions/checkout@v3

- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'

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

- name: Build with Gradle (Without Deployment)
run: ./gradlew clean build -PmainClass=com.uket.TicketApiApplication -x test

- name: Run Tests
run: ./gradlew test -PmainClass=com.uket.TicketApiApplication
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ subprojects {
}

bootJar {
mainClass = 'com.uket.TicketApiApplication'
mainClass = project.getProperty('mainClass')
}
}

0 comments on commit d4d56b4

Please sign in to comment.