Projekt

Allgemein

Profil

Setup erpnext15 dockerized » Historie » Version 1

Jeremias Keihsler, 12.12.2024 09:48

1 1 Jeremias Keihsler
h1. Setup erpnext15 dockerized 
2
3
the basic idea is taken from https://www.youtube.com/watch?v=8Q5B7DnxmLg
4
5
use of docker compose v2
6
7
h2. download pwd.yml (version erpnext:v15.45.4)
8
9
https://github.com/frappe/frappe_docker/blob/0333e62884b706d01d38804472f71b3f6a039ff6/pwd.yml
10
11
save in @/opt/docker.compose/erpnext@ as @docker-compose.yml@
12
13
<pre><code class="yaml">
14
version: "3"
15
16
services:
17
  backend:
18
    image: frappe/erpnext:v15.45.4
19
    deploy:
20
      restart_policy:
21
        condition: on-failure
22
    volumes:
23
      - sites:/home/frappe/frappe-bench/sites
24
      - logs:/home/frappe/frappe-bench/logs
25
26
  configurator:
27
    image: frappe/erpnext:v15.45.4
28
    deploy:
29
      restart_policy:
30
        condition: none
31
    entrypoint:
32
      - bash
33
      - -c
34
    command:
35
      - >
36
        ls -1 apps > sites/apps.txt;
37
        bench set-config -g db_host $$DB_HOST;
38
        bench set-config -gp db_port $$DB_PORT;
39
        bench set-config -g redis_cache "redis://$$REDIS_CACHE";
40
        bench set-config -g redis_queue "redis://$$REDIS_QUEUE";
41
        bench set-config -g redis_socketio "redis://$$REDIS_SOCKETIO";
42
        bench set-config -gp socketio_port $$SOCKETIO_PORT;
43
    environment:
44
      DB_HOST: db
45
      DB_PORT: "3306"
46
      REDIS_CACHE: redis-cache:6379
47
      REDIS_QUEUE: redis-queue:6379
48
      REDIS_SOCKETIO: redis-socketio:6379
49
      SOCKETIO_PORT: "9000"
50
    volumes:
51
      - sites:/home/frappe/frappe-bench/sites
52
      - logs:/home/frappe/frappe-bench/logs
53
54
  create-site:
55
    image: frappe/erpnext:v15.45.4
56
    deploy:
57
      restart_policy:
58
        condition: none
59
    volumes:
60
      - sites:/home/frappe/frappe-bench/sites
61
      - logs:/home/frappe/frappe-bench/logs
62
    entrypoint:
63
      - bash
64
      - -c
65
    command:
66
      - >
67
        wait-for-it -t 120 db:3306;
68
        wait-for-it -t 120 redis-cache:6379;
69
        wait-for-it -t 120 redis-queue:6379;
70
        wait-for-it -t 120 redis-socketio:6379;
71
        export start=`date +%s`;
72
        until [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".db_host // empty"` ]] && \
73
          [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_cache // empty"` ]] && \
74
          [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_queue // empty"` ]];
75
        do
76
          echo "Waiting for sites/common_site_config.json to be created";
77
          sleep 5;
78
          if (( `date +%s`-start > 120 )); then
79
            echo "could not find sites/common_site_config.json with required keys";
80
            exit 1
81
          fi
82
        done;
83
        echo "sites/common_site_config.json found";
84
        bench new-site erpnext --no-mariadb-socket --admin-password=admin --db-root-password=admin --install-app erpnext --set-default;
85
86
  db:
87
    image: mariadb:10.6
88
    healthcheck:
89
      test: mysqladmin ping -h localhost --password=admin
90
      interval: 1s
91
      retries: 15
92
    deploy:
93
      restart_policy:
94
        condition: on-failure
95
    command:
96
      - --character-set-server=utf8mb4
97
      - --collation-server=utf8mb4_unicode_ci
98
      - --skip-character-set-client-handshake
99
      - --skip-innodb-read-only-compressed # Temporary fix for MariaDB 10.6
100
    environment:
101
      MYSQL_ROOT_PASSWORD: admin
102
    volumes:
103
      - db-data:/var/lib/mysql
104
105
  frontend:
106
    image: frappe/erpnext:v15.45.4
107
    deploy:
108
      restart_policy:
109
        condition: on-failure
110
    command:
111
      - nginx-entrypoint.sh
112
    environment:
113
      BACKEND: backend:8000
114
      FRAPPE_SITE_NAME_HEADER: erpnext
115
      SOCKETIO: websocket:9000
116
      UPSTREAM_REAL_IP_ADDRESS: 127.0.0.1
117
      UPSTREAM_REAL_IP_HEADER: X-Forwarded-For
118
      UPSTREAM_REAL_IP_RECURSIVE: "off"
119
      PROXY_READ_TIMEOUT: 120
120
      CLIENT_MAX_BODY_SIZE: 50m
121
    volumes:
122
      - sites:/home/frappe/frappe-bench/sites
123
      - logs:/home/frappe/frappe-bench/logs
124
    ports:
125
      - "80:8080"
126
127
  queue-default:
128
    image: frappe/erpnext:v15.45.4
129
    deploy:
130
      restart_policy:
131
        condition: on-failure
132
    command:
133
      - bench
134
      - worker
135
      - --queue
136
      - default
137
    volumes:
138
      - sites:/home/frappe/frappe-bench/sites
139
      - logs:/home/frappe/frappe-bench/logs
140
141
  queue-long:
142
    image: frappe/erpnext:v15.45.4
143
    deploy:
144
      restart_policy:
145
        condition: on-failure
146
    command:
147
      - bench
148
      - worker
149
      - --queue
150
      - long
151
    volumes:
152
      - sites:/home/frappe/frappe-bench/sites
153
      - logs:/home/frappe/frappe-bench/logs
154
155
  queue-short:
156
    image: frappe/erpnext:v15.45.4
157
    deploy:
158
      restart_policy:
159
        condition: on-failure
160
    command:
161
      - bench
162
      - worker
163
      - --queue
164
      - short
165
    volumes:
166
      - sites:/home/frappe/frappe-bench/sites
167
      - logs:/home/frappe/frappe-bench/logs
168
169
  redis-queue:
170
    image: redis:6.2-alpine
171
    deploy:
172
      restart_policy:
173
        condition: on-failure
174
    volumes:
175
      - redis-queue-data:/data
176
177
  redis-cache:
178
    image: redis:6.2-alpine
179
    deploy:
180
      restart_policy:
181
        condition: on-failure
182
    volumes:
183
      - redis-cache-data:/data
184
185
  redis-socketio:
186
    image: redis:6.2-alpine
187
    deploy:
188
      restart_policy:
189
        condition: on-failure
190
    volumes:
191
      - redis-socketio-data:/data
192
193
  scheduler:
194
    image: frappe/erpnext:v15.45.4
195
    deploy:
196
      restart_policy:
197
        condition: on-failure
198
    command:
199
      - bench
200
      - schedule
201
    volumes:
202
      - sites:/home/frappe/frappe-bench/sites
203
      - logs:/home/frappe/frappe-bench/logs
204
205
  websocket:
206
    image: frappe/erpnext:v15.45.4
207
    deploy:
208
      restart_policy:
209
        condition: on-failure
210
    command:
211
      - node
212
      - /home/frappe/frappe-bench/apps/frappe/socketio.js
213
    volumes:
214
      - sites:/home/frappe/frappe-bench/sites
215
      - logs:/home/frappe/frappe-bench/logs
216
217
volumes:
218
  db-data:
219
  redis-queue-data:
220
  redis-cache-data:
221
  redis-socketio-data:
222
  sites:
223
  logs:
224
</code></pre>
225
226
h2. usage of mounts instead of docker-volumes
227
228
didn't work for me .. mariadb yes, but erpnext no
229
230
h3. create directory structure
231
232
<pre><code class="shell">
233
mkdir -p /opt/docker.compose/erpnext/{c_db/var/lib/mysql,c_erp/home/frappe/frappe-bench/sites,c_erp/home/frappe/frappe-bench/logs,c_redis_cache/data,c_redis_queue/data,c_redis_socketio/data}
234
chmod -R g+w /opt/docker.compose/erpnext/c_*
235
chmod -R o+w /opt/docker.compose/erpnext/c_*
236
</code></pre>
237
238
fix permission issue within volume
239
240
<pre><code class="shell">
241
sudo docker exec --user root -it erpnext-backend-1 /bin/bash
242
chown -R frappe:frappe logs
243
chown -R frappe:frappe sites
244
</code></pre>
245
246
as a consequence stuck with volumes. Although they can be easily accessed from within the host.
247
248
h2. migrate erpnext from different server
249
250
https://discuss.frappe.io/t/moving-to-docker/80457/4
251
252
Take @bench --site {site-name} backup --with-files@ on the running setup.
253
Copy files from @sites/{site-name}/private/backups@ to new server and optionally stop old server so users don’t create new data.
254
In case of container setup copy files from server into container using docker cp or placing files in volume location.
255
If existing site matches new site ... drop site first (https://frappeframework.com/docs/user/en/bench/reference/drop-site)
256
@bench drop-site erpnext --db-root-password admin@
257
Enter any worker container and create site using @bench new-site --no-mariadb-socket@ command. Name the site as per configured domain name. (Note down the db_name from site_config.json created)
258
@bench new-site erpnext --no-mariadb-socket --verbose --db-root-password admin@
259
Enter mariadb container / use mysql client and execute drop database {db_name}; create database {db_name}. This will clean the site db that was created by new site. We do this so that we have a running site configured without any database resulting in Internal Server Error.
260
261
<pre><code class="shell">
262
sudo docker exec -it erpnext-db-1 /bin/bash
263
mysql -p
264
  show database;
265
  drop database _76e6a5f706540e85;
266
  create database _76e6a5f706540e85;
267
</code></pre>
268
269
    In mysql shell execute, @use {db_name}; source /path/to/database.sql@. This will restore the database from backup on fresh db. We use source from mysql shell as it re-connects in case of disconnection or timeout during restoration of huge database. Simple alternate command will be mysql -uroot -p{root-password} -h{hostname} {db_name} < /path/to/database.sql
270
    Copy additional keys and encryption_key from backed up site_config.json. (Note, DO NOT change the db_name, db_password keys from newly created site, only copy other keys from backup site_config) The keys are important for the email-service, the hostname is important to 'wkhtmltopdf'
271
272
and don't forget ..
273
274
<pre><code class="shell">
275
bench --site erpnext migrate
276
</code></pre>
277
278
copy the tar-ed files into the corresponding directories
279
280
h2. erpnext as a service
281
282
https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up
283
284
<pre>
285
# /etc/systemd/system/docker-compose-erpnext.service 
286
287
[Unit]
288
Description=Docker Compose Application Service (erpnext)
289
Requires=docker.service
290
After=docker.service
291
292
[Service]
293
Type=oneshot
294
RemainAfterExit=yes
295
WorkingDirectory=/opt/docker.compose/erpnext
296
ExecStart=/usr/bin/docker compose up -d
297
ExecStop=/usr/bin/docker compose down
298
TimeoutStartSec=0
299
300
[Install]
301
WantedBy=multi-user.target
302
</pre>
303
304
<pre><code class="shell">
305
systemctl enable docker-compose-app
306
</code></pre>
307
308
h2. backup erpnext from outside a container
309
310
<pre><code class="shell">
311
sudo docker exec -t erpnext-backend-1 /usr/local/bin/bench --site all backup --with-files
312
</code></pre>
313
314
h1. upgrade erpnext v15
315
316
h2. shutdown erpnext
317
318
<pre><code class="shell">
319
sudo systemctl stop docker-compose-erpnext
320
</code></pre>
321
322
h2. modify compose-file
323
324
<pre><code class="shell">
325
sudo vim /opt/docker.compose/erpnext/docker-compose.yml
326
</code></pre>
327
328
replace all @frappe/erpnext:v15.20.6@ with the version desired (e.g. @v15.21.0@)
329
330
check whether mariadb-version or redis-version should be changed as well. (e.g. @mariadb 10.6@ / @redis-6.2@)
331
332
h2. restart erpnext manually
333
334
<pre><code class="shell">
335
cd /opt/docker.compose/erpnext/
336
sudo docker compose up
337
</code></pre>
338
339
h2. migrate erpnext installation (from within any erpnext-container)
340
341
<pre><code class="shell">
342
sudo docker ps
343
sudo docker exec -it b84444ac0cdb /bin/bash
344
bench --site erpnext migrate
345
</code></pre>
346
347
h2. stop manually started instance and restart service
348
349
<pre><code class="shell">
350
CTRL-C
351
sudo systemctl start docker-compose-erpnext
352
</code></pre>
353
354
h2. tidy up ..
355
356
<pre><code class="shell">
357
sudo docker system prune
358
</code></pre>