-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
w6 Weekly2develop
- Loading branch information
Showing
38 changed files
with
862 additions
and
187 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,148 @@ | ||
name: CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: [ week6 ] | ||
pull_request: | ||
branches: [ week6 ] | ||
|
||
env: | ||
LIGHTSAIL_USERNAME: ubuntu | ||
AWS_REGION: ap-northeast-2 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
# 브런치로 체크아웃 | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
# jdk 설치 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21' | ||
|
||
# application-oauth.yml 생성 | ||
- name: Create application.yml | ||
run: | | ||
mkdir -p src/main/resources | ||
cat <<EOF > src/main/resources/application-oauth.yml | ||
spring: | ||
datasource: | ||
url: ${{ | ||
secrets.SPRING_DATASOURCE_URL | ||
}} | ||
username: ${{ | ||
secrets.SPRING_DATASOURCE_USERNAME | ||
}} | ||
password: ${{ | ||
secrets.SPRING_DATASOURCE_PASSWORD | ||
}} | ||
security: | ||
oauth2: | ||
client: | ||
registration: | ||
google: | ||
client-id: ${{ | ||
secrets.GOOGLE_CLIENT_ID | ||
}} | ||
client-secret: ${{ | ||
secrets.GOOGLE_CLIENT_SECRET | ||
}} | ||
redirect-uri: "https://${{ | ||
secrets.LIGHT_SAIL_IP | ||
}}/login/oauth2/code/google" | ||
scope: | ||
- profile | ||
provider: | ||
google: | ||
authorization-uri: https://accounts.google.com/o/oauth2/auth | ||
token-uri: https://oauth2.googleapis.com/token | ||
user-info-uri: https://www.googleapis.com/oauth2/v3/userinfo | ||
server: | ||
port: 443 | ||
ssl: | ||
enabled: true | ||
key-store: /etc/letsencrypt/live/seamlessup.com/keystore.p12 | ||
key-store-password: ${{ | ||
secrets.KEYSTORE_PASSWORD | ||
}} | ||
key-store-type: PKCS12 | ||
key-alias: tomcat | ||
EOF | ||
# Gradle 캐시 설정 | ||
- name: Cache Gradle packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
# gradlew 실행 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
# gradle로 빌드 | ||
- name: Build with Gradle | ||
run: ./gradlew bootJar | ||
|
||
# AWS 인증 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-region: ${{ env.AWS_REGION }} | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
|
||
# AWS 인증 테스트 | ||
- name: Verify AWS Credentials | ||
run: aws configure list | ||
|
||
# 배포 자동화 | ||
- name: Upload files to Lightsail | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.LIGHTSAIL_HOST }} | ||
username: ${{ env.LIGHTSAIL_USERNAME }} | ||
port: 22 | ||
key: ${{ secrets.LIGHTSAIL_SSH_KEY }} | ||
source: 'build/libs/*.jar' | ||
target: '/home/ubuntu/seamless/dist' | ||
use_insecure_cipher: true | ||
|
||
- name: Restart Spring Boot process | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.LIGHTSAIL_HOST }} | ||
username: ${{env.LIGHTSAIL_USERNAME}} | ||
key: ${{ secrets.LIGHTSAIL_SSH_KEY }} | ||
script: | | ||
BUILD_PATH=$(ls /home/ubuntu/seamless/dist/build/libs/*.jar) | ||
JAR_NAME=$(basename $BUILD_PATH) | ||
CURRENT_PID=$(pgrep -f $JAR_NAME) | ||
if [ -z $CURRENT_PID ] | ||
then | ||
sleep 1 | ||
else | ||
kill -15 $CURRENT_PID | ||
sleep 5 | ||
fi | ||
DEPLOY_PATH=/home/ubuntu/seamless/deploy/ | ||
mkdir $DEPLOY_PATH | ||
cp $BUILD_PATH $DEPLOY_PATH | ||
cd $DEPLOY_PATH | ||
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME | ||
nohup java -jar $DEPLOY_JAR > /dev/null 2> /dev/null < /dev/null & |
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
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
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
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
Oops, something went wrong.