diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 405b7c5..b5e497a 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -15,71 +15,74 @@ jobs: contents: read steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. - # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md - - name: Setup Gradle - uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 - - - name: Build with Gradle Wrapper - run: ./gradlew -x test bootJar - - - name: Set up Docker Build - uses: docker/setup-buildx-action@v1 - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - - - - name: Build and push Docker image - run: | - docker build -t ${{ secrets.DOCKER_USERNAME }}/gitbal-be:latest . - docker push ${{ secrets.DOCKER_USERNAME }}/gitbal-be:latest - - - name: Create .env file - run: | - echo "${{ secrets.ENV_FILE_CONTENTS }}" > .env - cat .env - - - name: Verify docker-compose.yml exists - run: | - ls -la docker-compose.yml - - - - name: Copy files to EC2 - uses: appleboy/scp-action@master - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USER }} - key: ${{ secrets.EC2_SSH_KEY }} - source: | - ./docker-compose.yml - ./.env - target: "/home/${{ secrets.EC2_USER }}/" - debug: true - - - name: Deploy to EC2 - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USER }} - key: ${{ secrets.EC2_SSH_KEY }} - script: | - echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin - - cd /home/${{ secrets.EC2_USER }} - - sudo bash ./gitbal-deploy.sh + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. + # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Build with Gradle Wrapper + run: ./gradlew -x test bootJar + + - name: Set up Docker Build + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + + + - name: Build and push Docker image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/gitbal-be:latest . + docker push ${{ secrets.DOCKER_USERNAME }}/gitbal-be:latest + + - name: Create .env file + run: | + echo "${{ secrets.ENV_FILE_CONTENTS }}" > .env + cat .env + + - name: Verify docker-compose.yml exists + run: | + ls -la docker-compose.yml + + - name: Compress files + run: | + tar -czvf deploy-files.tar.gz docker-compose.yml .env + ls -la deploy-files.tar.gz # Ensure the tar file is created + + - name: Copy files to EC2 + uses: appleboy/scp-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_KEY }} + source: deploy-files.tar.gz + target: "/home/${{ secrets.EC2_USER }}/" + debug: true + + + - name: Deploy to EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + + cd /home/${{ secrets.EC2_USER }} + + sudo bash ./gitbal-deploy.sh dependency-submission: @@ -88,14 +91,14 @@ jobs: contents: write steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. - # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md - - name: Generate and submit dependency graph - uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. + # See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 \ No newline at end of file