mirror of
https://github.com/frappe/frappe_docker.git
synced 2024-11-08 22:31:07 +00:00
Merge pull request #114 from revant/feat-dev-docker
feat: development docker
This commit is contained in:
commit
91a66e7c75
12
.devcontainer/devcontainer.json
Normal file
12
.devcontainer/devcontainer.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "Frappe Bench",
|
||||||
|
"appPort": [8000, 9000, 6787],
|
||||||
|
"remoteUser": "frappe",
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.shell.linux": "/bin/bash"
|
||||||
|
},
|
||||||
|
"dockerComposeFile": "./docker-compose.yml",
|
||||||
|
"service": "frappe",
|
||||||
|
"workspaceFolder": "/workspace/development",
|
||||||
|
"shutdownAction": "stopCompose"
|
||||||
|
}
|
30
.devcontainer/docker-compose.yml
Normal file
30
.devcontainer/docker-compose.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
version: "3.7"
|
||||||
|
services:
|
||||||
|
mariadb:
|
||||||
|
image: mariadb:10.3
|
||||||
|
environment:
|
||||||
|
- MYSQL_ROOT_PASSWORD=123
|
||||||
|
- MYSQL_USER=root
|
||||||
|
volumes:
|
||||||
|
- ../installation/frappe-mariadb.cnf:/etc/mysql/conf.d/frappe.cnf
|
||||||
|
- mariadb-vol:/var/lib/mysql
|
||||||
|
|
||||||
|
redis-cache:
|
||||||
|
image: redis:alpine
|
||||||
|
|
||||||
|
redis-queue:
|
||||||
|
image: redis:alpine
|
||||||
|
|
||||||
|
redis-socketio:
|
||||||
|
image: redis:alpine
|
||||||
|
|
||||||
|
frappe:
|
||||||
|
image: frappe/bench:latest
|
||||||
|
command: sleep infinity
|
||||||
|
volumes:
|
||||||
|
- ..:/workspace:cached
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mariadb-vol:
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,3 +5,5 @@
|
|||||||
|
|
||||||
# mounted volume
|
# mounted volume
|
||||||
sites
|
sites
|
||||||
|
|
||||||
|
development
|
||||||
|
11
.travis.yml
11
.travis.yml
@ -20,11 +20,16 @@ after_success:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- name: "Build Frappe python environment (edge)"
|
- name: "Build Frappe bench development environment (latest)"
|
||||||
if: branch = develop AND type != pull_request
|
if: branch = develop AND type != pull_request
|
||||||
script:
|
script:
|
||||||
- ./travis.py frappe --worker --tag edge
|
- docker build -t frappe/bench:latest -f build/bench/Dockerfile .
|
||||||
- ./travis.py frappe --worker --tag develop --tag-only
|
- docker push frappe/bench:latest
|
||||||
|
- name: "Build Frappe python environment (edge)"
|
||||||
|
if: branch = develop AND type != pull_request
|
||||||
|
script:
|
||||||
|
- ./travis.py frappe --nginx --tag edge
|
||||||
|
- ./travis.py frappe --nginx --tag develop--tag-only
|
||||||
- name: "Build Frappe nginx + static assets (edge)"
|
- name: "Build Frappe nginx + static assets (edge)"
|
||||||
if: branch = develop AND type != pull_request
|
if: branch = develop AND type != pull_request
|
||||||
script:
|
script:
|
||||||
|
58
build/bench/Dockerfile
Normal file
58
build/bench/Dockerfile
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Frappe Bench Dockerfile
|
||||||
|
|
||||||
|
FROM debian:9.6-slim
|
||||||
|
LABEL author=frappé
|
||||||
|
|
||||||
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends locales \
|
||||||
|
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
|
||||||
|
&& dpkg-reconfigure --frontend=noninteractive locales \
|
||||||
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Set locale en_us.UTF-8 for mariadb and general locale data
|
||||||
|
ENV PYTHONIOENCODING=utf-8
|
||||||
|
ENV LANGUAGE=en_US.UTF-8
|
||||||
|
ENV LANG=en_US.UTF-8
|
||||||
|
ENV LC_ALL=en_US.UTF-8
|
||||||
|
|
||||||
|
# Install all neccesary packages
|
||||||
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-suggests --no-install-recommends \
|
||||||
|
build-essential cron curl git libffi-dev liblcms2-dev libldap2-dev libmariadbclient-dev libsasl2-dev libssl1.0-dev libtiff5-dev \
|
||||||
|
libwebp-dev mariadb-client iputils-ping python3-dev python3-pip python3-setuptools python3-tk redis-tools rlwrap \
|
||||||
|
software-properties-common sudo tk8.6-dev vim xfonts-75dpi xfonts-base wget wkhtmltopdf fonts-cantarell \
|
||||||
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install nvm with node
|
||||||
|
ENV NVM_DIR /usr/local/nvm
|
||||||
|
ENV NODE_VERSION 12.16.1
|
||||||
|
RUN mkdir /usr/local/nvm \
|
||||||
|
&& wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash \
|
||||||
|
&& . $NVM_DIR/nvm.sh \
|
||||||
|
&& nvm install $NODE_VERSION \
|
||||||
|
&& nvm install 10.19.0 \
|
||||||
|
&& nvm alias default $NODE_VERSION \
|
||||||
|
&& nvm use default \
|
||||||
|
&& npm install yarn -g
|
||||||
|
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
|
||||||
|
ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH
|
||||||
|
|
||||||
|
# Install wkhtmltox correctly
|
||||||
|
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb
|
||||||
|
RUN dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb && rm wkhtmltox_0.12.5-1.stretch_amd64.deb
|
||||||
|
|
||||||
|
|
||||||
|
# Add frappe user and setup sudo
|
||||||
|
RUN groupadd -g 1000 frappe \
|
||||||
|
&& useradd -ms /bin/bash -u 1000 -g 1000 -G sudo frappe \
|
||||||
|
&& chown -R 1000:1000 /home/frappe \
|
||||||
|
&& echo '. "$NVM_DIR/nvm.sh"' >> /home/frappe/.bashrc
|
||||||
|
|
||||||
|
# Install bench
|
||||||
|
RUN pip3 install -e git+https://github.com/frappe/bench.git#egg=bench --no-cache
|
||||||
|
|
||||||
|
USER frappe
|
||||||
|
|
||||||
|
WORKDIR /home/frappe/frappe-bench
|
||||||
|
|
||||||
|
EXPOSE 8000 9000 6787
|
||||||
|
|
||||||
|
VOLUME [ "/home/frappe/frappe-bench" ]
|
22
development/.vscode/launch.json
vendored
Normal file
22
development/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Bench",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/frappe-bench/apps/frappe/frappe/utils/bench_helper.py",
|
||||||
|
"args": [
|
||||||
|
"frappe", "serve", "--port", "8000", "--noreload", "--nothreading"
|
||||||
|
],
|
||||||
|
"pythonPath": "${workspaceFolder}/frappe-bench/env/bin/python",
|
||||||
|
"cwd": "${workspaceFolder}/frappe-bench/sites",
|
||||||
|
"env": {
|
||||||
|
"DEV_SERVER": "1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
4
development/.vscode/settings.json
vendored
Normal file
4
development/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "frappe-bench/env/bin/python",
|
||||||
|
"debug.node.autoAttach": "on"
|
||||||
|
}
|
118
development/README.md
Normal file
118
development/README.md
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
# Getting Started
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Docker
|
||||||
|
- docker-compose
|
||||||
|
- user added to docker group
|
||||||
|
|
||||||
|
### Bootstrap Containers for development
|
||||||
|
|
||||||
|
Clone and change working directory to frappe_docker directory
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git clone https://github.com/frappe/frappe_docker.git
|
||||||
|
cd frappe_docker
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Manually start containers
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker-compose -f .devcontainer/docker-compose.yml up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Enter the bench container
|
||||||
|
|
||||||
|
```shell
|
||||||
|
docker exec -e "TERM=xterm-256color" -w /workspace/development -it frappe bash
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Use VSCode Remote Containers extension
|
||||||
|
|
||||||
|
- Install Remote Development Pack / Remote Containers extension
|
||||||
|
- Install VSCode Python extension
|
||||||
|
- Open frappe_docker in VSCode
|
||||||
|
- From Command Palette (Ctrl + Shift + P) Execute Remote Containers : Reopen in Container
|
||||||
|
|
||||||
|
### Setup Docker specific bench environment
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- `development` directory is ignored by it. It is mounted and available in container. Create all your benches inside this directory
|
||||||
|
- Execute these commands from container
|
||||||
|
- nvm with node v12 and v10 is installed. Check with `nvm ls`. Node v12 is default
|
||||||
|
|
||||||
|
#### Setup first bench
|
||||||
|
|
||||||
|
```shell
|
||||||
|
bench init --skip-redis-config-generation --frappe-branch version-12 frappe-bench
|
||||||
|
cd frappe-bench
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Set hosts
|
||||||
|
|
||||||
|
```shell
|
||||||
|
bench set-mariadb-host mariadb
|
||||||
|
bench set-redis-cache-host redis-cache:6379
|
||||||
|
bench set-redis-queue-host redis-queue:6379
|
||||||
|
bench set-redis-socketio-host redis-socketio:6379
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Changes related to bench start / honcho / Procfile
|
||||||
|
|
||||||
|
- honcho/Procfile starts processes required for development.
|
||||||
|
- By default Procfile has 3 redis processes that it starts. Comment (`#`) or remove these lines and then run `bench start`.
|
||||||
|
- Another option is to run following command
|
||||||
|
|
||||||
|
```shell
|
||||||
|
honcho start \
|
||||||
|
web \
|
||||||
|
socketio \
|
||||||
|
watch \
|
||||||
|
schedule \
|
||||||
|
worker_short \
|
||||||
|
worker_long \
|
||||||
|
worker_default
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Changes related to MariaDB
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- `bench new-site` command creates a user in mariadb with container IP as host
|
||||||
|
- After rebuilding container there is a chance that new bench container will not be able to access mariadb
|
||||||
|
- `'db_name'@'%'` needs to be set in mariadb and permission to the site database be given to the user
|
||||||
|
- Replace `db_name` and `db_password` from site's `site_config.json`
|
||||||
|
- MariaDB root password is 123
|
||||||
|
|
||||||
|
Enter mariadb shell
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mysql -uroot -p123 -hmariadb
|
||||||
|
```
|
||||||
|
|
||||||
|
Execute following queries
|
||||||
|
|
||||||
|
```sql
|
||||||
|
UPDATE mysql.user SET Host = '%' where User = 'db_name'; FLUSH PRIVILEGES;
|
||||||
|
SET PASSWORD FOR 'db_name'@'%' = PASSWORD('db_password'); FLUSH PRIVILEGES;
|
||||||
|
GRANT ALL PRIVILEGES ON `db_name`.* TO 'db_name'@'%'; FLUSH PRIVILEGES;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Visual Studio Code Python Debugging
|
||||||
|
|
||||||
|
- Install VSCode Python Extension once in remote container
|
||||||
|
- Reload VSCode
|
||||||
|
- Do not start `web` process with honcho
|
||||||
|
|
||||||
|
```shell
|
||||||
|
honcho start \
|
||||||
|
socketio \
|
||||||
|
watch \
|
||||||
|
schedule \
|
||||||
|
worker_short \
|
||||||
|
worker_long \
|
||||||
|
worker_default
|
||||||
|
```
|
||||||
|
|
||||||
|
- On debugger tab, Connect debugger. This will start the web process with debugger connected
|
Loading…
Reference in New Issue
Block a user