Build Type | Status |
---|---|
Latest CI Build | |
Latest CD Build |
This repository contains the source code for https://www.dnistream.live - a platform agnostic development podcast website hosted by Chris Sebok and Josey Howarth.
Front-end test coverage is slightly lower than normal, though all pertinent back-end service code is covered adequately.
This solution consists of the following artifacts:
- A .Net Core 3.1 RESTful Web API (src/DNI.API)
- An Angular front-end (with a small number of Karma / Jasmine tests) (src/DNI.Web)
- A docker / docker-compose configuration for production deployment (docker-compose.yml)
- NGINX configuration files for a docker reverse proxy deployment (NGINX folder)
All data comes from Fireside's RSS feed.
The solution relies heavily on a number of configuration values and secret keys for API integration. These keys are not pushed to the repository, but are accessed from a local .env
file on the developer's machine, and within the CI / CD pipeline. All APIs are configured with both development and production keys with the relevant security restrictions (IP, referrer etc). Please speak to Chris Sebok if you need access to these keys, though you can set up and configure your own if you are forking this repository to create a similar website.
A number of helper scripts are included to facilitate the setup of a development environment on a Windows box. Docker is not used for development, but can be configured for local testing & debugging of production deployment.
Both the local development environment and the local docker deployment testing environments require a .env
file to be created in the repository root with the following contents (sensitive info redacted):
IMAGE_PREFIX=docker.pkg.github.com/dnistream/dni.website/
ANGULAR_ENV=production
ASPNETCORE_ENVIRONMENT=Production
ASPNET_CONFIGURATION=Release
CAPTCHA_KEY=<REDACTED>
SMTP_SERVER=<REDACTED>
SMTP_PORT=25
SMTP_ENABLE_SSL=True
SMTP_USERNAME=<REDACTED>
SMTP_PASSWORD=<REDACTED>
LOG_MOUNT_PATH=/app/api.dnistream.live/logs
LOCAL_WEB_PORT=8080
LOCAL_API_PORT=8181
ERROR_EMAIL_FROM=<REDACTED>
ERROR_EMAIL_TO=<REDACTED>
CONTACT_EMAIL_TO=<REDACTED>
IMAGE_PREFIX=docker.pkg.github.com/dnistream/dni.website/ (or empty)
ANGULAR_ENV=dev
ASPNETCORE_ENVIRONMENT=Development
ASPNET_CONFIGURATION=Debug
CAPTCHA_KEY=<REDACTED>
SMTP_SERVER=host.docker.internal
SMTP_ENABLE_SSL=False
SMTP_USERNAME=
SMTP_PASSWORD=
LOG_MOUNT_PATH=f:/docker-mounts/dni/apilogs
LOCAL_WEB_PORT=4200
LOCAL_API_PORT=12341
ERROR_EMAIL_FROM=<REDACTED>
ERROR_EMAIL_TO=<REDACTED>
CONTACT_EMAIL_TO=<REDACTED>
- Clone the repository
- Create a
feature/*
branch - Ensure the
.env
file has been created and contains the correct development key / value pairs for all config values - To run the .Net Core Web API in local developer testing mode, run the following scripts (in order) in a Powershell window:
- To host the Angular website, run the following command in your shell of choice:
npm start
- Open the DNI.sln file in Visual Studio to work on the .Net Core WebAPI solution. You can attach to the
dotnet
process to perform line by line debugging. - Open the src/DNI.Web folder in your text editor of choice to work on the Angular front-end application. I use Visual Studio Code and Notepad++.
- Push code to your feature/* branch
- Wait for the CI GitHub Action to complete.
The production build and docker image packages are compiled with this GitHub Action. Deployment of these packages is performed manually±, but has been scripted in deploy.sh.
± Deployment is manual because installing a GitHub Actions Runner on a production server for a public GitHub repo is a security risk. See here for further information.
It is recommended that you create a new user on your production server and add it to the sudo group, rather than run these commands as root.
To deploy this website, considering you want to deploy version 2.0.4
:
- Commit your changes to a
feature/*
branch - Run the
version.ps1 2.0.4
in powershell - Commit the various version file changes
- Create a PR into
master
- Wait for all CI / PR actions to complete
- Merge the PR into master
- Tag the changes with the version
git tag 2.0.4
- Push the tags with
git push --tags
- Wait for the CD action to complete
On the deployment target (server):
chmod +x deploy.sh
- Ensure the
.env
file has been created and contains the correct production key / value pairs for all config values - Ensure the
docker-username
anddocker-password
files has been created and contain valid values - Execute the script targeting the tag to deploy:
./deploy.sh 2.0.0
This project contains a public facing website, and as such uses Angular Universal Server Side Rendering. The following commands can be run inside the src/DNI.Web folder to build and serve the Universal website via Node.js and Express:
npm run build:ssr-prod
npm run serve:ssr-prod
npm run build:ssr-dev
npm run serve:ssr-dev
This Dockerfile contains all steps needed to build and compile the Angular Universal app for production.
A Powershell script has been provided that iterates through all files that need to be changed when a new version is released. The API, .Net Core assemblies and Angular website are versioned together.
This project uses GitFlow for branching and https://semver.org/ for versioning.
For example, to update the app to version 3.4.5, run the following commands on a clean commit
./version.ps1 3 4 5
git commit -am "Version 3.4.5"
git push
git tag 3.4.5
git push --tags
Only once the repository is tagged can it be deployed using the deploy.sh script.
At the time of writing, the following SDK / tool versions are in use:
- Node.js LTS 12.16.1
- Angular CLI 8.3.25
- Dotnet Core SDK 3.1.201
- Docker 19.03.8, build afacb8b (Windows)
- Docker-Compose 1.25.4, build 8d51620a (Windows)
- Visual Studio Professional 2019 (16.4.5)
- VSCode 1.45.0