Setup erpnext15 dockerized » Historie » Version 6
Jeremias Keihsler, 12.12.2024 10:33
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 | services: |
||
15 | backend: |
||
16 | image: frappe/erpnext:v15.45.4 |
||
17 | 2 | Jeremias Keihsler | networks: |
18 | - frappe_network |
||
19 | 1 | Jeremias Keihsler | 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 | 2 | Jeremias Keihsler | environment: |
26 | DB_HOST: db |
||
27 | DB_PORT: "3306" |
||
28 | MYSQL_ROOT_PASSWORD: admin |
||
29 | MARIADB_ROOT_PASSWORD: admin |
||
30 | 1 | Jeremias Keihsler | |
31 | configurator: |
||
32 | image: frappe/erpnext:v15.45.4 |
||
33 | 2 | Jeremias Keihsler | networks: |
34 | - frappe_network |
||
35 | 1 | Jeremias Keihsler | deploy: |
36 | restart_policy: |
||
37 | condition: none |
||
38 | entrypoint: |
||
39 | - bash |
||
40 | - -c |
||
41 | command: |
||
42 | - > |
||
43 | ls -1 apps > sites/apps.txt; |
||
44 | bench set-config -g db_host $$DB_HOST; |
||
45 | bench set-config -gp db_port $$DB_PORT; |
||
46 | bench set-config -g redis_cache "redis://$$REDIS_CACHE"; |
||
47 | bench set-config -g redis_queue "redis://$$REDIS_QUEUE"; |
||
48 | 2 | Jeremias Keihsler | bench set-config -g redis_socketio "redis://$$REDIS_QUEUE"; |
49 | 1 | Jeremias Keihsler | bench set-config -gp socketio_port $$SOCKETIO_PORT; |
50 | environment: |
||
51 | DB_HOST: db |
||
52 | DB_PORT: "3306" |
||
53 | REDIS_CACHE: redis-cache:6379 |
||
54 | REDIS_QUEUE: redis-queue:6379 |
||
55 | SOCKETIO_PORT: "9000" |
||
56 | volumes: |
||
57 | - sites:/home/frappe/frappe-bench/sites |
||
58 | - logs:/home/frappe/frappe-bench/logs |
||
59 | |||
60 | create-site: |
||
61 | image: frappe/erpnext:v15.45.4 |
||
62 | 2 | Jeremias Keihsler | networks: |
63 | - frappe_network |
||
64 | 1 | Jeremias Keihsler | deploy: |
65 | restart_policy: |
||
66 | condition: none |
||
67 | volumes: |
||
68 | - sites:/home/frappe/frappe-bench/sites |
||
69 | - logs:/home/frappe/frappe-bench/logs |
||
70 | entrypoint: |
||
71 | - bash |
||
72 | - -c |
||
73 | command: |
||
74 | - > |
||
75 | wait-for-it -t 120 db:3306; |
||
76 | wait-for-it -t 120 redis-cache:6379; |
||
77 | wait-for-it -t 120 redis-queue:6379; |
||
78 | export start=`date +%s`; |
||
79 | until [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".db_host // empty"` ]] && \ |
||
80 | [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_cache // empty"` ]] && \ |
||
81 | [[ -n `grep -hs ^ sites/common_site_config.json | jq -r ".redis_queue // empty"` ]]; |
||
82 | do |
||
83 | echo "Waiting for sites/common_site_config.json to be created"; |
||
84 | sleep 5; |
||
85 | if (( `date +%s`-start > 120 )); then |
||
86 | echo "could not find sites/common_site_config.json with required keys"; |
||
87 | exit 1 |
||
88 | fi |
||
89 | done; |
||
90 | echo "sites/common_site_config.json found"; |
||
91 | 2 | Jeremias Keihsler | bench new-site --mariadb-user-host-login-scope='%' --admin-password=admin --db-root-username=root --db-root-password=admin --install-app erpnext --set-default erpnext; |
92 | 1 | Jeremias Keihsler | |
93 | db: |
||
94 | image: mariadb:10.6 |
||
95 | 2 | Jeremias Keihsler | networks: |
96 | - frappe_network |
||
97 | 1 | Jeremias Keihsler | healthcheck: |
98 | test: mysqladmin ping -h localhost --password=admin |
||
99 | interval: 1s |
||
100 | 2 | Jeremias Keihsler | retries: 20 |
101 | 1 | Jeremias Keihsler | deploy: |
102 | restart_policy: |
||
103 | condition: on-failure |
||
104 | command: |
||
105 | - --character-set-server=utf8mb4 |
||
106 | - --collation-server=utf8mb4_unicode_ci |
||
107 | - --skip-character-set-client-handshake |
||
108 | - --skip-innodb-read-only-compressed # Temporary fix for MariaDB 10.6 |
||
109 | environment: |
||
110 | MYSQL_ROOT_PASSWORD: admin |
||
111 | 2 | Jeremias Keihsler | MARIADB_ROOT_PASSWORD: admin |
112 | 1 | Jeremias Keihsler | volumes: |
113 | - db-data:/var/lib/mysql |
||
114 | |||
115 | frontend: |
||
116 | image: frappe/erpnext:v15.45.4 |
||
117 | 2 | Jeremias Keihsler | networks: |
118 | - frappe_network |
||
119 | depends_on: |
||
120 | - websocket |
||
121 | 1 | Jeremias Keihsler | deploy: |
122 | restart_policy: |
||
123 | condition: on-failure |
||
124 | command: |
||
125 | - nginx-entrypoint.sh |
||
126 | environment: |
||
127 | BACKEND: backend:8000 |
||
128 | FRAPPE_SITE_NAME_HEADER: erpnext |
||
129 | SOCKETIO: websocket:9000 |
||
130 | UPSTREAM_REAL_IP_ADDRESS: 127.0.0.1 |
||
131 | UPSTREAM_REAL_IP_HEADER: X-Forwarded-For |
||
132 | UPSTREAM_REAL_IP_RECURSIVE: "off" |
||
133 | PROXY_READ_TIMEOUT: 120 |
||
134 | CLIENT_MAX_BODY_SIZE: 50m |
||
135 | volumes: |
||
136 | - sites:/home/frappe/frappe-bench/sites |
||
137 | - logs:/home/frappe/frappe-bench/logs |
||
138 | ports: |
||
139 | - "80:8080" |
||
140 | |||
141 | queue-long: |
||
142 | image: frappe/erpnext:v15.45.4 |
||
143 | 2 | Jeremias Keihsler | networks: |
144 | - frappe_network |
||
145 | 1 | Jeremias Keihsler | deploy: |
146 | restart_policy: |
||
147 | condition: on-failure |
||
148 | command: |
||
149 | - bench |
||
150 | - worker |
||
151 | - --queue |
||
152 | 2 | Jeremias Keihsler | - long,default,short |
153 | 1 | Jeremias Keihsler | volumes: |
154 | - sites:/home/frappe/frappe-bench/sites |
||
155 | - logs:/home/frappe/frappe-bench/logs |
||
156 | |||
157 | queue-short: |
||
158 | image: frappe/erpnext:v15.45.4 |
||
159 | 2 | Jeremias Keihsler | networks: |
160 | - frappe_network |
||
161 | 1 | Jeremias Keihsler | deploy: |
162 | restart_policy: |
||
163 | condition: on-failure |
||
164 | command: |
||
165 | - bench |
||
166 | - worker |
||
167 | - --queue |
||
168 | 2 | Jeremias Keihsler | - short,default |
169 | 1 | Jeremias Keihsler | volumes: |
170 | - sites:/home/frappe/frappe-bench/sites |
||
171 | - logs:/home/frappe/frappe-bench/logs |
||
172 | |||
173 | redis-queue: |
||
174 | image: redis:6.2-alpine |
||
175 | 2 | Jeremias Keihsler | networks: |
176 | - frappe_network |
||
177 | 1 | Jeremias Keihsler | deploy: |
178 | restart_policy: |
||
179 | condition: on-failure |
||
180 | volumes: |
||
181 | - redis-queue-data:/data |
||
182 | |||
183 | redis-cache: |
||
184 | image: redis:6.2-alpine |
||
185 | 2 | Jeremias Keihsler | networks: |
186 | - frappe_network |
||
187 | 1 | Jeremias Keihsler | deploy: |
188 | restart_policy: |
||
189 | condition: on-failure |
||
190 | volumes: |
||
191 | - redis-cache-data:/data |
||
192 | |||
193 | scheduler: |
||
194 | image: frappe/erpnext:v15.45.4 |
||
195 | 2 | Jeremias Keihsler | networks: |
196 | - frappe_network |
||
197 | 1 | Jeremias Keihsler | deploy: |
198 | restart_policy: |
||
199 | condition: on-failure |
||
200 | command: |
||
201 | - bench |
||
202 | - schedule |
||
203 | volumes: |
||
204 | - sites:/home/frappe/frappe-bench/sites |
||
205 | - logs:/home/frappe/frappe-bench/logs |
||
206 | |||
207 | websocket: |
||
208 | image: frappe/erpnext:v15.45.4 |
||
209 | 2 | Jeremias Keihsler | networks: |
210 | - frappe_network |
||
211 | 1 | Jeremias Keihsler | deploy: |
212 | restart_policy: |
||
213 | condition: on-failure |
||
214 | command: |
||
215 | - node |
||
216 | - /home/frappe/frappe-bench/apps/frappe/socketio.js |
||
217 | volumes: |
||
218 | - sites:/home/frappe/frappe-bench/sites |
||
219 | - logs:/home/frappe/frappe-bench/logs |
||
220 | |||
221 | volumes: |
||
222 | db-data: |
||
223 | redis-queue-data: |
||
224 | redis-cache-data: |
||
225 | sites: |
||
226 | logs: |
||
227 | 2 | Jeremias Keihsler | |
228 | networks: |
||
229 | frappe_network: |
||
230 | driver: bridge |
||
231 | 1 | Jeremias Keihsler | </code></pre> |
232 | |||
233 | h2. usage of mounts instead of docker-volumes |
||
234 | |||
235 | didn't work for me .. mariadb yes, but erpnext no |
||
236 | |||
237 | h3. create directory structure |
||
238 | |||
239 | <pre><code class="shell"> |
||
240 | 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} |
||
241 | chmod -R g+w /opt/docker.compose/erpnext/c_* |
||
242 | chmod -R o+w /opt/docker.compose/erpnext/c_* |
||
243 | </code></pre> |
||
244 | |||
245 | fix permission issue within volume |
||
246 | |||
247 | <pre><code class="shell"> |
||
248 | sudo docker exec --user root -it erpnext-backend-1 /bin/bash |
||
249 | chown -R frappe:frappe logs |
||
250 | chown -R frappe:frappe sites |
||
251 | </code></pre> |
||
252 | |||
253 | as a consequence stuck with volumes. Although they can be easily accessed from within the host. |
||
254 | |||
255 | h2. migrate erpnext from different server |
||
256 | |||
257 | https://discuss.frappe.io/t/moving-to-docker/80457/4 |
||
258 | |||
259 | Take @bench --site {site-name} backup --with-files@ on the running setup. |
||
260 | Copy files from @sites/{site-name}/private/backups@ to new server and optionally stop old server so users don’t create new data. |
||
261 | In case of container setup copy files from server into container using docker cp or placing files in volume location. |
||
262 | If existing site matches new site ... drop site first (https://frappeframework.com/docs/user/en/bench/reference/drop-site) |
||
263 | @bench drop-site erpnext --db-root-password admin@ |
||
264 | 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) |
||
265 | @bench new-site erpnext --no-mariadb-socket --verbose --db-root-password admin@ |
||
266 | 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. |
||
267 | |||
268 | <pre><code class="shell"> |
||
269 | sudo docker exec -it erpnext-db-1 /bin/bash |
||
270 | mysql -p |
||
271 | show database; |
||
272 | drop database _76e6a5f706540e85; |
||
273 | create database _76e6a5f706540e85; |
||
274 | </code></pre> |
||
275 | |||
276 | 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 |
||
277 | 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' |
||
278 | |||
279 | and don't forget .. |
||
280 | |||
281 | <pre><code class="shell"> |
||
282 | bench --site erpnext migrate |
||
283 | </code></pre> |
||
284 | |||
285 | copy the tar-ed files into the corresponding directories |
||
286 | |||
287 | h2. erpnext as a service |
||
288 | |||
289 | https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up |
||
290 | |||
291 | <pre> |
||
292 | # /etc/systemd/system/docker-compose-erpnext.service |
||
293 | |||
294 | [Unit] |
||
295 | Description=Docker Compose Application Service (erpnext) |
||
296 | Requires=docker.service |
||
297 | After=docker.service |
||
298 | |||
299 | [Service] |
||
300 | Type=oneshot |
||
301 | RemainAfterExit=yes |
||
302 | WorkingDirectory=/opt/docker.compose/erpnext |
||
303 | ExecStart=/usr/bin/docker compose up -d |
||
304 | ExecStop=/usr/bin/docker compose down |
||
305 | TimeoutStartSec=0 |
||
306 | |||
307 | [Install] |
||
308 | WantedBy=multi-user.target |
||
309 | </pre> |
||
310 | |||
311 | <pre><code class="shell"> |
||
312 | systemctl enable docker-compose-app |
||
313 | </code></pre> |
||
314 | |||
315 | h2. backup erpnext from outside a container |
||
316 | |||
317 | <pre><code class="shell"> |
||
318 | sudo docker exec -t erpnext-backend-1 /usr/local/bin/bench --site all backup --with-files |
||
319 | </code></pre> |
||
320 | |||
321 | h1. upgrade erpnext v15 |
||
322 | |||
323 | h2. shutdown erpnext |
||
324 | |||
325 | <pre><code class="shell"> |
||
326 | sudo systemctl stop docker-compose-erpnext |
||
327 | </code></pre> |
||
328 | |||
329 | h2. modify compose-file |
||
330 | |||
331 | <pre><code class="shell"> |
||
332 | sudo vim /opt/docker.compose/erpnext/docker-compose.yml |
||
333 | </code></pre> |
||
334 | |||
335 | 3 | Jeremias Keihsler | replace all @frappe/erpnext:v15.45.4@ with the version desired (e.g. @v15.46.0@) |
336 | 1 | Jeremias Keihsler | |
337 | check whether mariadb-version or redis-version should be changed as well. (e.g. @mariadb 10.6@ / @redis-6.2@) |
||
338 | |||
339 | h2. restart erpnext manually |
||
340 | |||
341 | <pre><code class="shell"> |
||
342 | cd /opt/docker.compose/erpnext/ |
||
343 | sudo docker compose up |
||
344 | </code></pre> |
||
345 | |||
346 | h2. migrate erpnext installation (from within any erpnext-container) |
||
347 | |||
348 | <pre><code class="shell"> |
||
349 | sudo docker ps |
||
350 | sudo docker exec -it b84444ac0cdb /bin/bash |
||
351 | bench --site erpnext migrate |
||
352 | </code></pre> |
||
353 | |||
354 | h2. stop manually started instance and restart service |
||
355 | |||
356 | <pre><code class="shell"> |
||
357 | CTRL-C |
||
358 | sudo systemctl start docker-compose-erpnext |
||
359 | </code></pre> |
||
360 | |||
361 | h2. tidy up .. |
||
362 | |||
363 | <pre><code class="shell"> |
||
364 | sudo docker system prune |
||
365 | </code></pre> |
||
366 | 4 | Jeremias Keihsler | |
367 | h2. create custom app image (erpnext & eu_einvoice) |
||
368 | |||
369 | https://github.com/frappe/frappe_docker/blob/main/docs/custom-apps.md |
||
370 | |||
371 | <pre><code class="shell"> |
||
372 | 6 | Jeremias Keihsler | docker pull mariadb:10.6 |
373 | docker pull redis:6.2-alpine |
||
374 | </code></pre> |
||
375 | |||
376 | <pre><code class="shell"> |
||
377 | 4 | Jeremias Keihsler | export APPS_JSON='[ |
378 | { |
||
379 | "url": "https://github.com/frappe/erpnext", |
||
380 | "branch": "version-15" |
||
381 | }, |
||
382 | { |
||
383 | "url": "https://github.com/alyf-de/eu_einvoice.git", |
||
384 | "branch": "version-15" |
||
385 | } |
||
386 | ]' |
||
387 | |||
388 | export APPS_JSON_BASE64=$(echo ${APPS_JSON} | base64 -w 0) |
||
389 | |||
390 | echo ${APPS_JSON} |
||
391 | echo ${APPS_JSON_BASE64} |
||
392 | </code></pre> |
||
393 | |||
394 | <pre><code class="shell"> |
||
395 | 5 | Jeremias Keihsler | cd ~ |
396 | 4 | Jeremias Keihsler | git clone https://github.com/frappe/frappe_docker |
397 | cd frappe_docker |
||
398 | docker build \ |
||
399 | --build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \ |
||
400 | --build-arg=FRAPPE_BRANCH=version-15 \ |
||
401 | --build-arg=PYTHON_VERSION=3.11.6 \ |
||
402 | --build-arg=NODE_VERSION=18.18.2 \ |
||
403 | --build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \ |
||
404 | --tag=customapp:1.0.0 \ |
||
405 | --file=images/custom/Containerfile . |
||
406 | |||
407 | docker build \ |
||
408 | --build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \ |
||
409 | --build-arg=FRAPPE_BRANCH=version-15 \ |
||
410 | --build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \ |
||
411 | --tag=customapp:1.0.0 \ |
||
412 | --file=images/custom/Containerfile . |
||
413 | 5 | Jeremias Keihsler | |
414 | docker image ls |
||
415 | 4 | Jeremias Keihsler | </code></pre> |
416 | 5 | Jeremias Keihsler | |
417 | <code> |
||
418 | ... |
||
419 | image: customapp:1.0.0 |
||
420 | pull_policy: never |