-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set CI/CD on main, CI on release-dev (#14)
* feat: Test github workflow * fix: ddl_auto - create_drop - 이제 테스트가 데이터베이스에 영향을 주지 않습니다. * feat: Use h2 on build * fix: Use test profile on build * fix: h2 Dialect sync * revert: h2 use on test * fix: use .env & refactor actions - Just for test & dev - Need to be fixed before prod * fix: apply env on build workflow * fix: use seperate test mysql container for build * fix: Rename ssh key * fix: Need ~/app folder, add mkdir command * fix: continue on error - stop running appliation on EC2 * fix: Now deploy w/docker * fix: run -> script typo * fix: typo on keyname * fix: fixed typo * fix: fixed typo on keyname * fix: fix dockerfile dir * fix: typo on dockerfile name * fix: typo on docker script * fix: docker compose env injection * fix: typo and unused .env create * fix: rewrite invalid env injection command * fix: fixed pwd typo, add --no-deps on docker compose up * fix: pwd change * fix: pwd typo * fix: remove hardcoded docker-compose environment * fix: change exposed port * fix: env_file import * fix: typo * feat: set deploy on main, build on main & release-dev
- Loading branch information
Showing
4 changed files
with
112 additions
and
5 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,98 @@ | ||
name: Build & deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- release-dev | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: testdb | ||
MYSQL_USER: user | ||
MYSQL_PASSWORD: somepassword | ||
ports: | ||
- 3306:3306 | ||
options: >- | ||
--health-cmd="mysqladmin ping -h localhost" | ||
--health-interval=10s | ||
--health-timeout=5s | ||
--health-retries=3 | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
|
||
- name: Build with Gradle | ||
run: | | ||
chmod +x gradlew | ||
./gradlew build | ||
env: | ||
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/testdb | ||
SPRING_DATASOURCE_USERNAME: user | ||
SPRING_DATASOURCE_PASSWORD: somepassword | ||
SPRING_JPA_HIBERNATE_DDL_AUTO: create-drop | ||
SPRING_PROFILES_ACTIVE: "prod" | ||
|
||
# 배포는 main 브랜치에서만 실행 | ||
- name: Upload JAR to EC2 | ||
if: github.ref == 'refs/heads/main' | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USER }} | ||
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | ||
source: "build/libs/*-SNAPSHOT.jar" | ||
target: "~/app/" | ||
|
||
- name: Delete latest JAR file | ||
if: github.ref == 'refs/heads/main' | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USER }} | ||
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | ||
script: | | ||
cd ~/app | ||
LATEST_JAR=$(ls -t *.jar | head -n 1) || true | ||
echo "Latest JAR file: $LATEST_JAR" | ||
for file in *.jar; do | ||
if [[ "$file" != "$LATEST_JAR" ]]; then | ||
echo "Deleting $file..." | ||
rm -f "$file" | ||
fi | ||
done | ||
continue-on-error: true | ||
|
||
- name: Upload Dockerfile and Compose file | ||
if: github.ref == 'refs/heads/main' | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USER }} | ||
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | ||
source: "deploy-Dockerfile, docker-compose.yaml" | ||
target: "~" | ||
|
||
- name: Deploy via SSH | ||
if: github.ref == 'refs/heads/main' | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USER }} | ||
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | ||
script: | | ||
echo "Starting containers..." | ||
docker compose up -d --no-deps myapp |
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,7 @@ | ||
FROM openjdk:17 | ||
|
||
# 가장 최신의 JAR 파일 하나만 있음, app.jar로 복사 | ||
COPY app/build/libs/*.jar /app.jar | ||
|
||
EXPOSE 8080 | ||
ENTRYPOINT ["java", "-jar", "/app.jar"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ spring: | |
dialect: org.hibernate.dialect.MySQL8Dialect | ||
format_sql: false | ||
show_sql: false | ||
ddl_auto: create-drop |