Projekt

Allgemein

Profil

Setup erpnext14 dockerized » Historie » Version 12

Jeremias Keihsler, 20.03.2024 10:59

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 3 Jeremias Keihsler
save in @/home/user/erpnext@ as @docker-compose.yml@
12
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 2 Jeremias Keihsler
<pre><code class="shell">
227 5 Jeremias Keihsler
sudo docker compose up -d
228
sudo docker compose logs
229
sudo docker compose  down
230
sudo docker ps
231
sudo docker exec -it b84444ac0cdb /bin/bash
232
</code></pre>
233
234
or more generic ...
235
236
<pre><code class="shell">
237 1 Jeremias Keihsler
sudo docker compose -p pwd -f pwd.yml up -d
238
sudo docker compose -p pwd -f pwd.yml logs
239
sudo docker compose -p pwd -f pwd.yml down
240
sudo docker ps
241
sudo docker exec -it b84444ac0cdb /bin/bash
242 2 Jeremias Keihsler
</code></pre>
243
244
h3. reset everything in the docker instance
245
246
<pre><code class="shell">
247
docker-compose down
248
docker rm -f $(docker ps -a -q)
249
docker volume rm $(docker volume ls -q)
250
docker-compose up -d
251
</code></pre>
252 8 Jeremias Keihsler
253 9 Jeremias Keihsler
h2. migrate erpnext from different server
254
255
https://discuss.frappe.io/t/moving-to-docker/80457/4
256
257
<pre>
258
Moving a site.
259
260
    Take bench --site {site-name} backup --with-files on the running setup.
261
    Copy files from sites/{site-name}/private/backups to new server and optionally stop old server so users don’t create new data.
262
    In case of container setup copy files from server into container using docker cp or placing files in volume location.
263
    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)
264
    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.
265
    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
266
    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)
267 1 Jeremias Keihsler
</pre>
268 10 Jeremias Keihsler
269
and don't forget ..
270
271
<pre><code class="shell">
272
bench --site erpnext migrate
273
</code></pre>
274
275 8 Jeremias Keihsler
h2. erpnext as a service
276
277
https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up
278
279
<pre>
280 12 Jeremias Keihsler
# /etc/systemd/system/docker-compose-erpnext.service 
281
282 8 Jeremias Keihsler
[Unit]
283 11 Jeremias Keihsler
Description=Docker Compose Application Service (erpnext)
284 8 Jeremias Keihsler
Requires=docker.service
285
After=docker.service
286 1 Jeremias Keihsler
287
[Service]
288
Type=oneshot
289 8 Jeremias Keihsler
RemainAfterExit=yes
290 11 Jeremias Keihsler
WorkingDirectory=/home/user/erpnext
291
ExecStart=/usr/bin/docker compose up -d
292
ExecStop=/usr/bin/docker compose down
293 8 Jeremias Keihsler
TimeoutStartSec=0
294
295
[Install]
296
WantedBy=multi-user.target
297 11 Jeremias Keihsler
298 8 Jeremias Keihsler
</pre>
299
300
<pre><code class="shell">
301
systemctl enable docker-compose-app
302
</code></pre>