diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 00000000..c761d11d --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,55 @@ +# CI/CD workflow +name: CI/CD + +on: + push: + branches: [ "dev" ] + pull_request: + branches: [ "dev" ] + +permissions: + contents: read + +jobs: + CI: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0 + + # TODO: 추후 테스트코드 작성 후 테스트 실패 시 CI 불가능하도록 수정 + - name: Build with Gradle + run: ./gradlew build -x test + + - name: Docker Login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build Docker Image + run: docker build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/orange . + + - name: Push Docker Image + run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/orange + + CD: + if: github.event.pull_request.merged == true && github.ref == 'refs/heads/dev' + runs-on: self-hosted + needs: CI + + steps: + - name: Remove Docker Container + run: sudo docker rm -f orange || true + + - name: Run Updated Docker Container + run: sudo docker run -t --env-file ./.env -d --name orange -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/orange diff --git a/.gitignore b/.gitignore index 334c155a..6b057539 100644 --- a/.gitignore +++ b/.gitignore @@ -37,5 +37,7 @@ out/ .vscode/ ### project +*.sh +*.yml *.yaml *.properties diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8e3e5f40 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Use OpenJDK 17 as the base image +FROM openjdk:17 + +# Specify the build argument for the JAR file +ARG JAR_FILE=build/libs/*.jar + +# Copy the JAR file into the container +COPY ${JAR_FILE} app.jar + +# Set the entry point to run the JAR file +ENTRYPOINT ["java", "-jar", "/app.jar"] diff --git a/build.gradle b/build.gradle index bec0f35a..f74bd3cb 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,15 @@ dependencies { implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0' annotationProcessor 'com.github.therapi:therapi-runtime-javadoc-scribe:0.13.0' implementation 'com.github.therapi:therapi-runtime-javadoc:0.13.0' + + // mysql + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + runtimeOnly 'com.mysql:mysql-connector-j' + + // redis + implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'org.springframework.data:spring-data-redis' } tasks.named('test') {