Skip to content

Commit 18beb87

Browse files
committed
fixed failed to solve: process "/bin/sh -c dotnet publish K8sDotnetApi.csproj
1 parent b4a2599 commit 18beb87

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

.github/workflows/cd.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: CD Deploy to AKS
2+
23
on:
34
workflow_run:
45
workflows: ["CI Build & Push"]
@@ -13,24 +14,30 @@ env:
1314
jobs:
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:
@@ -48,9 +55,9 @@ jobs:
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

.github/workflows/ci.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: CI Build & Push
2+
23
on:
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

src/K8sDotnetApi/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Build stage
22
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
33
WORKDIR /src
4-
COPY . .
4+
COPY src/K8sDotnetApi/ ./
55
RUN dotnet publish K8sDotnetApi.csproj -c Release -o /app/publish
66

77
# Runtime stage
88
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
99
WORKDIR /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 ./
1211
RUN mkdir -p /app/data
1312
EXPOSE 8080
14-
# ASPNETCORE_URLS permite que Kestrel escuche en el puerto 8080 dentro del contenedor
1513
ENV ASPNETCORE_URLS=http://+:8080
1614
ENTRYPOINT ["dotnet", "K8sDotnetApi.dll"]

0 commit comments

Comments
 (0)