diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml index 123a5e9..6656a20 100644 --- a/.github/workflows/dev_deploy.yml +++ b/.github/workflows/dev_deploy.yml @@ -1,12 +1,91 @@ -## github repository actions 페이지에 나타날 이름 -#name: EatPic CI/CD (using github actions & docker) -# -#on: -# pull_request: -# types: [closed] -# workflow_dispatch: # (2).수동 실행도 가능하도록 -# -#jobs: -# build: -# runs-on: ubuntu-latest # (3).OS환경 -# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' \ No newline at end of file +# github repository actions 페이지에 나타날 이름 +name: EatPic CI/CD (using github actions & docker) + +on: + push: + branches: [ "develop", "main" ] + pull_request: + branches: [ "develop", "main" ] + +permissions: + contents: read + +jobs: + CI-CD: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + + ## jdk setting + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + + ## gradle caching + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + ## create application.yml + - name: make application.yml + if: contains(github.ref, 'main') + run: | + mkdir -p ./src/main/resources + cd ./src/main/resources + touch application.yml + echo "${{ secrets.YML_DEV }}" > application.yml + shell: bash + + - name: Grant Execute Permission For Gradlew + run: chmod +x gradlew + + ## docker build & push + - name: docker build + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_USERNAME }}/eatpic . + docker push ${{ secrets.DOCKER_USERNAME }}/eatpic:latest + + ## docker deploy + - name: Deploy to dev + uses: appleboy/ssh-action@master + id: deploy-dev + # if: contains(github.ref, 'develop') + if : contains(github.ref,'main') + with: + key: ${{ secrets.PRIVATE_KEY }} + host: ${{ secrets.HOST_DEV }} + username: ${{ secrets.USERNAME }} + port: 22 + script: | + docker rm -f $(docker ps -qa) + docker pull ${{ secrets.DOCKER_USERNAME }}/eatpic + docker-compose up -d + docker image prune -f + + ## time + current-time: + needs: CI-CD + runs-on: ubuntu-latest + steps: + - name: Get Current Time + uses: 1466587594/get-current-time@v2 + id: current-time + with: + format: YYYY-MM-DDTHH:mm:ss + utcOffset: "+09:00" + - name: Print Current Time + run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}" + shell: bash \ No newline at end of file diff --git a/.gitignore b/.gitignore index c2065bc..f1d98ea 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ out/ ### VS Code ### .vscode/ + +*/application.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..04895f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# 빌드 단계 +FROM openjdk:17-jdk-slim as build +WORKDIR /app +COPY . . +RUN ./gradlew clean build +FROM openjdk:17-jdk-slim +WORKDIR /app + +# 타임존 설정 +ENV TZ=Asia/Seoul +RUN apt-get update && apt-get install -y tzdata && \ + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \ + apt-get clean + +COPY --from=build /app/build/libs/*.jar app.jar +EXPOSE 8080 + +# JVM 타임존 설정 추가 +ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul", "-jar", "app.jar"] \ No newline at end of file diff --git a/src/main/java/EatPic/spring/domain/card/entity/Card.java b/src/main/java/EatPic/spring/domain/card/entity/Card.java index 622743a..62c9f35 100644 --- a/src/main/java/EatPic/spring/domain/card/entity/Card.java +++ b/src/main/java/EatPic/spring/domain/card/entity/Card.java @@ -65,6 +65,7 @@ public class Card extends BaseEntity { private List cardHashtags = new ArrayList<>(); // 삭제 여부 (Soft Delete 용도) + @Builder.Default @Column(name = "is_deleted", nullable = false) private boolean isDeleted = false; diff --git a/src/main/resources/application-jwt.yml b/src/main/resources/application-jwt.yml deleted file mode 100644 index 50f3d1f..0000000 --- a/src/main/resources/application-jwt.yml +++ /dev/null @@ -1,4 +0,0 @@ -spring: - jwt: - secret: ${JWT_SECRET_KEY} - access-token-validity: ${JWT_ACCESS_TOKEN_TIME} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 0c7c661..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=spring diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3061d63..e590c05 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,26 +1,29 @@ spring: application: - name: backend + name: spring jpa: show-sql: false generate-ddl: true properties: hibernate: hbm2ddl: - auto: update + auto: update # 계속 update 유지 format_sql: false use_sql_comments: true default_batch_fetch_size: 1000 dialect: org.hibernate.dialect.MySQLDialect database: mysql datasource: - url: jdbc:mysql://localhost:3306/eatpic_db - username: ${DB_USERNAME} - password: ${DB_PASSWORD} + url: jdbc:mysql://eatpic-database.cxg2668gsj4t.ap-northeast-2.rds.amazonaws.com:3306/eatpic_db?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: eatpic + password: eatpic123*** driver-class-name: com.mysql.cj.jdbc.Driver + jwt: + secret: EatPic2025@JWTToken!SecureKey + access-token-validity: 3600000 profiles: include: - database - swagger - jwt - - s3 \ No newline at end of file + - s3 diff --git a/src/test/java/EatPic/spring/ApplicationTests.java b/src/test/java/EatPic/spring/ApplicationTests.java index baa5824..96865db 100644 --- a/src/test/java/EatPic/spring/ApplicationTests.java +++ b/src/test/java/EatPic/spring/ApplicationTests.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest class ApplicationTests {