-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mjlee-29/ci/1
ci/cd 파이프라인 구축
- Loading branch information
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: docker ci/cd | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
types: [closed] | ||
workflow_dispatch: # (2).수동 실행도 가능하도록 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest # (3).OS환경 | ||
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) | ||
|
||
|
||
steps: | ||
- name: Checkout current api gateway repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Checkout eureka server repository | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: Team-Shaka/Briefing-Eureka-Server | ||
path: eureka # Eureka 코드를 가져옴 | ||
ref : main | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 17 | ||
|
||
- name: Grant execute permission for Eureka's gradlew | ||
run: chmod +x eureka/gradlew | ||
shell: bash | ||
|
||
- name: Build Eureka with Gradle | ||
run: cd eureka && ./gradlew clean build | ||
shell: bash | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
shell: bash | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
shell: bash | ||
|
||
- 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: ap-northeast-2 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: latest | ||
IMAGE_TAG: latest | ||
run: | | ||
# Docker 이미지 빌드 | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
# 빌드한 이미지를 Amazon ECR로 푸시 | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
# 빌드된 이미지의 정보 출력 | ||
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | ||
- name: Get current time | ||
uses: 1466587594/get-current-time@v2 | ||
id: current-time | ||
with: | ||
format: YYYYMMDD_HH-mm-ss | ||
utcOffset: "+09:00" | ||
|
||
- name: Generate deployment package | ||
run: | | ||
mkdir -p deploy | ||
cp -r .ebextensions deploy/.ebextensions | ||
cp Dockerrun.aws.json deploy/Dockerrun.aws.json | ||
cp -r .platform deploy/.platform | ||
cd deploy && zip -r deploy.zip . | ||
- name: Beanstalk Deploy | ||
uses: einaregilsson/beanstalk-deploy@v14 | ||
with: | ||
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
application_name: gateway | ||
environment_name: Gateway-env | ||
version_label: github-action-${{ steps.current-time.outputs.formattedTime }} | ||
region: ap-northeast-2 | ||
deployment_package: deploy/deploy.zip | ||
wait_for_deployment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
FROM eclipse-temurin:17-jdk | ||
|
||
# 현재 리포지토리, api gateway의 코드를 바탕으로 JAR 생성 | ||
FROM eclipse-temurin:17-jdk as builder1 | ||
ARG JAR_FILE1=build/libs/*.jar | ||
COPY ${JAR_FILE1} app1.jar | ||
|
||
# eureka의 리포지토리, eureka server의 코드를 바탕으로 JAR 생성 | ||
FROM eclipse-temurin:17-jdk as builder2 | ||
ARG JAR_FILE2=eureka/build/libs/*.jar | ||
COPY ${JAR_FILE2} app2.jar | ||
|
||
# 최종 이미지 생성 | ||
FROM eclipse-temurin:17-jdk | ||
COPY --from=builder1 app1.jar app1.jar | ||
COPY --from=builder2 app2.jar app2.jar | ||
|
||
# 두 애플리케이션 모두 실행하는 스크립트 추가 | ||
COPY start.sh start.sh | ||
RUN chmod +x start.sh | ||
|
||
EXPOSE 8080 8761 | ||
|
||
ENTRYPOINT ["./start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"AWSEBDockerrunVersion": "1", | ||
"Image": { | ||
"Name": "190986346464.dkr.ecr.ap-northeast-2.amazonaws.com/latest:latest", | ||
"Update": "true" | ||
}, | ||
"Ports": [ | ||
{ | ||
"ContainerPort": "8080" | ||
}, | ||
{ | ||
"ContainerPort": "8761" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# 첫 번째 애플리케이션을 백그라운드에서 실행 | ||
java -jar -Dspring.profiles.active=dev app1.jar & | ||
|
||
# 두 번째 애플리케이션을 백그라운드에서 실행 | ||
java -jar -Dspring.profiles.active=dev app2.jar & | ||
|
||
# 모든 자식 프로세스가 종료될 때까지 대기 | ||
wait |