Skip to content

Commit 1739260

Browse files
authored
Merge pull request #36 from bradymholt/netcore21
Upgrade to .NET Core 2.1
2 parents 89927be + 901deb9 commit 1739260

File tree

20 files changed

+44
-4169
lines changed

20 files changed

+44
-4169
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
bin/
55
obj/
66
project.lock.json
7-
.NETCoreApp,Version=v2.0.AssemblyAttributes.cs
87
NuGetScratch/
98

109
api/wwwroot/**

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "coreclr",
77
"request": "launch",
88
"preLaunchTask": "build",
9-
"program": "${workspaceRoot}/api/bin/Debug/netcoreapp2.0/api.dll",
9+
"program": "${workspaceRoot}/api/bin/Debug/netcoreapp2.1/api.dll",
1010
"args": [],
1111
"env": {
1212
"ASPNETCORE_ENVIRONMENT": "Development",

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# ASP.NET Core / React SPA Template App
22

3-
This app is a template application using ASP.NET Core 2.0 for a REST/JSON API server and React for a web client.
3+
This app is a template application using ASP.NET Core 2.1 for a REST/JSON API server and React for a web client.
44

55
![screen recording 2017-06-10 at 04 12 pm](https://user-images.githubusercontent.com/759811/27006360-bd3b8152-4df7-11e7-9011-f22204abe4d5.gif)
66

77
## Overview of Stack
88
- Server
9-
- ASP.NET Core 2.0
10-
- PostgreSQL
9+
- ASP.NET Core 2.1
10+
- PostgreSQL 10
1111
- Entity Framework Core w/ EF Migrations
1212
- JSON Web Token (JWT) authorization
1313
- Docker used for development PostgreSQL database and MailCatcher server
@@ -31,7 +31,7 @@ This app is a template application using ASP.NET Core 2.0 for a REST/JSON API se
3131
## Setup
3232

3333
1. Install the following:
34-
- [.NET Core 2.0](https://www.microsoft.com/net/core)
34+
- [.NET Core 2.1](https://www.microsoft.com/net/core)
3535
- [Node.js >= v8](https://nodejs.org/en/download/)
3636
- [Ansible >= 2.0](http://docs.ansible.com/ansible/intro_installation.html)
3737
- [Docker](https://docs.docker.com/engine/installation/)
@@ -69,7 +69,9 @@ This will run the xUnit tests in api.test/ and the Mocha/Enzyme tests in client-
6969

7070
_Before running this script, you need to create an ops/hosts file first. See the [ops README](ops/) for instructions._
7171

72-
This will run the ops/provision.yml Ansible playbook and provision hosts in ops/hosts inventory file. This prepares the hosts to recieve deployments by doing the following:
72+
This will run the ops/provision.yml Ansible playbook and provision hosts in ops/hosts inventory file. Ubuntu 16.04 (Xenial) and Ubuntu 18.04 (Bionic) is supported and tested.
73+
74+
This prepares the hosts to recieve deployments by doing the following:
7375
- Install Nginx
7476
- Generate a SSL certificate from [Let's Encrypt](https://letsencrypt.org/) and configure Nginx to use it
7577
- Install .Net Core
@@ -86,7 +88,9 @@ _Before running this script, you need to create a ops/hosts file first. See the
8688
This script will:
8789
- Build release Webpack bundles
8890
- Package the .NET Core application in Release mode (dotnet publish)
89-
- Run the ops/deploy.yml Ansible playbook to deploy this app to hosts in /ops/hosts inventory file. This does the following:
91+
- Run the ops/deploy.yml Ansible playbook to deploy this app to hosts in /ops/hosts inventory file.
92+
93+
This does the following:
9094
- Copies the build assets to the remote host(s)
9195
- Updates the `appsettings.json` file with PostgreSQL credentials specified in ops/hosts file and the app URL (needed for JWT tokens)
9296
- Restarts the app so that changes will be picked up

api.test/api.test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
44
<AssemblyName>api.test</AssemblyName>
55
<PackageId>api.test</PackageId>
66
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

api/Migrations/20171204210645_Initial.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/Migrations/20171204210645_Initial.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.EntityFrameworkCore.Metadata;
22
using Microsoft.EntityFrameworkCore.Migrations;
3+
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
34
using System;
45
using System.Collections.Generic;
56

api/Migrations/DefaultDbContextModelSnapshot.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.EntityFrameworkCore.Migrations;
77
using Microsoft.EntityFrameworkCore.Storage;
88
using Microsoft.EntityFrameworkCore.Storage.Internal;
9+
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
910
using System;
1011

1112
namespace api.Migrations

api/api.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
44
<AssemblyName>api</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<PackageId>api</PackageId>
@@ -14,12 +14,8 @@
1414
</None>
1515
</ItemGroup>
1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
17+
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.4" />
1818
<PackageReference Include="AspNet.Security.OAuth.Validation" Version="2.0.0-*" />
19-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" />
20-
</ItemGroup>
21-
<ItemGroup>
22-
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
23-
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
19+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.2" />
2420
</ItemGroup>
2521
</Project>

ops/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This folder contains [Ansible](https://www.ansible.com/) assets responsible for
22

33
## Setup
44

5-
1. Procure access to Ubuntu 16 host(s) which will be used to host this application. [AWS](aws.amazon.com) or [Digital Ocean](https://m.do.co/c/974ef9a471c1) are good options.
5+
1. Procure access to Ubuntu 16.04 (Xenial) or Ubuntu 18.04 (Bionic) host which will be used to host this application. [AWS](aws.amazon.com) or [Digital Ocean](https://m.do.co/c/974ef9a471c1) are good options.
66
2. Setup DNS records to point to these host(s).
77
3. Create `hosts` file in this directory, using `hosts.example` as a pattern.
88

ops/group_vars/all

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
database_name: "{{ app_name }}"
33
database_username: "{{ app_name }}"
4+
source_directory: ../api/bin/Release/netcoreapp2.1/publish/
45
deploy_directory: "/home/{{ deploy_user }}/apps/{{ app_name }}"
56
email_enable_ssl: true
67
email_from_name: "{{ app_name }}"

ops/hosts.example

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# Global variables
22
[all:vars]
3-
app_name=aspnetCoreReactTemplate # Name of the application
4-
source_directory=../../../../appName/bin/Release/netcoreapp2.0/publish/ # The local deploy build asset source location (source files for deploy)
5-
entry_dll_file_name=api.dll # The name of the .NET Core DLL to run
3+
app_name=aspnetCoreReactTemplate
64

75
# Production variables
86
[production_web]
97
0.0.0.0 # The IP address or hostname of the production web server
108

119
[production:vars]
12-
deploy_user=jdoe # The name of the remote user account for provisioning and deployment
10+
# The name of the remote user account for provisioning and deployment
11+
deploy_user=jdoe
1312
gh_pubkey_user=johndoe1981 # The GitHub username used to pull the public key for deploy_user authorized_user access
1413
use_ssl=true # If true, SSL cert will be obtained from Let's Encrypt and Nginx provisioned for SSL
1514
letsencrypt_use_live_ca=true # If true, will use the Live Let's Encrypt ACME servers; otherwise will use staging server
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
dotnetcore_package_name: dotnet-sdk-2.0.0
2+
dotnetcore_package_name: dotnet-sdk-2.1

ops/roles/dotnetcore/tasks/main.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
---
2-
- name: Create dotnetdev.list file
3-
command: touch /etc/apt/sources.list.d/dotnetdev.list creates="/etc/apt/sources.list.d/dotnetdev.list"
2+
- name: Download product repository file
3+
get_url:
4+
url: "https://packages.microsoft.com/config/ubuntu/{{ansible_distribution_major_version}}.04/packages-microsoft-prod.deb"
5+
dest: "/tmp/packages-microsoft-prod.deb"
6+
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "18"
47

5-
- name: Set apt-get feed for Ubuntu Xenial
6-
lineinfile: dest=/etc/apt/sources.list.d/dotnetdev.list line="deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main"
7-
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "16"
8+
- name: Execute dehydrated shell script
9+
shell: "dpkg -i /tmp/packages-microsoft-prod.deb"
810

9-
- name: Set apt-get feed for Ubuntu Trusty
10-
lineinfile: dest=/etc/apt/sources.list.d/dotnetdev.list line="deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main"
11-
when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version == "14"
12-
13-
- name: Add apt key
14-
apt_key: keyserver=apt-mo.trafficmanager.net id=417A0893
11+
- name: Install transport-https
12+
apt: pkg=apt-transport-https state=present update_cache=yes
1513

1614
- name: Install dotnet core SDK
17-
apt: name={{ dotnetcore_package_name }} state=present update_cache=yes
15+
apt: name={{ dotnetcore_package_name }} state=present

ops/roles/postgresql/tasks/configure.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- name: Configure | postgres | pidfile
1515
lineinfile:
1616
state: present
17-
dest: "/etc/postgresql/{{ postgresql_version }}/main/postgresql.conf"
17+
dest: "/etc/postgresql/{{ postgresql_major_version }}/main/postgresql.conf"
1818
regexp: '^#*external_pid_file'
1919
line: "external_pid_file = '{{ postgresql_pidfile_path }}'"
2020
notify: Reload Service | postgres
@@ -25,7 +25,7 @@
2525
- name: Configure | postgres | listen_address
2626
lineinfile:
2727
state: present
28-
dest: "/etc/postgresql/{{ postgresql_version }}/main/postgresql.conf"
28+
dest: "/etc/postgresql/{{ postgresql_major_version }}/main/postgresql.conf"
2929
regexp: '^#* *listen_addresses ='
3030
line: "listen_addresses = '*'"
3131
notify: Reload Service | postgres
@@ -36,7 +36,7 @@
3636
- name: Configure | postgres | pg_hba.conf
3737
lineinfile:
3838
state: present
39-
dest: "/etc/postgresql/{{ postgresql_version }}/main/pg_hba.conf"
39+
dest: "/etc/postgresql/{{ postgresql_major_version }}/main/pg_hba.conf"
4040
regexp: "^#* *host {{ item }}"
4141
line: "host {{ item }} {{ database_username | default(project) }} all md5"
4242
with_items:

ops/roles/postgresql/vars/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
postgresql_version: '9.5'
2+
postgresql_major_version: '10'
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
entry_dll_file_name: "{{app_name}}.dll"
21
log_file: "/var/log/{{app_name}}.out.log"
32
error_file: "/var/log/{{app_name}}.err.log"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
- name: Reload supervisor
3+
become: true
34
service: name=supervisor state=reloaded enabled=true
45

56
- name: Reload supervisor app config
6-
become: yes
7-
become_method: sudo
7+
become: true
88
command: supervisorctl restart {{app_name}}

ops/roles/supervisor/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
- name: Install Supervisor
3+
become: true
34
apt: pkg=supervisor state=present cache_valid_time=86400
45

56
- name: Setup app config
7+
become: true
68
template: src=etc_supervisor_conf.d_app_name.conf.j2 dest=/etc/supervisor/conf.d/{{app_name}}.conf
79
notify: Reload supervisor
810

911
- name: Create .NET Core cert cache directory and give access to {{ webserver_user }}
12+
become: true
1013
file: path=/var/www/.dotnet/corefx/cryptography/crls state=directory owner={{ webserver_user }} group={{ webserver_user }} mode=0775

ops/roles/supervisor/templates/etc_supervisor_conf.d_app_name.conf.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[program:{{app_name}}]
2-
command=/usr/bin/dotnet {{deploy_directory}}/{{entry_dll_file_name}}
2+
command=/usr/bin/dotnet {{deploy_directory}}/api.dll
33
directory={{deploy_directory}}
44
autostart=true
55
autorestart=true

0 commit comments

Comments
 (0)