-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeployToLinuxDocker.txt
212 lines (153 loc) · 5.82 KB
/
DeployToLinuxDocker.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
Deploy to Linux using Docker - for use with .Net 5.0
====================================================
1. Create a new droplet with Digital Ocean using the Docker 19.03.12 on Ubuntu 20.04
IP address: Your IP address
Password for root user: YourPassword
2. Login to the droplet using either the terminal or Powershell:
ssh root@ipaddress
You will be asked for your password. Enter this.
3. Create a new docker-compose file using the following command:
sudo nano docker-compose.yml
4. Copy and paste in the docker-compose configuration:
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
adminer:
image: adminer
restart: always
ports:
- 8080:8080
volumes:
redis-data:
5. Run the following command to start the docker services
docker-compose up -d
6. Install and configure apache by running the following commands:
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
7. Optional - allow the ports through the firewall to allow you to manage PostGreSQL and Redis via the ports.
sudo ufw allow 8080/tcp
sudo ufw allow 8081/tcp
8. Test you can access the default apache page by browsing to: http://ipaddress
9. Create a new directory that will contain our published dotnet app and assign rights to the user:
sudo mkdir /var/skinet
sudo chown -R $USER:$USER /var/skinet
10. Create a new config file for the skinet app:
sudo nano /etc/apache2/sites-available/skinet.conf
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>
12. Enable the skinet site by running the following commands:
a2ensite skinet
ls /etc/apache2/sites-enabled
a2dissite 000-default
systemctl reload apache2
13. 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/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:
dotnet publish -c Release -o publish skinet.sln
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:
sudo nano /etc/systemd/system/skinet-web.service
19. 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/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://REPLACEME'
Environment='StripeSettings__PublishibleKey=REPLACEME'
Environment='StripeSettings__SecretKey=REPLACEME'
Environment='StripeSettings__WhSecret=REPLACEME'
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://ipaddress/Content/'
[Install]
WantedBy=multi-user.target
20. Install the .Net runtime using the instructions here: https://docs.microsoft.com/en-gb/dotnet/core/install/linux-ubuntu#2004-
21. Restart the journal service by running the following command:
systemctl restart systemd-journald
22. Start the kestrel service by running the following command:
sudo systemctl start skinet-web.service
23. Check it is started by running:
netstat -ntpl
24. Check the journal by running:
journalctl -u skinet-web.service --since "5 min ago"
25. Make sure there are no errors and then test you can browse to the published app on http://ipaddress