The API First Design strategy is used to develop ASP.NET Core Web APIs automatically generated by Swagger Hub. The faster build and availability of Visual Studio environment are the key advantages of this starter kit targeting the Raspberry Pi.
Starting from a Swagger API definition, an ASP.NET Core Web API is automatically generated by Swagger Hub. The code is pushed to github and then loaded by a Windows x64 machine and upgraded to ASP.NET Core 2.0, using Visual Studio 2017.
A multi-stage docker image build is accomplished at the speedy Windows x64 machine, generating code of linux-arm framework. The image container is pushed to the cloud and then pulled back into a Raspberry Pi with Raspbian 9.1 stretch installed.
- Restlet generates API and exports swagger.json
- Swagger Hub imports file and generates server stub
- Install Docker
- Pull server stub from github
- Upgrade to .NET Core 2 and Docker support
- Create multi-stage image build for server stub
- Compiles at x64 machine for linux-arm framework
- Push Docker image to cloud
- Raspbian GNU/Linux 9.1 (stretch)
- Install Docker
- Run Docker image
- Go back to x64 machine
- Access rpi-server-stub via browser
- http://rpi:5000/swagger/ui/index.html
Testing API at port:5000 with code generated from SwaggerHub.
Links:
https://app.swaggerhub.com/apis/josemottalopes/contacts-api/1.2.0
https://github.com/josemotta/Api
https://hub.docker.com/r/josemottalopes/io.swagger/
cd /aspnetcore
docker-compose -f docker-compose.ci.build.yml build
docker push josemottalopes/io.swagger:latest
docker run --privileged -p 5000:5000 -d josemottalopes/io.swagger
http://rpi:5000/swagger/ui/index.html
Starter for Home project at port:5010
Links:
https://app.swaggerhub.com/apis/josemottalopes/home-api/1.0.1
https://github.com/josemotta/Api
https://hub.docker.com/r/josemottalopes/home-web/
cd /home-web
docker-compose -f docker-compose.ci.build.yml build
docker push josemottalopes/home-web:latest
docker run --privileged -p 5010:5010 -d josemottalopes/home-web
http://rpi:5010/swagger/ui/index.html
Web UI Starter for Home project (port:80) using RazorPageShop from Marcelo Oliveira as a template. Another option would be a "regular" ASP.NET Core MVC Application.
Razor
From MVC to Razor Pages
ASP.NET Core Application
Building an ASP.NET Core Application with Web API and Code First Development
React
React Shop - A Tiny E-Commerce
DAL/DB (check .net 2.0 support?)
Building Entity Framework Disconnected Generic Repository
Links:
https://github.com/josemotta/Api
https://hub.docker.com/r/josemottalopes/home-pi-1/
cd razorpageshop
docker-compose -f docker-compose.pi.yml build
docker push josemottalopes/home-pi-1:latest
docker run --privileged -p 80:80 -d josemottalopes/home-pi-1
http://rpi
The commands start clearing all docker containers and images:
# Stop the containers
root@lumi:# docker stop $(docker ps -a -q)
# Delete all containers
root@lumi:# docker rm $(docker ps -a -q)
# Delete all images
root@lumi:# docker rmi --force $(docker images -q)
Then all projects are started, downloading images from cloud (DockerHub) to RPI:
#alias homeweb='docker run --privileged -p 5010:5010 -d josemottalopes/home-web:latest'
#alias ioswagger='docker run --privileged -p 5000:5000 -d josemottalopes/io.swagger:latest'
root@lumi:# homeweb
Unable to find image 'josemottalopes/home-web:latest' locally
latest: Pulling from josemottalopes/home-web
e7ea15fa8fb2: Pull complete
14ae8f7a598f: Pull complete
15d4c9904a5d: Pull complete
4e1120917082: Pull complete
b8d414906f99: Pull complete
0dfe3a2727e0: Pull complete
Digest: sha256:48da4f5cff21fd7d1f44c0e129a9b0de3114e48124d491f1da1f1a1ecfa1cf33
Status: Downloaded newer image for josemottalopes/home-web:latest
2e8be31f9e5e641ddfb94e3db5d4770c039dedc410c0d66f86555e9286e34f0a
root@lumi:/# ioswagger
Unable to find image 'josemottalopes/io.swagger:latest' locally
latest: Pulling from josemottalopes/io.swagger
e7ea15fa8fb2: Already exists
14ae8f7a598f: Already exists
15d4c9904a5d: Already exists
4e1120917082: Already exists
b8d414906f99: Already exists
97db2d097015: Pull complete
Digest: sha256:5eac7701f0d884d3ef6b1eeafb773014a042389ddacc7342cc8a87eaab618cf4
Status: Downloaded newer image for josemottalopes/io.swagger:latest
19285505a953d130401a42aa67017f6f7289d9838adb1b0e994cb7d841acb53a
You can notice the second project share five images with first project and they don't need to be downloaded again. The docker images and running containers are shown below:
root@lumi:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a347c582e14e josemottalopes/io.swagger:latest "/bin/sh -c /app/I..." 2 minutes ago Up 2 minutes 0.0.0.0:5000->5000/tcp dreamy_bose
268429269f52 josemottalopes/home-web:latest "/bin/sh -c /app/I..." 2 minutes ago Up 2 minutes 0.0.0.0:5010->5010/tcp epic_swirles
22337a4f50b8 josemottalopes/home-pi-1:latest "dotnet RazorPageS..." 25 hours ago Up 25 hours 0.0.0.0:80->80/tcp goofy_wescoff
root@lumi:~# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
josemottalopes/home-pi-1 latest 7e335e37b9d3 28 hours ago 249MB
josemottalopes/home-web latest 75e89c7c1cf5 4 weeks ago 235MB
josemottalopes/io.swagger latest fb9745c521f5 7 weeks ago 235MB
root@lumi:~#
There are a couple ASP.NET Core Web APIs listening to ports 5000 and 5010, each one related to a different swagger file. The Web UI is running on port 80, although the activation is not shown above.
Following is a full activation after a boot, considering that all containers are already loaded.
alias yhomeweb='docker run --privileged -p 5010:5010 -d josemottalopes/home-web:latest'
alias yioswagger='docker run --privileged -p 5000:5000 -d josemottalopes/io.swagger:latest'
alias yrazor='docker run --privileged -p 80:80 -d josemottalopes/home-pi-1:latest'
root@lumi:~# yioswagger
98815f8f3381212979098b27c80fdf6f226bf10dfd237c448f8b2fc3c63bd754
root@lumi:~# yhomeweb
694c4be94e3de0789ee4822bca51c0266f1933edb8201e1953faa32dd9794656
root@lumi:~# yrazor
cf531a536076373cde0bdf1fe292997e89c5f2c2f51bc718e317930a2499cc56
root@lumi:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf531a536076 josemottalopes/home-pi-1:latest "dotnet RazorPageS..." 17 seconds ago Up 7 seconds 0.0.0.0:80->80/tcp admiring_edison
694c4be94e3d josemottalopes/home-web:latest "/bin/sh -c /app/I..." 27 seconds ago Up 16 seconds 0.0.0.0:5010->5010/tcp youthful_colden
98815f8f3381 josemottalopes/io.swagger:latest "/bin/sh -c /app/I..." 35 seconds ago Up 27 seconds 0.0.0.0:5000->5000/tcp suspicious_albattani