Projekt

Allgemein

Profil

Setup erpnext14 dockerized » Historie » Version 22

Jeremias Keihsler, 20.03.2024 15:05

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 18 Jeremias Keihsler
create directory structure
227
228
<pre><code class="shell">
229
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}
230 19 Jeremias Keihsler
chmod -R g+w /opt/docker.compose/erpnext/c_*
231
chmod -R o+w /opt/docker.compose/erpnext/c_*
232 18 Jeremias Keihsler
</code></pre>
233
234 20 Jeremias Keihsler
fix permission issue within volume
235
236
<pre><code class="shell">
237
sudo docker exec --user root -it erpnext-backend-1 /bin/bash
238
chown -R frappe:frappe logs
239
chown -R frappe:frappe sites
240
</code></pre>
241
242 2 Jeremias Keihsler
<pre><code class="shell">
243 5 Jeremias Keihsler
sudo docker compose up -d
244
sudo docker compose logs
245
sudo docker compose  down
246
sudo docker ps
247
sudo docker exec -it b84444ac0cdb /bin/bash
248
</code></pre>
249
250
or more generic ...
251
252
<pre><code class="shell">
253 1 Jeremias Keihsler
sudo docker compose -p pwd -f pwd.yml up -d
254
sudo docker compose -p pwd -f pwd.yml logs
255
sudo docker compose -p pwd -f pwd.yml down
256
sudo docker ps
257
sudo docker exec -it b84444ac0cdb /bin/bash
258 2 Jeremias Keihsler
</code></pre>
259
260
h3. reset everything in the docker instance
261
262
<pre><code class="shell">
263 14 Jeremias Keihsler
sudo docker compose down
264 15 Jeremias Keihsler
sudo docker rm -f $(sudo docker ps -a -q)
265
sudo docker volume rm $(sudo docker volume ls -q)
266 14 Jeremias Keihsler
sudo docker compose up -d
267 2 Jeremias Keihsler
</code></pre>
268 8 Jeremias Keihsler
269 9 Jeremias Keihsler
h2. migrate erpnext from different server
270
271
https://discuss.frappe.io/t/moving-to-docker/80457/4
272
273
<pre>
274
Moving a site.
275
276
    Take bench --site {site-name} backup --with-files on the running setup.
277
    Copy files from sites/{site-name}/private/backups to new server and optionally stop old server so users don’t create new data.
278
    In case of container setup copy files from server into container using docker cp or placing files in volume location.
279 21 Jeremias Keihsler
    If existing site matches new site ... drop site first (https://frappeframework.com/docs/user/en/bench/reference/drop-site)
280 22 Jeremias Keihsler
      bench drop-site erpnext --db-root-password admin
281 9 Jeremias Keihsler
    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)
282 22 Jeremias Keihsler
      bench new-site erpnext --no-mariadb-socket --verbose --db-root-password admin
283 9 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.
284 22 Jeremias Keihsler
      sudo docker exec -it erpnext-db-1 /bin/bash
285
      mysql -p
286
      show database;
287
      drop database _76e6a5f706540e85;
288
      create database _76e6a5f706540e85;
289 9 Jeremias Keihsler
    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
290
    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)
291 1 Jeremias Keihsler
</pre>
292 10 Jeremias Keihsler
293
and don't forget ..
294
295
<pre><code class="shell">
296
bench --site erpnext migrate
297
</code></pre>
298
299 8 Jeremias Keihsler
h2. erpnext as a service
300
301
https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up
302
303
<pre>
304 12 Jeremias Keihsler
# /etc/systemd/system/docker-compose-erpnext.service 
305
306 8 Jeremias Keihsler
[Unit]
307 11 Jeremias Keihsler
Description=Docker Compose Application Service (erpnext)
308 8 Jeremias Keihsler
Requires=docker.service
309
After=docker.service
310 1 Jeremias Keihsler
311
[Service]
312
Type=oneshot
313 8 Jeremias Keihsler
RemainAfterExit=yes
314 16 Jeremias Keihsler
WorkingDirectory=/opt/docker.compose/erpnext
315 11 Jeremias Keihsler
ExecStart=/usr/bin/docker compose up -d
316
ExecStop=/usr/bin/docker compose down
317 8 Jeremias Keihsler
TimeoutStartSec=0
318
319
[Install]
320
WantedBy=multi-user.target
321 11 Jeremias Keihsler
322 8 Jeremias Keihsler
</pre>
323
324
<pre><code class="shell">
325
systemctl enable docker-compose-app
326
</code></pre>