diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 2de1f06..62029af 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -37,17 +37,25 @@ jobs: java-version: '17' distribution: 'temurin' + + - name: Set Spring Profile Based on Branch + id: set-profile + run: | + if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then + echo "SPRING_PROFILE=prod" >> $GITHUB_ENV + else + echo "SPRING_PROFILE=dev" >> $GITHUB_ENV + fi + - name: Verify Backend_Config files run: ls -al Backend_Config - - name: Build and Test with Gradle Wrapper - env: - SPRING_PROFILES_ACTIVE: test + - name: Build with Gradle Wrapper run: | - echo "▶ Running Gradle build and test..." - ./gradlew --no-daemon clean build test \ - -Dspring.profiles.active=test \ - -Dspring.config.location=classpath:/,file:./Backend_Config/application-test.properties + echo "▶ Running Gradle bootJar with $SPRING_PROFILE profile..." + ./gradlew --no-daemon clean bootJar \ + -Dspring.profiles.active=$SPRING_PROFILE \ + -Dspring.config.location=classpath:/,file:./Backend_Config/application-$SPRING_PROFILE.properties - name: Show test results summary if: success() @@ -61,7 +69,8 @@ jobs: - name: Find latest jar file id: find-jar - run: echo "LATEST_JAR=$(ls -t build/libs/*.jar | head -n 1)" >> $GITHUB_ENV + run: echo "LATEST_JAR=$(find build/libs -type f -name '*.jar' ! -name '*plain*' | head -n 1)" >> $GITHUB_ENV + - name: Upload jar file to Artifact uses: actions/upload-artifact@v4 @@ -69,7 +78,6 @@ jobs: name: jar_files path: ${{ env.LATEST_JAR }} - - name: Upload Dockerfile to Artifact uses: actions/upload-artifact@v4 with: diff --git a/Dockerfile b/Dockerfile index 3daf3fe..dffa0d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM openjdk:17-alpine -ARG JAR_FILE=build/libs/*.jar +ARG JAR_FILE=build/libs/*-SNAPSHOT.jar COPY ${JAR_FILE} app.jar -RUN ls -al /app.jar -ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"] diff --git a/build.gradle b/build.gradle index e94f690..2ebca90 100644 --- a/build.gradle +++ b/build.gradle @@ -59,4 +59,8 @@ task copyYml(type: Copy){ include '*.properties' into 'src/main/resources' } +} + +tasks.withType(Jar){ + enabled = false } \ No newline at end of file