diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 41a0dfd..3814fe5 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,45 +1,56 @@ -name: rhkr8521 CI +name: rhkr8521 - CI on: push: branches: [ "develop" ] + pull_request: + branches: [ "develop" ] -jobs: - build: - runs-on: ubuntu-22.04 +permissions: + contents: read - steps: - - name: checkout +jobs: + # Spring Boot application build and Docker image push process + build-docker-image: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout uses: actions/checkout@v3 - + + # 1. Set up JDK 17 - name: Set up JDK 17 uses: actions/setup-java@v3 with: - distribution: 'corretto' java-version: '17' - - - name: create application.yml + distribution: 'corretto' + + # 2. Create application.yml file + - name: Create application.yml run: | - ## create application.yml mkdir -p ./ChargeControlBackend/src/main/resources - echo "${{ secrets.CI_APPLICATION }}" > ./ChargeControlBackend/src/main/resources/application.yml - - - name: build + echo "${{ secrets.APPLICATION_YML }}" > ./ChargeControlBackend/src/main/resources/application.yml + cat ./ChargeControlBackend/src/main/resources/application.yml + shell: bash + + # 3. Build Spring Boot application + - name: Build with Gradle run: | chmod +x ./ChargeControlBackend/gradlew - ./ChargeControlBackend/gradlew build --project-dir ./ChargeControlBackend -x test + ./ChargeControlBackend/gradlew clean bootJar --project-dir ./ChargeControlBackend shell: bash - - - name: docker image build - run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/chargecontrol_backend . - # Dockerfile과 빌드 컨텍스트가 모두 루트 디렉토리에 있도록 설정 - working-directory: ./ - - - name: docker login + + # 4. Build Docker image + - name: Docker image build + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/chargecontrol_backend ./ChargeControlBackend + + # 5. DockerHub login + - name: Docker login uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: docker Hub push + + # 6. Push Docker image to DockerHub + - name: Docker Hub push run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/chargecontrol_backend