Skip to content

removes circleci deployment workflow && add the github actions workflow #2

removes circleci deployment workflow && add the github actions workflow

removes circleci deployment workflow && add the github actions workflow #2

name: Build and Deploy Spring Boot Application to Azure
on:
push:
branches:
- main # Only triggers on the 'main' branch (for production builds)
- dev # Triggers on the 'dev' branch (for dev/test builds)
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout repository
uses: actions/checkout@v2
with:
path: backend # This sets the context to the 'backend' folder.
# Step 2: Set up JDK 17
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
# Step 3: Build the application with Maven
- name: Build with Maven
working-directory: ./backend
run: mvn clean package -DskipTests
# Step 4: Log in to Azure Container Registry (ACR)
- name: Log in to Azure Container Registry
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.AZURE_REGISTRY_USERNAME }}
password: ${{ secrets.AZURE_REGISTRY_PASSWORD }}
# Step 5: Build Docker image
- name: Build Docker image
working-directory: ./backend
run: docker build -t ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}/marketspy-backend:${{ github.sha }} .
# Step 6: Push Docker image to ACR
- name: Push Docker image to ACR
run: docker push ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}/marketspy-backend:${{ github.sha }}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
# Step 7: Deploy to Azure Spring Apps based on branch (production or devment)
- name: Deploy to Azure Spring Apps
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "Deploying to production environment"
az login
az spring app deploy --name marketspy-backend --resource-group ${{ secrets.AZURE_RESOURCE_GROUP_PROD }} --service ${{ secrets.AZURE_SPRING_SERVICE_PROD }} --container-registry ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }} --image ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}/marketspy-backend:${{ github.sha }}
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
echo "Deploying to devment environment"
az login
az spring app deploy --name marketspy-backend --resource-group ${{ secrets.AZURE_RESOURCE_GROUP_DEV }} --service ${{ secrets.AZURE_SPRING_SERVICE_DEV }} --container-registry ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }} --image ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}/marketspy-backend:${{ github.sha }}
fi