3

I'm using Google Cloud to host my .Net Core 2.2 application, but I want to update it to 3.0. My app.yaml looks like this

service: api runtime: aspnetcore env: flex 

I know that I can specify the .Net Core version in runtime section. But Google Cloud Container Registry doesn't have .Net Core 3.0. I've checked it here.

Should I make a custom container then? I have zero experience with docker. Maybe there is a ready-to-go container somehow.

I didn't found any roadmap for update .Net Core images in public Container Registry.

@update

Solution

It's working!

My dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY MyProject.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish /app/MyProject.csproj -c Release -o ./out --nologo # Build runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app COPY --from=build-env /app/out/ . EXPOSE 8080 ENV ASPNETCORE_URLS=http://*:8080 ENV ASPNETCORE_ENVIRONMENT=production ENV TAPTAKE_SEED=false ENTRYPOINT ["dotnet", "MyProject.dll"] 

And my new app.yaml

service: api runtime: custom env: flex env_variables: ASPNETCORE_ENVIRONMENT: "production" # Note this manual scaling is only for development manual_scaling: instances: 1 resources: cpu: 1 memory_gb: 4 disk_size_gb: 10 

And my cloudbuild.yaml:

steps: # Build - name: 'gcr.io/cloud-builders/dotnet' args: [ 'publish', '-c', 'Release' ] dir: 'MyProject' # Migrations - name: 'gcr.io/cloud-builders/dotnet' args: [ 'ef', 'database', 'update' , '--configuration', 'Production'] dir: 'MyProject' env: - 'ASPNETCORE_ENVIRONMENT=production' # DEPLOY - name: 'gcr.io/cloud-builders/gcloud' args: ['app','deploy','MyProject/bin/Release/netcoreapp3.1/publish/app.yaml', '--verbosity=debug'] timeout: '1200s' 
1
  • 1
    I'm not sure about the exact syntax, but you should be able to reference the image from any registry, and in the case of ASP.NET Core, that registry should be mcr.microsoft.com. Commented Oct 22, 2019 at 13:23

1 Answer 1

5

Since you are already using the Flexible environment, one possible solution would be to set the runtime to custom and then use a Dockerfile to specify the image that you would like, which in this case is .Net Core 3.0.

As an example, the app.yaml file can be re-written like such:

service: api runtime: custom env: flex 

We could also write the Dockerfile on top of the example given in the official docker docs

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "aspnetapp.dll"] 

Again, this is only one of the possible solutions. Google has an article that describes 4 ways you can deploy a .Net Core application. Granted, it is a few years old, but concepts should still apply. As an overview, you can:

  • Deploy from Visual Studio directly using the Cloud Tools for Visual Studio extension
  • Deploy a Framework Dependent Deployment bundle with "dotnet publish"
  • Deploy to App Engine flexible environment with a custom Dockerfile
  • Deploy to Container Engine with a custom Dockerfile
Sign up to request clarification or add additional context in comments.

5 Comments

That looks promising. Actually I have a setup with Cloud Build and Triggers using cloudbuild.yaml and the last step is deploy
This is the approach I'd recommend as a Googler, too. While we have previously provided .NET Core specific images, the "vanilla" images from Microsoft absolutely should work, and are the best approach to use, at least for now.
@Morasiu let me know how it went for you.
Updates on this would be nice. If anybody has any insight!
@ThorkilVærge Updated ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.