Browse Source

update gha pipeline

Daniel Bohry 8 tháng trước cách đây
mục cha
commit
ad12141122
1 tập tin đã thay đổi với 44 bổ sung21 xóa
  1. 44 21
      .github/workflows/buildAndRelease.yml

+ 44 - 21
.github/workflows/buildAndRelease.yml

@@ -5,27 +5,50 @@ on:
     branches: [ main ]
 
 jobs:
-
-  build:
+  build-and-test:
+    name: Build and Test
     runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+      - name: Cache Gradle packages
+        uses: actions/cache@v2
+        with:
+          path: ~/.gradle/caches
+          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
+          restore-keys: ${{ runner.os }}-gradle-
+      - name: Set up JDK
+        uses: actions/setup-java@v3
+        with:
+          java-version: '21'
+          distribution: 'temurin'
+      - name: Build with Gradle
+        run: chmod +x ./gradlew && ./gradlew clean build test
 
+  dockerize:
+    name: Dockerize Application
+    needs: build-and-test
+    runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v3
-    - name: Set up JDK 21
-      uses: actions/setup-java@v3
-      with:
-        java-version: '21'
-        distribution: 'adopt'
-    - name: Build jar
-      run: chmod +x ./gradlew && ./gradlew clean build
-    - name: Run tests
-      run: ./gradlew test
-    - name: Build the Docker image
-      run: docker build -t dbohry/auth-service .
-    - name: Login to Docker Hub
-      uses: docker/login-action@v2
-      with:
-        username: ${{ secrets.DOCKERHUB_USERNAME }}
-        password: ${{ secrets.DOCKERHUB_TOKEN }}
-    - name: Push image
-      run: docker push dbohry/auth-service
+      - uses: actions/checkout@v3
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v1
+      - name: Cache Docker layers
+        uses: actions/cache@v2
+        with:
+          path: /tmp/.buildx-cache
+          key: ${{ runner.os }}-buildx-${{ github.sha }}
+          restore-keys: ${{ runner.os }}-buildx-
+      - name: Set up JDK
+        uses: actions/setup-java@v3
+        with:
+          java-version: '21'
+          distribution: 'temurin'
+      - name: Build the Docker image
+        run: ./gradlew build && docker build -t dbohry/auth-service .
+      - name: Login to Docker Hub
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
+          password: ${{ secrets.DOCKERHUB_TOKEN }}
+      - name: Push image
+        run: docker push dbohry/auth-service