Projekt

Allgemein

Profil

Setup erpnext14 dockerized » Historie » Version 26

Jeremias Keihsler, 22.03.2024 11:46

1 1 Jeremias Keihsler
h1. Setup erpnext14 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:v14.44.0)
8
9
https://github.com/frappe/frappe_docker/blob/0333e62884b706d01d38804472f71b3f6a039ff6/pwd.yml
10
11 17 Jeremias Keihsler
save in @/opt/docker.compose/erpnext@ as @docker-compose.yml@
12 3 Jeremias Keihsler
13 4 Jeremias Keihsler
<pre><code class="yaml">
14 3 Jeremias Keihsler
version: "3"
15
16
services:
17
  backend:
18
    image: frappe/erpnext:v14.44.0
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:v14.44.0
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:v14.44.0
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:v14.44.0
107
    deploy:
108
      restart_policy:
109
        condition: on-failure
110
    command:
111
      - nginx-entrypoint.sh
112
    environment:
113
      BACKEND: backend:8000
114 6 Jeremias Keihsler
      FRAPPE_SITE_NAME_HEADER: erpnext
115 3 Jeremias Keihsler
      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 7 Jeremias Keihsler
      - "80:8080"
126 3 Jeremias Keihsler
127
  queue-default:
128
    image: frappe/erpnext:v14.44.0
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:v14.44.0
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:v14.44.0
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:v14.44.0
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:v14.44.0
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 4 Jeremias Keihsler
</code></pre>
225 3 Jeremias Keihsler
226 25 Jeremias Keihsler
h2. usage of mounts instead of docker-volumes
227 1 Jeremias Keihsler
228 25 Jeremias Keihsler
didn't work for me .. mariadb yes, but erpnext no
229
230
h3. create directory structure
231
232 18 Jeremias Keihsler
<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 19 Jeremias Keihsler
chmod -R g+w /opt/docker.compose/erpnext/c_*
235
chmod -R o+w /opt/docker.compose/erpnext/c_*
236 18 Jeremias Keihsler
</code></pre>
237
238 20 Jeremias Keihsler
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 1 Jeremias Keihsler
</code></pre>
245 25 Jeremias Keihsler
246
as a consequence stuck with volumes. Although they can be easily accessed from within the host.
247
248
h2. docker compose cheats
249 20 Jeremias Keihsler
250 2 Jeremias Keihsler
<pre><code class="shell">
251 5 Jeremias Keihsler
sudo docker compose up -d
252
sudo docker compose logs
253
sudo docker compose  down
254
sudo docker ps
255
sudo docker exec -it b84444ac0cdb /bin/bash
256
</code></pre>
257
258
or more generic ...
259
260
<pre><code class="shell">
261 1 Jeremias Keihsler
sudo docker compose -p pwd -f pwd.yml up -d
262
sudo docker compose -p pwd -f pwd.yml logs
263
sudo docker compose -p pwd -f pwd.yml down
264
sudo docker ps
265
sudo docker exec -it b84444ac0cdb /bin/bash
266 2 Jeremias Keihsler
</code></pre>
267
268
h3. reset everything in the docker instance
269
270
<pre><code class="shell">
271 14 Jeremias Keihsler
sudo docker compose down
272 15 Jeremias Keihsler
sudo docker rm -f $(sudo docker ps -a -q)
273
sudo docker volume rm $(sudo docker volume ls -q)
274 14 Jeremias Keihsler
sudo docker compose up -d
275 2 Jeremias Keihsler
</code></pre>
276 8 Jeremias Keihsler
277 9 Jeremias Keihsler
h2. migrate erpnext from different server
278
279
https://discuss.frappe.io/t/moving-to-docker/80457/4
280
281 26 Jeremias Keihsler
    Take @bench --site {site-name} backup --with-files@ on the running setup.
282
    Copy files from @sites/{site-name}/private/backups@ to new server and optionally stop old server so users don’t create new data.
283 1 Jeremias Keihsler
    In case of container setup copy files from server into container using docker cp or placing files in volume location.
284 9 Jeremias Keihsler
    If existing site matches new site ... drop site first (https://frappeframework.com/docs/user/en/bench/reference/drop-site)
285 26 Jeremias Keihsler
      @bench drop-site erpnext --db-root-password admin@
286
    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)
287
      @bench new-site erpnext --no-mariadb-socket --verbose --db-root-password admin@
288 22 Jeremias Keihsler
    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.
289 26 Jeremias Keihsler
290
<pre><code class="shell">
291
sudo docker exec -it erpnext-db-1 /bin/bash
292
mysql -p
293
  show database;
294
  drop database _76e6a5f706540e85;
295
  create database _76e6a5f706540e85;
296
</code></pre>
297
298
    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
299
    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'
300 10 Jeremias Keihsler
301
and don't forget ..
302
303
<pre><code class="shell">
304
bench --site erpnext migrate
305
</code></pre>
306
307 23 Jeremias Keihsler
copy the tar-ed files into the corresponding directories
308
309 8 Jeremias Keihsler
h2. erpnext as a service
310
311
https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up
312
313
<pre>
314 12 Jeremias Keihsler
# /etc/systemd/system/docker-compose-erpnext.service 
315
316 8 Jeremias Keihsler
[Unit]
317 11 Jeremias Keihsler
Description=Docker Compose Application Service (erpnext)
318 8 Jeremias Keihsler
Requires=docker.service
319
After=docker.service
320 1 Jeremias Keihsler
321
[Service]
322
Type=oneshot
323 8 Jeremias Keihsler
RemainAfterExit=yes
324 16 Jeremias Keihsler
WorkingDirectory=/opt/docker.compose/erpnext
325 11 Jeremias Keihsler
ExecStart=/usr/bin/docker compose up -d
326
ExecStop=/usr/bin/docker compose down
327 8 Jeremias Keihsler
TimeoutStartSec=0
328
329
[Install]
330
WantedBy=multi-user.target
331 11 Jeremias Keihsler
332 8 Jeremias Keihsler
</pre>
333
334
<pre><code class="shell">
335
systemctl enable docker-compose-app
336
</code></pre>