martes, 28 de noviembre de 2017

Quickstart for .NET in the App Engine Flexible Environment

  1. Use the GCP Console to create a new GCP project, create an App Engine application, and enable billing: 
    GO TO APP ENGINE
    When prompted, select the region where you want your App Engine application located and then enable billing.
  2. Install the following prerequisites locally:
    1. Download and install the Google Cloud SDK and then initialize the gcloud tool: 
      DOWNLOAD THE SDK
    2. Install the .NET Core SDK, LTS version.
    3. If you are using Visual Studio, to build and run .NET core applications you must install .NET Core tools.
      • Images are available for ASP.NET Core apps written for .NET Core 1.0, 1.1, and 2.0.
    4. To deploy to App Engine directly from Visual Studio, install Google Cloud Tools for Visual Studio.
This quickstart assumes that you are familiar with building web applications with C#.

Download the Hello World app

We've created a simple Hello World app for .NET so you can quickly get a feel for deploying an app to the App Engine flexible environment. It's basically the same application you get when you use Visual Studio to create an empty ASP.NET core application, with an added app.yaml file. The app.yaml file is a App Engine configuration file that specifies your runtime and other App Engine specific settings.
  1. Download the sample app and extract it.
  2. If you're using the command line, navigate into the app directory, dotnet-docs-samples\appengine\flexible\HelloWorld.

Run Hello World on your local machine

VISUAL STUDIO

COMMAND LINE

To run the Hello World app on your local computer:
  1. Run the following commands from the dotnet-docs-samples\appengine\flexible\HelloWorld directory:
    dotnet restore dotnet run
  2. In your web browser, navigate to http://localhost:5000/
    You can see the "Hello World" message from the sample app displayed in the page.
  3. In your terminal window, press Ctrl+C to exit the web server.

Deploy and run Hello World on App Engine

VISUAL STUDIO

COMMAND LINE

  1. Run the following commands from the dotnet-docs-samples\appengine\flexible\HelloWorld directory:
    dotnet restore dotnet publish -c Release gcloud app deploy .\bin\Release\netcoreapp1.0\publish\app.yaml
  2. Launch your browser and view the app at http://YOUR_PROJECT_ID.appspot.com, by running the following command:
    gcloud app browse
This time, the page that displays the Hello World message is delivered by a web server running on an App Engine instance.
Congratulations! You've deployed your first .NET app to App Engine flexible environment!
See the following sections for information about cleaning up as well as links to the possible next steps that you can take.

.NET on Google Cloud Platform

Original: https://github.com/salrashid123/gcpdotnet
Sample code demonstrating running trivial .NET web applications on Google Cloud Platform services.
These simply builds off of existing technologies and samples but configures it to run on GCP effeciently with healh checking and load balancing.

The example here uses Microsofts's .NET Core 1.0.0 RC/preview (dotnet-dev-1.0.0-preview2-003121).
FROM microsoft/dotnet:1.1.0-sdk-projectjson

ADD . /app
WORKDIR /app
RUN ["dotnet", "restore"]

EXPOSE 8080
WORKDIR /app/src/WebApplication1/
ENTRYPOINT ["dotnet", "run", "-p", "project.json"]

in project.json:
"Microsoft.NETCore.App": {
   "type": "platform",
   "version": "1.1.0"
}
You can use Visutal Studio 2015 to create and extend the sample from scratch. VS2015
  • WebApplication1 Default webapplication generated by Visual Studio 2015: "New Project
    • C#
      • Web
        • ASP.NET Core Web Application (.NET Core) ; (Change Authenticaiton --> No Authentication)
(optionally, if you want to try out Google APIs, see Using Google API Libraries)
Basic Configuration
Sample application simply spins up inside a Docker container an runs Kestrel to host the application. The sample is modified from the baseline in the following way to run with healthchecks in GCP:
  • port: 8080
  • GET requests to endpoint /_ah/health must return a 200 OK HTTP response
  • Use Kestrel Webserver

WebApplication1
Pack/Publish steps
If you want to pack the deployment to a .dll using dotnet publish
in project.json, if the following artifiact from Visual Studio exists, remove
  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
Then make the build/release .dll
cd WebApplication1/src/WebApplication1
dotnet restore
dotnet publish  -c Release
To run the local pack directly:
dotnet bin/Release/netcoreapp1.0/publish/WebApplication1.dll
Finally, edit the Dockerfile
FROM microsoft/dotnet:1.1.0-sdk-projectjson

ADD . /app
WORKDIR /app

EXPOSE 8080
WORKDIR /app/src/WebApplication1/
ENTRYPOINT ["dotnet", "bin/Release/netcoreapp1.0/publish/WebApplication1.dll"]
Note: As of 8/16, dotnet is currently not supported on Alpine Linux.
Deploying
Deploying to GCP requires your gcloud environment to get setup:
gcloud auth login
gcloud config set project <your_project>
AppEngine
Deploying to GAE is pretty simple:
gcloud app deploy app.yaml
Then, http://your_project.appspot.com
ContainerEngine
To deploy on GKE, you need to setup the replication controllers and frontend loadbalancer services as well as a small cluster.




viernes, 24 de noviembre de 2017

Types of Questions #3

Coding Fundamentals

What is a variable?

A place to store data

What is the difference between an integer and a float variable?

Integer just stores whole numbers or integral values, while a float variable stores numbers with potential use of decimals.

What is a conditional operator?

(!=, ==, >=, <=, …). Those are operators that compare two values in a conditional statement.

What is the difference between using ‘=’ and ‘==’ operators?

‘=’ is used to assign a value to a variable. “==” is a conditional operators that is used to compare values in a conditional statement.

What are conditional statements?

A conditional statement is an if-then statement. The conditional is defined to be true or false due to the operation you are leading.

What is a loop?

It is an operational cycle that goes through a conditional statement while this is true and executes a block of code.

What is the difference between a ‘for’ loop, a ‘while’ loop, and a ‘do-while’ loop?

for () performs statements repeatedly based on a condition.
while () performs statements repeatedly while condition remains true.
Do-while() performs statements repeatedly (at least once) while  condition remains true.

What is an array?

An array is a data structure that contains a number of variables, which are accessed through computed indices.

The variables contained in an array, are called the elements of the array. They must all be of the same type, and this type is called the element type of the array

How do you store/retrieve values in an array?

Declaration, Creation, Initialization. When an array is initialized there are methods that push or pull data into an array. Commonly the way to manipulate arrays is using cycles (loop, while, do-while).