diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index e1b39c4..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Deploy to AKS Cluster - -on: - workflow_run: - workflows: ["Java CI with Maven"] - types: - - completed - -jobs: - deploy: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} - steps: - - uses: actions/checkout@v3 - - - uses: Azure/aks-set-context@v1 - with: - creds: '${{ secrets.AZURE_CREDENTIALS }}' - cluster-name: pixelCluster - resource-group: gr-pixel-containers - - - uses: Azure/k8s-deploy@v1 - with: - manifests: | - k8s/deployment.yaml - k8s/service.yaml - images: | - springapppixel.azurecr.io/backend:${{ github.sha }} - imagepullsecrets: | - k8s-secret - namespace: ingress-basic diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6b3e7a4..88d5803 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,28 +56,48 @@ jobs: if: github.ref == 'refs/heads/main' run: mvn clean install - docker: + build-and-push-acr: + name: Build and Push to Azure Container Registry runs-on: ubuntu-latest + if: github.event_name == 'pull_request' && github.base_ref == 'main' steps: - - uses: actions/checkout@v3 - - - name: Set up Docker for Azure - uses: Azure/docker-login@v1 - with: - login-server: springapppixel.azurecr.io - username: ${{ secrets.ACR_USERNAME }} - password: ${{ secrets.ACR_PASSWORD }} - - - name: Build Docker Image and Push to Azure - if: github.ref == 'refs/heads/main' - run: | - docker build . -t springapppixel.azurecr.io/backend:${{ github.sha }} - docker push springapppixel.azurecr.io/backend:${{ github.sha }} + - uses: actions/checkout@master + + - uses: Azure/docker-login@v1 + with: + login-server: springapppixel.azurecr.io + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - run: | + docker build . -t springapppixel.azurecr.io/backend:${{ github.sha }} + docker push springapppixel.azurecr.io/backend:${{ github.sha }} + + # Set the target AKS cluster. + - uses: Azure/aks-set-context@v1 + with: + creds: '${{ secrets.AZURE_CREDENTIALS }}' + cluster-name: pixelCluster + resource-group: gr-pixel-containers + + - name: Update deployment image + run: | + sed -i 's||springapppixel.azurecr.io/backend:${{ github.sha }}|' k8s/deployment.yaml + - uses: Azure/k8s-deploy@v1 + with: + manifests: | + k8s/deployment.yaml + k8s/service.yaml + images: | + springapppixel.azurecr.io/backend:${{ github.sha }} + imagepullsecrets: | + k8s-secret + namespace: ingress-basic notifyTelegramSuccess: runs-on: ubuntu-latest - needs: [build, test, docker] + needs: [build, test, build-and-push-acr] if: success() steps: - name: Send Telegram Notification (Success) @@ -93,7 +113,7 @@ jobs: notifyTelegramFailure: runs-on: ubuntu-latest - needs: [build, test, docker] + needs: [build, test, build-and-push-acr] if: failure() steps: - name: Send Telegram Notification (Failure) diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index a50f4c2..de8b589 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -4,7 +4,7 @@ metadata: name: api namespace: ingress-basic spec: - replicas: 2 + replicas: 1 selector: matchLabels: app: api diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f3572c1..df7e966 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,12 +1,11 @@ spring.application.name=pixel -spring.datasource.url=jdbc:postgresql://localhost:5432/dash -spring.datasource.username=admin -spring.datasource.password=admin +spring.datasource.url=jdbc:postgresql://bd-pixel.postgres.database.azure.com:5432/postgres +spring.datasource.username=pixel +spring.datasource.password=NeymarJr2024 spring.datasource.driver-class-name=org.postgresql.Driver - -spring.flyway.enabled=true +spring.flyway.enabled=false spring.flyway.locations=classpath:bd/migration spring.jpa.open-in-view=false