This project is to help entrepenure women to sell their products online.
/c/Projects/Womix/client
npm i --legacy-peer-deps
For this you need mkcert installed
Installation guideline here --> link
This one is to install a certificate for your PC, this is a one-time use command.
/c/Projects/Womix/client/ssl
mkcert -install
Each time you clone the repository, or each time you create a branch, the local certificate needs to be installed in order to develop the Angular client application over https.
/c/Projects/Womix/client/ssl
mkcert localhost
This will build the built angular client application inside API/wwwroot.
These files are used once the API project is in production mode, but it is required for development.
/c/Projects/Womix/client
ng build
/c/Projects/Womix/client
ng serve
or
ng s
Do this until all packages are installed.
/c/Projects/Womix
dotnet restore
Delete the following files if they exist.
This runs the migration with the latest database scheme, and it seeds the information after.
/c/Projects/Womix/API
entities.db
identity.db
/c/Projects/Womix/API
dotnet watch run
/c/Projects/Womix/client
ng help
/c/Projects/Womix/client
ng generate help
or
ng g help
/c/Projects/Womix
dotnet ef migrations add InitialCreate -p Infrastructure -s API -c DataContext -o Data/Migrations
To run angular in another port ng s --port 4201
Change it to 1mb for maximumWarning and 2mb for maximumError.
{
"projects": {
"client": {
"architect": {
"build": {
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "1mb",
"maximumError": "2mb"
/c/Projects/Womix/client
ng build
public class FallbackController : Controller
{
public IActionResult Index()
{
return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html"), "text/HTML");
}
}
app.MapControllers();
app.MapFallbackToController("Index", "Fallback");
/c/Projects/Womix
docker run --name postgres -e POSTGRES_PASSWORD=postgrespw -p 5432:5432 -d postgres:latest
Name: PostgreSQL Developer: Chris Kolkman
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
</ItemGroup>
</Project>
/c/Projects/Womix/API
dotnet ef database drop
{
...
"ConnectionStrings": {
"DefaultConnection": "Data source=womix.db"
}
...
}
{
...
"ConnectionStrings": {
"DefaultConnection": "Server=localhost; Port=5432; User Id=postgres; Password=postgrespw; Database=womix;"
}
...
}
services.AddDbContext<DataContext>(opt => {
opt.UseNpgsql(config.GetConnectionString("DefaultConnection"));
});
/c/Projects/Womix
dotnet ef migrations add PostgresInitial -p Infrastructure -s API -c DataContext -o Data/Migrations
- Add Database Connection
- The hostname of the database -->
localhost - The PostgreSQL user to authenticate -->
postgres - The password of the PostgreSQL user -->
postgrespw - The port number to connect to -->
5432 - Use an SSL connection? -->
Standard Connection - Type -->
womix - The display name of the database connection -->
localhost
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /app
# copy .csproj and restore as distinct layers
# COPY *.csproj ./
# RUN dotnet restore
# copy everything else and build
COPY . ./
RUN dotnet publish API -c Release -o out
# build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [ "dotnet", "API.dll" ]
**/bin
**/obj
This step requires a docker hub account.
This builds an image named womix
/c/Projects/Womix
docker build -f API/Dockerfile -t ramirocaste/womix .
--rm --> Removes it from the local containers when it quits from running
-it --> Interactive mode: to see the logs from dotnet
-p --> port
/c/Projects/Womix
docker run --rm -it -p 8080:80 ramirocaste/womix:latest
Running this produces an error.
To fix it paste configuration inside appsettings.json
"ConnectionStrings": {
"DefaultConnection": "Server=host.docker.internal; Port=5432; User Id=postgres; Password=postgrespw; Database=womix;"
},
"Token": {
"Key": "super secret key",
"Issuer": "https://localhost:5001"
},
Rebuild the image.
It should be successfull.
In http://localhost:8080 the application should be running.
This requires to be logged in docker login
/c/Projects/Womix
docker push ramirocaste/womix:latest
powershell -Command "iwr https://fly.io/install.ps1 -useb | iex"
fly auth login
/c/Projects/Womix
fly launch --image ramirocaste/womix:latest
? Choose an app name (leave blank to generate one): womix
? Choose a region for deployment: Guadalajara, Mexico (gdl)
? Would you like to set up a Postgresql database now? Yes
? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
? Would you like to set up an Upstash Redis database now? No
? Would you like to deploy now? No
fly.toml
[env]
ASPNETCORE_URLS="http://+:8080"
CloudinarySettings__CloudName="dmjdskgd4"
CloudinarySettings__ApiKey="318856679489316"
Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /app
EXPOSE 8080 <--
List secrets --> fly secrets list
dotnet tool install --global dotnet-ef
dotnet tool update --global dotnet ef
fly secrets set CloudinarySettings__ApiSecret=VkhhhKr7Ure-pLCmaAS66n-FSu0 fly secrets set TokenKey=estaeslacontraseniamasecretadelmundo
fly deploy
https://fly.io/docs/postgres/connecting/connecting-external/
List PostgreSQL Database Application Public IP Address
fly ips list --app womix-db
Find IPv4 Address
fly ips allocate-v4 --app womix-db
VERSION IP TYPE REGION CREATED AT
v4 137.66.6.188 public global 27s ago
Make a fly.toml file for the DB App
fly config save --app womix-db
Current fly.toml file
# fly.toml file generated for womix on 2023-03-29T21:32:56-06:00
app = "womix"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[build]
image = "ramirocaste/womix:latest"
[env]
ASPNETCORE_URLS="http://+:8080"
CloudinarySettings__CloudName="dmjdskgd4"
CloudinarySettings__ApiKey="318856679489316"
[experimental]
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
docker build -f API/Dockerfile -t ramirocaste/womix .
docker push ramirocaste/womix:latest
docker run --rm -it -p 8080:80 ramirocaste/womix:latest
fly launch --image ramirocaste/womix:latest
fly secrets set CloudinarySettings__ApiSecret=VkhhhKr7Ure-pLCmaAS66n-FSu0
fly secrets set TokenKey=estaeslacontraseniamasecretadelmundo
fly secrets list
fly deploy
DATABASE_URL=postgres://womix:vEAV7yqTEXaJqxL@top2.nearest.of.womix-db.internal:5432/womix?sslmode=disable
git clone https://github.com/celr00/Womix.git
/c/Projects/Womix
dotnet publish -c Release -o publish [app].sln
- -s Startup
- -p Project
- -c Context
/c/Projects/Womix
dotnet ef database drop -s API -p Infrastructure -c DataContext
/c/Projects/Womix
npm install -g @angular/cli
dotnet dev-certs https --trust
/c/Projects/Womix
dotnet publish -c Release -o publish Womix.sln
/c/Projects/Womix
dotnet ef database drop -s API -p Infrastructure -c DataContext
sudo nano docker-compose.yml
services:
redis:
image: redis:latest
ports:
- 6379:6379
command: ["redis-server", "--appendonly", "yes"]
volumes:
- redis-data:/data
redis-commander:
image: rediscommander/redis-commander:latest
environment:
- REDIS_HOSTS=local:redis:6379
- HTTP_USER=root
- HTTP_PASSWORD=secret
ports:
- 8081:8081
depends_on:
- redis
db:
image: postgres
environment:
POSTGRES_PASSWORD: secret
POSTGRES_USER: appuser
ports:
- 5432:5432
volumes:
- postgres-data:/data
volumes:
redis-data:
postgres-data:
sudo apt-get update
sudo apt-get install docker.io
sudo apt install docker-compose
docker-compose up -d
sudo apt update sudo apt install apache2 a2enmod proxy proxy_http proxy_html rewrite systemctl restart apache2 sudo ufw app list sudo ufw allow 'Apache Full' sudo systemctl status apache2
Enable ufw Uncomplicated Firewall
sudo ufw enable
Allow ports
sudo ufw allow 5432/tcp
sudo ufw allow 8081/tcp
List ports allowed
sudo ufw status
Go to the Google Cloud Platform
Search for firewall and go to it
Select on the top the second option (Create Firewall Rule)
Name: allow-postgres
Targets: Specified target tags
Target tags: postgres
Source filter: IPv4 ranges
Source IPv4 ranges: 0.0.0.0/0
Protocols and ports --> Specified protocols and ports
Select TCP
Ports: 5432
Click the CREATE button on the button.
Edit the instance
In Network Tags type postgres and press tab
Click the SAVE button.
Now it is ready for Postgres connection
Browser / Servers
Right click Servers --> Register --> Server...
Name: womix
Host name/address: 34.174.26.63
Port: 5432
Maintenance database: womix
Username: appuser
Kerberos authentication? Off
Password: secret
The connection should be successfull.
Add the rules for redis and redis-commander
sudo ufw allow 6379/tcp
sudo ufw allow 8081/tcp
sudo ufw status
Name: allow-redis
Targets: Specified target tags
Target tags: redis
Source filter: IPv4 ranges
Source IPv4 ranges: 0.0.0.0/0
Protocols and ports --> Specified protocols and ports
Select TCP
Ports: 6379
Name: allow-redis-commander
Targets: Specified target tags
Target tags: redis-commander
Source filter: IPv4 ranges
Source IPv4 ranges: 0.0.0.0/0
Protocols and ports --> Specified protocols and ports
Select TCP
Ports: 8081
Go to the instance and add the rules of redis and redis-commander in the Network tags
Browser: http://womix-online.beta:8081 or http://34.174.26.63:8081
Login with
Username: root
Password: secret
sudo mkdir /var/womix sudo chown -R $USER:$USER /var/womix
sudo nano /etc/apache2/sites-available/womix.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
a2ensite womix
ls /etc/apache2/sites-enabled
a2dissite 000-default
systemctl reload apache2
Install the deploy reloaded extension. Create a settings.json file in the .vscode directory and update the IP address and password for your server:
{
"deploy.reloaded": {
"packages": [
{
"name": "Version 1.0.0",
"description": "Package version 1.0.0",
"files": [
"publish/**"
]
}
],
"targets": [
{
"type": "sftp",
"name": "Linux",
"description": "SFTP folder",
"host": "ipaddress",
"port": 22,
"user": "root",
"password": "your password",
"dir": "/var/womix",
"mappings": {
"publish/**": "/"
}
}
]
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
}
dotnet publish -c Release -o publish Womix.sln
-
Deploy the files by using the command pallette -> deploy reloaded -> deploy package
-
Add an endpoint to stripe for to point to the IP address of the server and select the 2 events we want to listen to: payment_intent.succeeded, payment_intent.payment_failed. Note the web hook secret as we will need this soon.
http://ipaddress/api/payments/webhook
- Back on the linux server create a service config for the kestrel server:
sudo nano /etc/systemd/system/womix-web.service
- Update the configuration for your API keys where it says REPLACEME and then paste the config into the nano editor
[Unit] Description=Kestrel service running on Ubuntu 20.04 [Service] WorkingDirectory=/var/womix ExecStart=/usr/bin/dotnet /var/womix/API.dll Restart=always RestartSec=10 SyslogIdentifier=womix User=www-data Environment=ASPNETCORE_ENVIRONMENT=Production Environment='Token__Key=supersecretunguessablekey' Environment='Token__Issuer=http://34.174.26.63' Environment='ConnectionStrings__DefaultConnection=Server=localhost;Port=5432;User Id=appuser;Password=secret; Database=womix' [Install] WantedBy=multi-user.target
- Install the .Net runtime using the instructions here: https://docs.microsoft.com/en-gb/dotnet/core/install/linux-ubuntu#2004-
# Get Ubuntu version
declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)
# Download Microsoft signing key and repository
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
# Install Microsoft signing key and repository
sudo dpkg -i packages-microsoft-prod.deb
# Clean up
rm packages-microsoft-prod.deb
# Update packages
sudo apt update
apt install dotnet-runtime-7.0
systemctl restart systemd-journald
sudo systemctl start womix-web.service
sudo systemctl status womix-web.service
netstat -ntpl
journalctl -u womix-web.service --since "5 min ago"
#
dotnet publish -c Release -o publish Womix.sln
docker-compose down -v
sudo systemctl stop womix-web.service
(publish)
docker-compose up -d
sudo systemctl restart systemd-journald
sudo systemctl start womix-web.service
netstat -ntpl
journalctl -u womix-web.service --since "5 min ago"
Url
IP Address
34.174.143.105
Server: 34.174.143.105
Port: 22
URL: sftp://root@34.174.143.105/var/womix
Username: root
Password:
SSH Private Key: C:\Projects\Womix\private.ppk
Path: /var/womix
- configure auto upload to server
<IfModule mod_ssl.c>
<VirtualHost *:443 *:5000>
ServerAdmin webmaster@localhost
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000
ServerName womix-beta.online
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass "/ws" "ws://localhost:5000/hubs"
ProxyPassReverse "/ws" "ws://localhost:5000/hubs"
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/womix-beta.online/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/womix-beta.online/privkey.pem
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{REQUEST_URI} ^/hubs [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule /(.*) ws://127.0.1:5000/$1 [P,L]
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:443 *:5000>
ServerAdmin webmaster@localhost
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000
ServerName womix-beta.online
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass "/ws" "ws://localhost:5000/hubs"
ProxyPassReverse "/ws" "ws://localhost:5000/hubs"
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/womix-beta.online/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/womix-beta.online/privkey.pem
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{REQUEST_URI} ^/hubs [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule /(.*) ws://127.0.1:5000/$1 [P,L]
</VirtualHost>
</IfModule>
[Unit]
Description=Kestrel service running on Ubuntu 20.04
[Service]
WorkingDirectory=/var/womix
ExecStart=/usr/bin/dotnet /var/womix/API.dll
Restart=always
RestartSec=10
SyslogIdentifier=womix
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment='Token__Key=supersecretunguessablekey'
Environment='Token__Issuer=https://womix-beta.online'
Environment='ConnectionStrings__DefaultConnection=Server=localhost;Port=5432;User Id=appuser;Password=secret; Database=womix'
[Install]
WantedBy=multi-user.target