Deploy To Linux Docker
Deploy To Linux Docker
0
====================================================
1. Create a new droplet with Digital Ocean using the Docker 20.x.x image on Ubuntu
20.04
ssh root@ipaddress
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
restart: always
environment:
POSTGRES_PASSWORD: secret
POSTGRES_USER: appuser
ports:
- 5432:5432
volumes:
- postgres-data:/data
volumes:
redis-data:
postgres-data:
docker-compose up -d
*** Note: if you get a warning telling you that docker-compose is unavailable then
just use:
apt install docker-compose
7. Optional - allow the ports through the firewall to allow you to manage
PostGreSQL and Redis via the ports.
8. Test you can access the default apache page by browsing to:
http://104.248.154.184
9. Create a new directory that will contain our published dotnet app and assign
rights to the user:
11. Paste in the following configuration which will set up a reverse proxy with
the Kestrel server:
<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 skinet
ls /etc/apache2/sites-enabled
a2dissite 000-default
systemctl reload apache2
{
"deploy.reloaded": {
"packages": [
{
"name": "Version 1.0.0",
"description": "Package version 1.0.0",
"files": [
"publish/**"
]
}
],
"targets": [
{
"type": "sftp",
"name": "Linux",
"description": "SFTP folder",
"dir": "/var/skinet",
"mappings": {
"publish/**": "/"
}
}
]
}
}
14. Optional - Change the logging level for the appsettings.json to information
for the Microsoft logging level:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
}
15. Republish the app with changes by running the following command in VS Code
terminal:
16. Deploy the files by using the command pallette -> deploy reloaded -> deploy
package
17. 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
18. Back on the linux server create a service config for the kestrel server:
[Unit]
Description=Kestrel service running on Ubuntu 20.04
[Service]
WorkingDirectory=/var/skinet
ExecStart=/usr/bin/dotnet /var/skinet/API.dll
Restart=always
RestartSec=10
SyslogIdentifier=skinet
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment='Token__Key=CHANGE ME TO SOMETHING SECURE'
Environment='Token__Issuer=http://REPLACE_ME'
Environment='StripeSettings__PublishibleKey=REPLACE_ME'
Environment='StripeSettings__SecretKey=REPLACE_ME'
Environment='StripeSettings__WhSecret=REPLACE_ME'
Environment='ConnectionStrings__DefaultConnection=Server=localhost;Port=5432;User
Id=appuser;Password=secret; Database=skinet'
Environment='ConnectionStrings__IdentityConnection=Server=localhost;Port=5432;User
Id=appuser;Password=secret; Database=identity'
Environment='ConnectionStrings__Redis=localhost'
Environment='ApiUrl=http://REPLACE_ME/Content/'
[Install]
WantedBy=multi-user.target
netstat -ntpl
25. Make sure there are no errors and then test you can browse to the published
app on http://ipaddress