I am trying to complete a Github action to build and deploy my .Net8 web API with Docker to Kubernetes. Here is the yml file I am currently using for the workflow:
name: Deploy to DigitalOcean Kubernetes
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
NUGETUSERNAME: ${{ secrets.NUGETUSERNAME }}
NUGETPASSWORD: ${{ secrets.NUGETPASSWORD }}
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Log in to DigitalOcean Container Registry
uses: docker/login-action@v1
with:
registry: registry.digitalocean.com
username: _ # DigitalOcean requires username to be `_`
password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Replace Github Username In Nuget.Config
run: sed -i 's/%NUGETUSERNAME%/${{ secrets.NUGETUSERNAME }}/g' x/x.Api/nuget.config
- name: Replace Github Password In Nuget.Config
run: sed -i 's/%NUGETPASSWORD%/${{ secrets.NUGETPASSWORD }}/g' x/x.Api/nuget.config
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: x/x.Api
file: x/x.Api/Dockerfile
push: true
tags: registry.digitalocean.com/x-api/aggregator-api:latest # Replace with your registry and image name
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Install Kompose
run: |
curl -L https://github.com/kubernetes/kompose/releases/download/v1.26.0/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv kompose /usr/local/bin/kompose
- name: Convert Docker Compose to Kubernetes manifests
run: kompose convert -f docker-compose.yml -o ./k8s/
- name: Set up Kubectl
uses: azure/setup-kubectl@v1
- name: Configure Kubernetes context
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
- name: Deploy to Kubernetes
run: |
kubectl apply -f ./k8s/
- name: Verify deployment
run: kubectl rollout status deployment/x
Here is the Docker file of the API
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["x.Api.csproj", "x.Api/"]
COPY ./nuget.config ./
RUN dotnet restore "./x.Api/./x.Api.csproj" --configfile nuget.config
COPY . .
WORKDIR "/src/x.Api"
RUN dotnet build "./x.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./x.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "x.Api.dll"]
When the Github Action is run, it fails and I get the following (on dotnet build):
"Program does not contain a static 'Main' method suitable for an entry point"
I have updated the Docker file to use this line to be more specific:
RUN dotnet build "./x.Api.csproj" -v=q /property:StartupObject=x.Api.Program -c $BUILD_CONFIGURATION -o /app/build
It again fails with:
"Could not find 'x.Api.Program' specified for Main method" and "
This project builds fine locally using docker-compose.
Anyone know whats going on here?