Merge pull request #19 from GraduationProject-SayUp/refactor #38
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: Docker Image CI/CD | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| env: | |
| FILE_UPLOAD_DIR: ./tmp/file/userVoice | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 with Gradle cache | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'gradle' | |
| - name: Grant execute permission to gradlew | |
| run: chmod +x ./gradlew | |
| - name: Create upload directory | |
| run: mkdir -p ${{ env.FILE_UPLOAD_DIR }} | |
| - name: Build with Gradle (skip tests) | |
| run: ./gradlew build -x test | |
| env: | |
| FILE_UPLOAD_DIR: ${{ env.FILE_UPLOAD_DIR }} | |
| API_KEY: ${{ secrets.ChatGptAPI }} | |
| - name: Docker Hub Login | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Extract Gradle Version | |
| id: get_version | |
| run: | | |
| echo "VERSION=$(./gradlew properties -q | grep '^version:' | cut -d ' ' -f2)" >> $GITHUB_ENV | |
| - name: Build & Push Docker Image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sayup:latest | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sayup:${{ github.sha }} | |
| ${{ secrets.DOCKERHUB_USERNAME }}/sayup:${{ env.VERSION }} | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/sayup:buildcache | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/sayup:buildcache,mode=max |