Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cicd #107

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open

Cicd #107

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
71 changes: 71 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
# ci cd
name: ci-cd

on:
pull_request:
branches: [BE, dev]

env:
working-directory: ./be
APPLICATION_PROPERTIES_FILE_PATH: ./src/main/resources/application.properties
AWS_REGION: ap-northeast-2
S3_BUCKET_NAME: team2-kiosk
CODE_DEPLOY_APPLICATION_NAME: team2-kiosk
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: team2-kiosk

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./be

steps:

- name: Checkout Source Code
uses: actions/checkout@v3

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

- name: Make application.properties file
run: touch '${{ env.APPLICATION_PROPERTIES_FILE_PATH }}'

- name: Output application information
run: echo '${{ secrets.APPLICATION }}' > '${{ env.APPLICATION_PROPERTIES_FILE_PATH }}'

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

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


- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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: Upload to S3
run: aws s3 cp
--region '${{ env.AWS_REGION }}' ./$GITHUB_SHA.zip
s3://$S3_BUCKET_NAME/Build/$GITHUB_SHA.zip

- name: Code Deploy
run: aws deploy create-deployment
--application-name $CODE_DEPLOY_APPLICATION_NAME
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name $CODE_DEPLOY_DEPLOYMENT_GROUP_NAME
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=Build/$GITHUB_SHA.zip

19 changes: 19 additions & 0 deletions be/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 0.0 # CodeDeploy 버전
os: linux
files:
- source: / # CodeDeploy에 있는 파일 위치
destination: /home/ubuntu/app/ # EC2로 전달할 위치
overwrite: yes

permissions:
- object: /
pattern: "**"
owner: ubuntu
group: ubuntu
mode: 755

hooks:
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ubuntu
12 changes: 12 additions & 0 deletions be/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
KIOSK_ID=$(jps | grep be | awk '{ print $1 }')

if [ -z $KIOSK_ID ]; then
echo "동작중인 서버가 없습니다."
else
echo "$KIOSK_ID 프로세스를 삭제합니다."
kill -9 $KIOSK_ID
fi

echo "서버 시작"
nohup java -jar ~/app/build/libs/be-0.0.1-SNAPSHOT.jar >/home/ubuntu/app/log.txt 2>&1 &
echo "배포 성공"