Merge pull request #53 from StudyLink-SW-Project/fix/#52 #103
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Java CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| # build-and-test: 코드 빌드 | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Set executable permission for gradlew | |
| run: chmod +x ./gradlew | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| # - name: Run Tests | |
| # run: ./gradlew test | |
| - name: Build with Gradle | |
| run: ./gradlew clean build -x test # test skip | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-build | |
| path: build/libs/*.jar | |
| retention-days: 3 | |
| build-and-push-image: | |
| # Docker 이미지 생성 및 DockerHub 배포 | |
| needs: build-and-test | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: app-build | |
| path: build/libs | |
| - name: Generate Image Tag | |
| id: tag | |
| run: | | |
| echo "TAG=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
| echo "Generated tag: ${{ env.TAG }}" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Cache Docker layers | |
| uses: actions/cache@v3 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: DockerHub Login | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| lehojun/studylink:latest | |
| lehojun/studylink:${{ env.TAG }} | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new | |
| # Temp fix for cache (https://github.com/docker/build-push-action/issues/252) | |
| - name: Move cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| - name: Image Build Complete | |
| run: | | |
| echo "Image lehojun/studylink:${{ env.TAG }} successfully built and pushed to DockerHub" | |
| echo "This image can now be used in the OpenVidu docker-compose.override.yaml file" |