Skip to content

Commit

Permalink
Merge pull request #110 from Kumoh-talk/main
Browse files Browse the repository at this point in the history
테스트서버 cicd 파이프라인 적용
  • Loading branch information
siwan9 authored Nov 20, 2024
2 parents 9d20800 + c2ea754 commit 02ad8b1
Show file tree
Hide file tree
Showing 339 changed files with 14,071 additions and 2,673 deletions.
92 changes: 0 additions & 92 deletions .github/workflows/ci-gradle-build.yml

This file was deleted.

101 changes: 101 additions & 0 deletions .github/workflows/cicd-gradle-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Java CI with Gradle and Deploy to Amazon ECS

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: checkout action with submodule
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true

- name: Set up JDK 17 action
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle action
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: add +x permission to gradlew
run: chmod +x gradlew

- name: Build with Gradle Wrapper
run: ./gradlew clean build

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build-libs
path: build/libs/*.jar

deploy:
needs: build
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout action
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

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

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-libs
path: build/libs

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG .
docker push $ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG
echo "image=$ECR_REGISTRY/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ secrets.ECS_TASK_DEFINITION }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ secrets.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
environment: |
USE_PROFILE=prod
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ secrets.ECS_SERVICE }}
cluster: ${{ secrets.ECS_CLUSTER }}
wait-for-service-stability: true
93 changes: 93 additions & 0 deletions .github/workflows/develop-cicd-gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Java CI with Gradle and Deploy to develop EC2

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

env:
IMAGE_TAG: ${{ github.sha }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: checkout action with submodule
uses: actions/checkout@v4
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true

- name: Set up JDK 17 action
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle action
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: add +x permission to gradlew
run: chmod +x gradlew

- name: Build with Gradle Wrapper
run: ./gradlew clean build

- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: build-libs
path: build/libs/*.jar

deploy:
needs: build
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout action
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-libs
path: build/libs

- name: Build image and Generate tar
id: build-image
run: |
docker build -t kumoh_talk:$IMAGE_TAG .
docker save kumoh_talk:$IMAGE_TAG -o kumoh_talk:$IMAGE_TAG.tar
- name: Upload to S3
run: |
aws s3 cp kumoh_talk:$IMAGE_TAG.tar s3://${{ secrets.S3_BUCKET_NAME }}/kumoh_talk:$IMAGE_TAG.tar
- name: SSH Connect
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_HOST }}
username: ubuntu
key: ${{ secrets.DEV_EC2_PRIVATE_KEY }}
script: |
sudo docker stop spring-boot-app || true
sudo docker rm spring-boot-app || true
aws s3 cp s3://${{ secrets.S3_BUCKET_NAME }}/kumoh_talk:$IMAGE_TAG.tar kumoh_talk:$IMAGE_TAG.tar
sudo docker load -i kumoh_talk:$IMAGE_TAG.tar
sudo docker run -d --log-driver=syslog -e USE_PROFILE=dev -p 8080:8080 kumoh_talk:$IMAGE_TAG
sudo docker image prune -a -f
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ out/
.vscode/

# 속성 제외
**/application.properties
**/application.properties
.env
data
.DS_Store
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/main/resources/security"]
path = src/main/resources/security
url = https://github.com/Kumoh-talk/kumoh-talk-backend-security.git
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17-jdk-slim
ARG JAR_FILE_PATH=build/libs/*.jar
COPY ${JAR_FILE_PATH} app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=${USE_PROFILE}", "-jar", "app.jar"]
Loading

0 comments on commit 02ad8b1

Please sign in to comment.