diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d84a097 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + branches: [ "dev" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.1.7 + + - name: Set up JDK 21 + uses: actions/setup-java@v4.2.2 + with: + distribution: 'temurin' + java-version: '21' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew clean build diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..6a5d8b1 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,47 @@ +name: CI/CD + +on: + push: + branches: [ "dev" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.1.7 + + - name: Log in to Docker Hub + uses: docker/login-action@v3.3.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and Push Docker image + if: github.ref == 'refs/heads/dev' + uses: docker/build-push-action@v6.7.0 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROD_IMAGE_NAME }}:latest + platforms: linux/amd64 + + deploy: + runs-on: ubuntu-latest + needs: build + + steps: + - name: SSH to Server and Deploy + if: github.ref == 'refs/heads/dev' + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.PROD_SERVER_HOST }} + port: ${{ secrets.PROD_SERVER_PORT }} + username: ${{ secrets.PROD_SERVER_USERNAME }} + key: ${{ secrets.PROD_SERVER_KEY }} + script: | + cd /home/ubuntu/dasom + mkdir -p ./env + echo "${{ secrets.ENV }}" > ./env/prodEnv + ./deploy.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95d0f50 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM gradle:8.12.1-jdk21-alpine AS build +WORKDIR /home/gradle/project + +COPY build.gradle settings.gradle ./ +COPY gradle gradle/ + +COPY src src + +RUN gradle clean build + +FROM eclipse-temurin:21-jre-alpine +WORKDIR /app + +COPY --from=build /home/gradle/project/build/libs/dmu-dasom-api.jar api.jar + +ENTRYPOINT ["java", "-Dspring.profiles.active=default,credentials", "-jar", "api.jar"] diff --git a/build.gradle b/build.gradle index 72bb68c..a1b9038 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,7 @@ dependencies { developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.oracle.database.jdbc:ojdbc11' annotationProcessor 'org.projectlombok:lombok' + testImplementation 'com.h2database:h2' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' diff --git a/src/main/resources/application-credentials.yml b/src/main/resources/application-credentials.yml new file mode 100644 index 0000000..4eb2020 --- /dev/null +++ b/src/main/resources/application-credentials.yml @@ -0,0 +1,13 @@ +spring: + datasource: + url: ${DB_URL} + driver-class-name: oracle.jdbc.OracleDriver + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + jpa: + hibernate: + ddl-auto: ${DDL_AUTO} + show-sql: ${SHOW_SQL} + properties: + hibernate: + dialect: org.hibernate.dialect.OracleDialect diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d11613d..9c92956 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,12 +3,3 @@ server: spring: application: name: dasom-api - datasource: - url: ${DB_URL} - driver-class-name: oracle.jdbc.OracleDriver - username: ${DB_USERNAME} - password: ${DB_PASSWORD} - jpa: - hibernate: - ddl-auto: update - show-sql: true