Global refactoring (#617)
* Rename `bench-build` target to `bench` in bake file * Update bake file and break everything * Rename docker-compose.yml to compose.yml to avoid conflicting on `docker buildx bake` * Fix groups in bake file * Update frappe-worker * Update frappe-nginx, erpnext-nginx * Remove old erpnext images * Update frappe-socketio * Fix develop frappe-nginx build on linux/arm64 * Update dockerignore * Update gitignore * Update gitignore * Update .env files * Update installation (overrides) * Update tests * Fix image names * Update compose * Update get-latest-tags * Update CI * Setup and remove .env on tests * Add build bench workflow * Add triggers to main workflow * Add release helm job * Use reusable workflows * Rollback * Print configuration before running tests * Show tests/.env * Revert "Show tests/.env" This reverts commit4bc3bdebaf. * Fix ci image versions * Remove `frappe-` prefix in build directories * Move requirements-dev.txt * Fix image name in CI * Update gitignore * Update pre-commit config * Drop `version:` in compose files * Add push-backup * Fix postgres CI test * Change .yml to .yaml in compose file to follow compose-spec * Remove prettierignore * Fix dockerignore * Change .yml to .yaml in compose file to follow compose-spec * Don't depend on boto3 while testing (do it in backend) * Update erpnext example version * Don't fail ping on URLError * Move assets volume to main compose file * Fix type annotations for v12 * Fix postgres ci override in tests * Fix spaces in socketio * Reorder stages in nginx image, improve perfomance * Remove unused todo * Optimize worker build * Install Node in worker image * Add 502 error page * Remove unused quiet-pull in tests * Add configurator service to dynamically set common config * Remove unused compose.ci-postgres.yml * Use Python for configurator service: faster and more robust * Add TODO.md * Use python script to get latest tags in CI * Clean up nginx dockerfile * Remove VOLUME declaration https://stackoverflow.com/a/55052682 * Add custom app example * Remove pwd for now * Remove pwd for now * Use jq for parsing config in healthcheck * Take advantage of yaml lang: add defaults in compose file. Also require env vars * Fix CI * Use resusable workflow * Update * Move release_helm job to main.yml * Rename docker-build to docker-build-push * Rename main to build_stable * Rename bench targets * Remove quotes from docker-build-push inputs * Update build develop * Remove HELM_DEPLOY_KEY secret from docker-build-push * Add job names * Remove build_bench workflow * Update version input description in docker-build-push * Print .env in tests, if version is develop, change to latest (for tag) * Fix env setup * Uncomment tests * Parse and set short tags from git tag in bake file * Move devcontainer settings to devcontainer.json * Add db command notice * Fix CI? * Fix inconsistencies in development readme * Remove pwd for now * Remove custom apps for production instruction * Update todos * Add docs for images and compose files * Add variables docs and allow custom frappe site name header * Add notice about internal environment variables * Update site-operations docs * Update todos * Add Overrides header in images-and-compose-files * Update todos * Remove extra docs * Don't log requests in worker image (nginx already does that) * Remove default value of FRAPPE_SITE_NAME_HEADER in example.env * Use file that consistent in v12, v13 and develop to check /assets * Fix paths in CI * Update todos * Remove TODO.md * Update tests/_check_backup_files.py Co-authored-by: Revant Nandgaonkar <revant.one@gmail.com> * Change variables MINIO_ACCESS_KEY and MINIO_SECRET_KEY to S3_ACCESS_KEY, S3_SECRET_KEY in tests * Fix S3 test * Use `nginxinc/nginx-unprivileged` instead of `nginx` image Also use Ngnix 1.20 instead of unstable 1.21 * Fix https override * Update Dockerfile * Mount assets to backend service in read only mode * Touch .build (#307), use scripts from nginx image to generate config and touch .build * Update example env after building stable images * Touch `.build` on develop image (untill https://github.com/frappe/frappe/issues/15396 is resolved) * Add `make` to worker build deps for linux/arm64 * Fix update example.env job * Fix .build creation on develop branch * Move bench CI to different file This way workflow runs only on PRs that relevant to bench build * Fix app name in custom app example * Update erpnext and frappe versions in example.env * Don't install `svg-sprite` and `sass` node modules in nginx image on linux/arm64 (https://github.com/frappe/frappe/pull/15275) * docs: README and docs * docs: add link to site operations from docker swarm * ci: fix tests as per changes to compose.yaml * docs: move wiki articles to docs * docs: fix add custom domain * docs: fix patch code from images * fix: do not expose port 80 for old images * fix: custom domain labels to frontend container/service * Add missing descriptions to envs in example.env * Fix redis depends_on * Fix docker compose in tests when not running on TTY * Set -T flag in `docker compose exec` only if not tty * Run pre-commit on docs * Remove postgres healthcheck (it gets overriden by mariadb) * Refactor test * Update workflow names * Add pip to dependabot config * docs: backup and push (#19) * Beautify changes by @revant (#20) * feat: add gevent to worker image * feat: real_ip configuration for nginx * Return `healthcheck.sh` just for tests Co-authored-by: Lev Vereshchagin <mail@vrslev.com> * Make pretend bench catch unknown commands (closes #666) * Remove debug print in push-backup * Fix typing issues in push-backup * Update file keys in push-backups: from abs path to <site>/<file> * Refactor push-backup * Move gevent installation in Frappe step * Don't pin boto stubs requirement * Cache pip deps on build * Update example env versions * Refactor check backup files * Fix backup test * Fix backup test * Rename build/ dir to images/ * Rename build/ dir to images/ * Fix /build -> /images in docs * Update example.env * Use reusable workflow in frappe user instead of vrslev * Fix compose`s `project` option in docs (https://github.com/frappe/frappe_docker/pull/617#issuecomment-1065178792) * Add note about project option in site-operations doc * Update example env * Rename build arg `USERNAME` to `REGISTRY_USER` * Allow https proxy to access Docker socket * Revert "Use reusable workflow in frappe user instead of vrslev" This reverts commit6062500d0d. * Revert "Revert "Use reusable workflow in frappe user instead of vrslev"" This reverts commit4680d18ff8. Co-authored-by: Revant Nandgaonkar <revant.one@gmail.com>
This commit is contained in:
@@ -1,295 +1,55 @@
|
||||
### Prerequisites
|
||||
## Prerequisites
|
||||
|
||||
IMPORTANT: All commands are executed on live server with public IP and DNS Configured.
|
||||
- [yq](https://mikefarah.gitbook.io/yq)
|
||||
- [docker-compose](https://docs.docker.com/compose/)
|
||||
- [docker swarm](https://docs.docker.com/engine/swarm/)
|
||||
|
||||
#### Setup docker swarm
|
||||
#### Generate setup for docker swarm
|
||||
|
||||
Follow [dockerswarm.rocks](https://dockerswarm.rocks) guide to setup Docker swarm, Traefik and Portainer.
|
||||
Generate the swarm compatible YAML,
|
||||
|
||||
Use Portainer for rest of the guide
|
||||
|
||||
### Create Config
|
||||
|
||||
Configs > Add Config > `frappe-mariadb-config`
|
||||
|
||||
```
|
||||
[mysqld]
|
||||
character-set-client-handshake = FALSE
|
||||
character-set-server = utf8mb4
|
||||
collation-server = utf8mb4_unicode_ci
|
||||
|
||||
[mysql]
|
||||
default-character-set = utf8mb4
|
||||
```bash
|
||||
docker-compose -f compose.yaml \
|
||||
-f overrides/compose.erpnext.yaml \
|
||||
-f overrides/compose.swarm.yaml \
|
||||
-f overrides/compose.https.yaml \
|
||||
config \
|
||||
| yq eval 'del(.services.*.depends_on) | del(.services.frontend.labels)' - \
|
||||
| yq eval '.services.proxy.command += "--providers.docker.swarmmode"' - > \
|
||||
~/gitops/compose.yaml
|
||||
```
|
||||
|
||||
### Create Secret
|
||||
In case you need to generate config for multiple benches. Install the proxy separately only once and generate stacks for each bench as follows:
|
||||
|
||||
Secret > Add Secret > `frappe-mariadb-root-password`
|
||||
|
||||
```
|
||||
longsecretpassword
|
||||
```bash
|
||||
# Setup Bench $BENCH_SUFFIX
|
||||
export BENCH_SUFFIX=one
|
||||
docker-compose -f compose.yaml \
|
||||
-f overrides/compose.erpnext.yaml \
|
||||
-f overrides/compose.swarm.yaml \
|
||||
config \
|
||||
| yq eval 'del(.services.*.depends_on) | del(.services.frontend.labels)' - \
|
||||
| sed "s|frontend|frontend-${BENCH_SUFFIX}|g" \
|
||||
| yq eval ".services.frontend-${BENCH_SUFFIX}.\"networks\"=[\"traefik-public\",\"default\"]" - \
|
||||
| yq eval ".\"networks\"={\"traefik-public\":{\"external\":true}}" - > \
|
||||
~/gitops/compose-${BENCH_SUFFIX}.yaml
|
||||
```
|
||||
|
||||
Note down this password.
|
||||
It is only available in mariadb containers at location `/run/secrets/frappe-mariadb-root-password` later
|
||||
Commands explained:
|
||||
|
||||
### Deploy MariaDB Replication
|
||||
- `docker-compose -f ... -f ... config`, this command generates the YAML based on the overrides
|
||||
- `yq eval 'del(.services.*.depends_on) | del(.services.frontend.labels)'`, this command removes the `depends_on` from all services and `labels` from frontend generated from previous command.
|
||||
- `yq eval '.services.proxy.command += "--providers.docker.swarmmode"'`, this command enables swarmmode for traefik proxy.
|
||||
- `sed "s|frontend|frontend-${BENCH_SUFFIX}|g"`, this command replaces the service name `frontend` with `frontend-` and `BENCH_SUFFIX` provided.
|
||||
- `yq eval ".services.frontend-${BENCH_SUFFIX}.\"networks\"=[\"traefik-public\",\"default\"]"`, this command attaches `traefik-public` and `default` network to frontend service.
|
||||
- `yq eval ".\"networks\"={\"traefik-public\":{\"external\":true}}"`, this commands adds external network `traefik-public` to the stack
|
||||
|
||||
Stacks > Add Stacks > `frappe-mariadb`
|
||||
Notes:
|
||||
|
||||
```yaml
|
||||
version: "3.7"
|
||||
- Set `BENCH_SUFFIX` to the stack name. the stack will be located at `~/gitops/compose-${BENCH_SUFFIX}.yaml`.
|
||||
- `traefik-public` is assumed to be the network for traefik loadbalancer for swarm.
|
||||
- Once the stack YAML is generated, you can edit it further for advance setup and commit it to your gitops
|
||||
|
||||
services:
|
||||
mariadb-master:
|
||||
image: "bitnami/mariadb:10.3"
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
configs:
|
||||
- source: frappe-mariadb-config
|
||||
target: /opt/bitnami/mariadb/conf/bitnami/my_custom.cnf
|
||||
networks:
|
||||
- frappe-network
|
||||
secrets:
|
||||
- frappe-mariadb-root-password
|
||||
volumes:
|
||||
- "mariadb_master_data:/bitnami/mariadb"
|
||||
environment:
|
||||
- MARIADB_REPLICATION_MODE=master
|
||||
- MARIADB_REPLICATION_USER=repl_user
|
||||
- MARIADB_REPLICATION_PASSWORD_FILE=/run/secrets/frappe-mariadb-root-password
|
||||
- MARIADB_ROOT_PASSWORD_FILE=/run/secrets/frappe-mariadb-root-password
|
||||
#### Site Operations
|
||||
|
||||
mariadb-slave:
|
||||
image: "bitnami/mariadb:10.3"
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
configs:
|
||||
- source: frappe-mariadb-config
|
||||
target: /opt/bitnami/mariadb/conf/bitnami/my_custom.cnf
|
||||
networks:
|
||||
- frappe-network
|
||||
secrets:
|
||||
- frappe-mariadb-root-password
|
||||
volumes:
|
||||
- "mariadb_slave_data:/bitnami/mariadb"
|
||||
environment:
|
||||
- MARIADB_REPLICATION_MODE=slave
|
||||
- MARIADB_REPLICATION_USER=repl_user
|
||||
- MARIADB_REPLICATION_PASSWORD_FILE=/run/secrets/frappe-mariadb-root-password
|
||||
- MARIADB_MASTER_HOST=mariadb-master
|
||||
- MARIADB_MASTER_PORT_NUMBER=3306
|
||||
- MARIADB_MASTER_ROOT_PASSWORD_FILE=/run/secrets/frappe-mariadb-root-password
|
||||
|
||||
volumes:
|
||||
mariadb_master_data:
|
||||
mariadb_slave_data:
|
||||
|
||||
configs:
|
||||
frappe-mariadb-config:
|
||||
external: true
|
||||
|
||||
secrets:
|
||||
frappe-mariadb-root-password:
|
||||
external: true
|
||||
|
||||
networks:
|
||||
frappe-network:
|
||||
name: frappe-network
|
||||
attachable: true
|
||||
```
|
||||
|
||||
### Deploy Frappe/ERPNext
|
||||
|
||||
Stacks > Add Stacks > `frappe-bench-v13`
|
||||
|
||||
```yaml
|
||||
version: "3.7"
|
||||
|
||||
services:
|
||||
redis-cache:
|
||||
image: redis:latest
|
||||
volumes:
|
||||
- redis-cache-vol:/data
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
redis-queue:
|
||||
image: redis:latest
|
||||
volumes:
|
||||
- redis-queue-vol:/data
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
redis-socketio:
|
||||
image: redis:latest
|
||||
volumes:
|
||||
- redis-socketio-vol:/data
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
erpnext-nginx:
|
||||
image: frappe/erpnext-nginx:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
|
||||
environment:
|
||||
- UPSTREAM_REAL_IP_ADDRESS=10.0.0.0/8
|
||||
- FRAPPE_PY=erpnext-python
|
||||
- FRAPPE_PY_PORT=8000
|
||||
- FRAPPE_SOCKETIO=frappe-socketio
|
||||
- SOCKETIO_PORT=9000
|
||||
volumes:
|
||||
- sites-vol:/var/www/html/sites:rw
|
||||
- assets-vol:/assets:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
- traefik-public
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
labels:
|
||||
- "traefik.docker.network=traefik-public"
|
||||
- "traefik.enable=true"
|
||||
- "traefik.constraint-label=traefik-public"
|
||||
- "traefik.http.routers.erpnext-nginx.rule=Host(${SITES?Variable SITES not set})"
|
||||
- "traefik.http.routers.erpnext-nginx.entrypoints=http"
|
||||
- "traefik.http.routers.erpnext-nginx.middlewares=https-redirect"
|
||||
- "traefik.http.routers.erpnext-nginx-https.rule=Host(${SITES?Variable SITES not set})"
|
||||
- "traefik.http.routers.erpnext-nginx-https.entrypoints=https"
|
||||
- "traefik.http.routers.erpnext-nginx-https.tls=true"
|
||||
- "traefik.http.routers.erpnext-nginx-https.tls.certresolver=le"
|
||||
- "traefik.http.services.erpnext-nginx.loadbalancer.server.port=8080"
|
||||
|
||||
erpnext-python:
|
||||
image: frappe/erpnext-worker:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
environment:
|
||||
- MARIADB_HOST=${MARIADB_HOST?Variable MARIADB_HOST not set}
|
||||
- REDIS_CACHE=redis-cache:6379
|
||||
- REDIS_QUEUE=redis-queue:6379
|
||||
- REDIS_SOCKETIO=redis-socketio:6379
|
||||
- SOCKETIO_PORT=9000
|
||||
- AUTO_MIGRATE=1
|
||||
volumes:
|
||||
- sites-vol:/home/frappe/frappe-bench/sites:rw
|
||||
- assets-vol:/home/frappe/frappe-bench/sites/assets:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
frappe-socketio:
|
||||
image: frappe/frappe-socketio:${FRAPPE_VERSION?Variable FRAPPE_VERSION not set}
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
volumes:
|
||||
- sites-vol:/home/frappe/frappe-bench/sites:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
erpnext-worker-default:
|
||||
image: frappe/erpnext-worker:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
command: worker
|
||||
volumes:
|
||||
- sites-vol:/home/frappe/frappe-bench/sites:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
erpnext-worker-short:
|
||||
image: frappe/erpnext-worker:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
command: worker
|
||||
environment:
|
||||
- WORKER_TYPE=short
|
||||
volumes:
|
||||
- sites-vol:/home/frappe/frappe-bench/sites:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
erpnext-worker-long:
|
||||
image: frappe/erpnext-worker:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
command: worker
|
||||
environment:
|
||||
- WORKER_TYPE=long
|
||||
volumes:
|
||||
- sites-vol:/home/frappe/frappe-bench/sites:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
frappe-schedule:
|
||||
image: frappe/erpnext-worker:${ERPNEXT_VERSION?Variable ERPNEXT_VERSION not set}
|
||||
deploy:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
command: schedule
|
||||
volumes:
|
||||
- sites-vol:/home/frappe/frappe-bench/sites:rw
|
||||
networks:
|
||||
- frappe-network
|
||||
|
||||
volumes:
|
||||
redis-cache-vol:
|
||||
redis-queue-vol:
|
||||
redis-socketio-vol:
|
||||
assets-vol:
|
||||
sites-vol:
|
||||
|
||||
networks:
|
||||
traefik-public:
|
||||
external: true
|
||||
frappe-network:
|
||||
external: true
|
||||
```
|
||||
|
||||
Use environment variables:
|
||||
|
||||
- `ERPNEXT_VERSION` variable to be set to desired version of ERPNext. e.g. 12.10.0
|
||||
- `FRAPPE_VERSION` variable to be set to desired version of Frappe Framework. e.g. 12.7.0
|
||||
- `MARIADB_HOST=frappe-mariadb_mariadb-master`
|
||||
- `SITES` variable is list of sites in back tick and separated by comma
|
||||
|
||||
```
|
||||
SITES=`site1.example.com`,`site2.example.com`
|
||||
```
|
||||
|
||||
### Create new site job
|
||||
|
||||
1. Containers > Add Container > `add-site1-example-com`
|
||||
2. Select Image frappe/erpnext-worker:v13
|
||||
3. Set command as `new`
|
||||
4. Select network `frappe-network`
|
||||
5. Select Volume `frappe-bench-v13_sites-vol` and mount in container `/home/frappe/frappe-bench/sites`
|
||||
6. Env variables:
|
||||
- MYSQL_ROOT_PASSWORD=longsecretpassword
|
||||
- SITE_NAME=site1.example.com
|
||||
- INSTALL_APPS=erpnext
|
||||
7. Start container
|
||||
|
||||
### Migrate Sites job
|
||||
|
||||
1. Containers > Add Container > `migrate-sites`
|
||||
2. Select Image frappe/erpnext-worker:v13
|
||||
3. Set command as `migrate`
|
||||
4. Select network `frappe-network`
|
||||
5. Select Volume `frappe-bench-v13_sites-vol` and mount in container `/home/frappe/frappe-bench/sites`
|
||||
6. Env variables:
|
||||
- MAINTENANCE_MODE=1
|
||||
7. Start container
|
||||
Refer [site operations documentation](./site-operations) to create new site, migrate site, drop site and perform other site operations.
|
||||
|
||||
Reference in New Issue
Block a user