File tree Expand file tree Collapse file tree 3 files changed +30
-16
lines changed
Expand file tree Collapse file tree 3 files changed +30
-16
lines changed Original file line number Diff line number Diff line change 11name : CD Deploy to AKS
2+
23on :
34 workflow_run :
45 workflows : ["CI Build & Push"]
1314jobs :
1415 deploy :
1516 runs-on : ubuntu-latest
17+
1618 steps :
17- - uses : actions/checkout@v3
19+ - name : Checkout code
20+ uses : actions/checkout@v3
1821
1922 - name : Azure Login
2023 uses : azure/login@v1
2124 with :
2225 creds : ${{ secrets.AZURE_CREDENTIALS }}
2326
24- - name : Get Terraform Outputs
27+ - name : Terraform Init & Get Outputs
2528 id : tfout
2629 run : |
30+ terraform -chdir=infra init -input=false
2731 echo "acr=$(terraform -chdir=infra output -raw acr_login_server)" >> $GITHUB_OUTPUT
2832 echo "aks=$(terraform -chdir=infra output -raw aks_name)" >> $GITHUB_OUTPUT
2933 echo "rg=$(terraform -chdir=infra output -raw aks_rg_name)" >> $GITHUB_OUTPUT
3034
3135 - name : Get AKS Credentials
3236 run : |
33- az aks get-credentials --name "${{ steps.tfout.outputs.aks }}" --resource-group "${{ steps.tfout.outputs.rg }}" --overwrite-existing
37+ az aks get-credentials \
38+ --name "${{ steps.tfout.outputs.aks }}" \
39+ --resource-group "${{ steps.tfout.outputs.rg }}" \
40+ --overwrite-existing
3441
3542 - name : Patch Deployment Image
3643 env :
4855 run : |
4956 echo "Esperando EXTERNAL-IP..."
5057 for i in {1..30}; do
51- ip=$(kubectl get svc hola-mundo-dotnet-svc -o jsonpath='{.status.loadBalancer.ingress[0].ip}' || true)
58+ ip=$(kubectl get svc hola-mundo-dotnet-svc -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null || true)
5259 if [ -n "$ip" ]; then
53- echo "EXTERNAL-IP =$ip" >> $GITHUB_ENV
60+ echo "EXTERNAL_IP =$ip" >> $GITHUB_ENV
5461 echo "External IP: $ip"
5562 break
5663 fi
Original file line number Diff line number Diff line change 11name : CI Build & Push
2+
23on :
34 workflow_run :
45 workflows : ["Terraform Create Infra"]
@@ -14,22 +15,30 @@ jobs:
1415 build :
1516 runs-on : ubuntu-latest
1617 steps :
17- - uses : actions/checkout@v3
18+ - name : Checkout code
19+ uses : actions/checkout@v3
1820
1921 - name : Azure Login
2022 uses : azure/login@v1
2123 with :
22- creds : ${{ secrets.AZURE_CREDENTIALS }}
24+ creds : ${{ secrets.AZURE_CREDENTIALS }}
25+
26+ - name : Set up Terraform
27+ uses : hashicorp/setup-terraform@v3
2328
24- - name : Get ACR login server from terraform output
29+ - name : Get ACR login server from Terraform output
2530 id : get_acr
26- run : echo "acr=$(terraform -chdir=infra output -raw acr_login_server)" >> $GITHUB_OUTPUT
31+ run : |
32+ terraform -chdir=infra init -input=false
33+ ACR_LOGIN_SERVER=$(terraform -chdir=infra output -raw acr_login_server)
34+ echo "acr_login_server=$ACR_LOGIN_SERVER" >> $GITHUB_OUTPUT
2735
2836 - name : Docker Build & Push
2937 env :
30- ACR_LOGIN_SERVER : ${{ steps.get_acr.outputs.acr }}
38+ ACR_LOGIN_SERVER : ${{ steps.get_acr.outputs.acr_login_server }}
3139 run : |
3240 echo "ACR_LOGIN_SERVER=$ACR_LOGIN_SERVER"
33- az acr login --name $(echo $ACR_LOGIN_SERVER | cut -d'.' -f1)
34- docker build -t $ACR_LOGIN_SERVER/hola-mundo-dotnet:latest ./src/K8sDotnetApi
41+ ACR_NAME=$(echo $ACR_LOGIN_SERVER | cut -d'.' -f1)
42+ az acr login --name $ACR_NAME
43+ docker build -t $ACR_LOGIN_SERVER/hola-mundo-dotnet:latest -f src/K8sDotnetApi/Dockerfile .
3544 docker push $ACR_LOGIN_SERVER/hola-mundo-dotnet:latest
Original file line number Diff line number Diff line change 11# Build stage
22FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
33WORKDIR /src
4- COPY . .
4+ COPY src/K8sDotnetApi/ ./
55RUN dotnet publish K8sDotnetApi.csproj -c Release -o /app/publish
66
77# Runtime stage
88FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
99WORKDIR /app
10- COPY --from=build /app/publish .
11- # Crear carpeta para datos SQLite (montada luego via PVC en K8s)
10+ COPY --from=build /app/publish ./
1211RUN mkdir -p /app/data
1312EXPOSE 8080
14- # ASPNETCORE_URLS permite que Kestrel escuche en el puerto 8080 dentro del contenedor
1513ENV ASPNETCORE_URLS=http://+:8080
1614ENTRYPOINT ["dotnet" , "K8sDotnetApi.dll" ]
You can’t perform that action at this time.
0 commit comments