|
| 1 | +## How to containerized a new Asp.net Boiler Plate Application |
| 2 | + |
| 3 | +#### Intro: |
| 4 | + |
| 5 | +This instructions will allow runing one aspnetboilerplate application as docker containers. The Dockerfile and docker-compose files are taken from a repository pull request listed below. |
| 6 | + |
| 7 | +#### Requirements: |
| 8 | + |
| 9 | +To follow along this instructions you will need to be familiar with git, aspnetboilerplate, docker, aspnet core, angular. |
| 10 | + |
| 11 | +The tools being used here are: |
| 12 | +- Git command line for Linux or Mac or Git bash for Windows |
| 13 | +- Docker for Linux or Mac or Windows |
| 14 | +- Docker Compose for Linux or Mac or Windows |
| 15 | +- MS SQL Server Instance |
| 16 | + |
| 17 | +#### Instructions: |
| 18 | + |
| 19 | +- Download the new application from aspnetboilerplate website. Ex: `https://aspnetboilerplate.com/Templates`. For our example we are taking ASP.NET Core target version v7.x and Single Page Web Application with Angular. |
| 20 | +- Leave the Options by default which will be Include login, register, user, roles and tenant management pages. And untick the One solution. |
| 21 | +- Set your project name to be MyCollege. |
| 22 | +- Enter the captcha code, leave the latest stable version and click the download project button. |
| 23 | +- You will get a MyCollege.zip file. |
| 24 | +- Extract this file, and inside you will file the version number in our example we have 7.3. We don't need this version now. Go inside the version number folder and create a git repository in there. In my example, I will be doing: |
| 25 | + - `unzip MyCollege.zip -d MyCollege/` |
| 26 | + - `cd MyCollege/7.3.0/` |
| 27 | +- Once terminal and navigated to inside the version number folder, once there execute those commands: |
| 28 | + - `git init` |
| 29 | + - `git add .` |
| 30 | + - `git commit -m 'my initial commit'` |
| 31 | +- Then we are going to add some Docker files from this repository pull request `https://github.com/aspnetboilerplate/module-zero-core-template/pull/613`. Basically we are taking all updated and new files from this pull request and copy them over to our new project folder. In my example I am copying those file with this command: |
| 32 | + - `cp -r ../../copy-from-merge/* ./` |
| 33 | +- Open the root of the repository folder with any IDE/text editor of your preference, I am using VS Code. |
| 34 | +- Update the file `aspnet-core/Dockerfile` place holder `AbpCompanyName.AbpProjectName` with your project own name. In my case I am doing `MyCollege` name, and executing this commands: |
| 35 | + - `cat ./aspnet-core/Dockerfile` |
| 36 | + - `sed -i "s/AbpCompanyName.AbpProjectName/MyCollege/g" ./aspnet-core/Dockerfile` |
| 37 | + - `cat ./aspnet-core/Dockerfile` |
| 38 | +- Create a new database in your MS SQL Server, for me it will be dbMyCollege. Therefore I am going to MS SQL Management Studio and executing the `CREATE DATABASE MyCollegeDb` command. |
| 39 | +- Go back to VS code and set the connection string in the `aspnet-core/src/MyCollege.Migrator/appsettings.json` file. For my example the connection string will be: `Server=192.168.22.101;Database=dbMyCollege;User Id=sa;Password=D8JeW7jjSmBVXLcRxWLDwMjYLnf6xVG8;`. For my example: |
| 40 | + - `cat ./aspnet-core/src/MyCollege.Migrator/appsettings.json` |
| 41 | + - `sed -i "s/Server=localhost; Database=MyCollegeDb; Trusted_Connection=True;/Server=192.168.22.101;Database=dbMyCollege;User Id=sa;Password=D8JeW7jjSmBVXLcRxWLDwMjYLnf6xVG8;/g" ./aspnet-core/src/MyCollege.Migrator/appsettings.json` |
| 42 | + - `cat ./aspnet-core/src/MyCollege.Migrator/appsettings.json` |
| 43 | +- With your terminal navigate to migration project folder and run this project with the following command: |
| 44 | + - `cd ./aspnet-core/src/MyCollege.Migrator` |
| 45 | + - `dotnet run` |
| 46 | +- Build the container image for the Angular Application and the Aspnet Core Application by running the script hosted in `aspnet-core/build/build-with-ng-updated.sh`. Please note this script is expecting you to navigate your terminal to the folder `aspnet-core/build` and then execute the script from there. |
| 47 | + - `cd ../../../aspnet-core/build` |
| 48 | + - `ls -al` |
| 49 | + - `cat ./build-with-ng-updated.sh` |
| 50 | + - `./build-with-ng-updated.sh` |
| 51 | +- Run your docker-compose file by navigating your terminal to: `aspnet-core/docker/ng`. And executing the following command: |
| 52 | + - `docker-compose up -d`. |
| 53 | + |
| 54 | +#### Final Notes: |
| 55 | +Once the pull request is merged all you would need to run your application as docker container is follow the steps number 11 and 15. |
0 commit comments