Skip to content

Commit

Permalink
[Feat] Manager CD test
Browse files Browse the repository at this point in the history
  • Loading branch information
lcj1204 committed Apr 29, 2024
1 parent 0efcbaa commit b0e19b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 112 deletions.
32 changes: 10 additions & 22 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name: pothole CD

on:
# pull_request_target:
# types:
# - closed
# branches:
# - 'develop'
push:
branches: [ "develop" ]
pull_request_target:
types:
- closed
branches:
- 'develop'

jobs:
build:
Expand All @@ -20,8 +18,8 @@ jobs:
WORKER_APPLICATION_DEV_YML: ${{ secrets.WORKER_APPLICATION_DEV_YML }}

deploy_manager:
# if: github.event.pull_request.merged == true
# && (contains(github.head_ref, 'manager') || contains(github.head_ref, 'core'))
if: github.event.pull_request.merged == true
&& (contains(github.head_ref, 'manager') || contains(github.head_ref, 'core'))
needs: build
uses: ./.github/workflows/reusable-CD.yml
with:
Expand All @@ -32,15 +30,10 @@ jobs:
EC2_IP: ${{ secrets.EC2_IP }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
# CORE_APPLICATION_DEV_YML: ${{ secrets.CORE_APPLICATION_DEV_YML }}
# MANAGER_APPLICATION_YML: ${{ secrets.MANAGER_APPLICATION_YML }}
# MANAGER_APPLICATION_DEV_YML: ${{ secrets.MANAGER_APPLICATION_DEV_YML }}
# WORKER_APPLICATION_YML: ${{ secrets.WORKER_APPLICATION_YML }}
# WORKER_APPLICATION_DEV_YML: ${{ secrets.WORKER_APPLICATION_DEV_YML }}

deploy_worker:
# if: github.event.pull_request.merged == true
# && (contains(github.head_ref, 'worker') || contains(github.head_ref, 'core'))
if: github.event.pull_request.merged == true
&& (contains(github.head_ref, 'worker') || contains(github.head_ref, 'core'))
needs: build
uses: ./.github/workflows/reusable-CD.yml
with:
Expand All @@ -50,9 +43,4 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EC2_IP: ${{ secrets.EC2_IP }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
# CORE_APPLICATION_DEV_YML: ${{ secrets.CORE_APPLICATION_DEV_YML }}
# MANAGER_APPLICATION_YML: ${{ secrets.MANAGER_APPLICATION_YML }}
# MANAGER_APPLICATION_DEV_YML: ${{ secrets.MANAGER_APPLICATION_DEV_YML }}
# WORKER_APPLICATION_YML: ${{ secrets.WORKER_APPLICATION_YML }}
# WORKER_APPLICATION_DEV_YML: ${{ secrets.WORKER_APPLICATION_DEV_YML }}
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
9 changes: 3 additions & 6 deletions .github/workflows/build-CD.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: pothole build CD
name: pothole all build for CD

on:
workflow_call:
Expand All @@ -14,12 +14,9 @@ on:
WORKER_APPLICATION_DEV_YML:
required: true

permissions:
contents: read

jobs:
deploy:
name: ${{ inputs.module }} deploy
build:
name: pothole all build for CD
runs-on: ubuntu-22.04

steps:
Expand Down
88 changes: 4 additions & 84 deletions .github/workflows/reusable-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ on:
required: true
EC2_SSH_KEY:
required: true
# CORE_APPLICATION_DEV_YML:
# required: true
# MANAGER_APPLICATION_YML:
# required: true
# MANAGER_APPLICATION_DEV_YML:
# required: true
# WORKER_APPLICATION_YML:
# required: true
# WORKER_APPLICATION_DEV_YML:
# required: true


permissions:
contents: read
Expand All @@ -49,7 +40,7 @@ jobs:
- name: GitHub Repository Checkout
uses: actions/checkout@v3

- name: Core jar 파일 다운
- name: core jar 파일 다운
uses: actions/download-artifact@v4
with:
name: pothole-core-artifact
Expand All @@ -61,69 +52,6 @@ jobs:
name: pothole-${{ inputs.module }}-artifact
path: ./pothole-${{ inputs.module }}-api/build/libs/

- name: ${{ inputs.module }} 빌드 디렉토리 출력
run: |
cd ./pothole-${{ inputs.module }}-api/build/libs/
ls -l
- name: 현재 디렉토리 출력
run: |
echo ${{ github.workspace }}
ls -l
# - name: Set up JDK 17
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@v3
#
# - name: core application.yml 생성
# shell: bash
# run: |
# mkdir -p ./pothole-core/src/main/resources
# cd ./pothole-core/src/main/resources
#
# touch ./application-core-dev.yml
# echo "${{ secrets.CORE_APPLICATION_DEV_YML }}" > ./application-core-dev.yml
#
# - name: Manager application.yml 생성
# shell: bash
# run: |
# mkdir -p ./pothole-manager-api/src/main/resources
# cd ./pothole-manager-api/src/main/resources
#
# touch ./application.yml
# echo "${{ secrets.MANAGER_APPLICATION_YML }}" > ./application.yml
#
# touch ./application-aws.yml
# echo "${{ secrets.MANAGER_APPLICATION_DEV_YML }}" > ./application-manager-dev.yml
#
# - name: Worker application.yml 생성
# shell: bash
# run: |
# mkdir -p ./pothole-worker-api/src/main/resources
# cd ./pothole-worker-api/src/main/resources
#
# touch ./application.yml
# echo "${{ secrets.WORKER_APPLICATION_YML }}" > ./application.yml
#
# touch ./application-aws.yml
# echo "${{ secrets.WORKER_APPLICATION_DEV_YML }}" > ./application-worker-dev.yml

# - name: pothole all build
# run: |
# ./gradlew clean pothole-core:bootJar -x test
# ./gradlew pothole-manager-api:bootJar -x test
# ./gradlew pothole-worker-api:bootJar -x test

- name: 현재 디렉토리 출력
run: |
echo ${{ github.workspace }}
ls -l
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
Expand All @@ -138,19 +66,12 @@ jobs:
- name: Build, tag, and push the image ${{ inputs.module }} to Amazon ECR
run: |
cd ./${{ env.MODULE_PACKAGE }}
pwd
ls -l
# Build a Docker container and push it to ECR
docker build -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} .
echo "Pushing image to ECR..."
docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: 현재 디렉토리 출력
run: |
echo ${{ github.workspace }}
ls -l
- name: docker-compose.yml 파일 전송
uses: appleboy/scp-action@master
with:
Expand All @@ -169,7 +90,7 @@ jobs:
script: |
docker-compose stop ${{ env.IMAGE_NAME }}
docker-compose rm -f ${{ env.IMAGE_NAME }}
docker image prune -f
docker image prune -f -a
- name: pull image from ECR
uses: appleboy/ssh-action@master
Expand All @@ -182,7 +103,6 @@ jobs:
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
docker image tag ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }} ${{ env.IMAGE_NAME }}
# docker rmi ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: docker compose up [${{ inputs.module }}] on EC2
uses: appleboy/ssh-action@master
Expand All @@ -192,4 +112,4 @@ jobs:
key: ${{ secrets.EC2_SSH_KEY }}
script: |
docker-compose up -d ${{ env.DOCKER_COMPOSE_SERVICES_NAME }}
docker image prune -f
docker image prune -f -a

0 comments on commit b0e19b4

Please sign in to comment.