Add custom app example

This commit is contained in:
Lev Vereshchagin
2021-12-16 22:34:11 +03:00
parent e6d80db704
commit fc0ee586b1
7 changed files with 151 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
- [ ] Docs
- [ ] Test with helm chart
- [ ] Play With Docker generation
- [ ] Custom app compose and dockerfile examples
- [x] Custom app compose and dockerfile examples

View File

@@ -33,7 +33,7 @@ RUN cd apps/frappe && \
fi \
&& yarn
# Build assets stored in frappe-bench/sites/assets
# Build assets they're stored in frappe-bench/sites/assets
RUN echo "frappe" >sites/apps.txt \
&& yarn --cwd apps/frappe run production \
&& rm sites/apps.txt

38
custom_app/README.md Normal file
View File

@@ -0,0 +1,38 @@
This is basic configuration for building images and testing custom apps that use Frappe.
You can see that there's four files in this folder:
- `backend.Dockerfile`,
- `frontend.Dockerfile`,
- `docker-bake.hcl`,
- `compose.override.yaml`.
Python code will `backend.Dockerfile`. JS and CSS (and other fancy frontend stuff) files will be built in `frontend.Dockerfile` if required and served from there.
`docker-bake.hcl` is reference file for cool new [Buildx Bake](https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md). It helps to build images without having to remember all build arguments.
`compose.override.yaml` is [Compose](https://docs.docker.com/compose/compose-file/) override that replaces images from [main compose file](https://github.com/frappe/frappe_docker/blob/main/compose.yaml) so it would use your own images.
To get started, install Docker and [Buildx](https://github.com/docker/buildx#installing). Then copy all content of this folder (except this README) to your app's root directory. Also copy `compose.yaml` in the root of this repository.
Before the next step—to build images—replace "custom_app" with your app's name in `docker-bake.hcl`. After that, let's try to build:
```bash
FRAPPE_VERSION=<Frappe version you need> docker buildx bake
```
If something goes wrong feel free to leave an issue.
To test if site works, setup `.env` file (check [example](<(https://github.com/frappe/frappe_docker/blob/main/example.env)>)) and run:
```bash
docker-compose up -d
docker-compose exec backend \
bench new-site 127.0.0.1 \
--mariadb-root-password 123 \
--admin-password admin \
--install-app <Name of your app>
docker-compose restart backend
```
Cool! You just containerized your app!

View File

@@ -0,0 +1,8 @@
ARG FRAPPE_VERSION
FROM frappe/frappe-worker:${FRAPPE_VERSION}
ARG APP_NAME
COPY --chown=frappe . ../apps/${APP_NAME}
RUN echo "frappe\ncomfort" >/home/frappe/frappe-bench/sites/apps.txt \
&& ../env/bin/pip install --no-cache-dir -e ../apps/${APP_NAME}

View File

@@ -0,0 +1,21 @@
services:
configurator:
image: custom_app/worker:${VERSION}
backend:
image: custom_app/worker:${VERSION}
frontend:
image: custom_app/nginx:${VERSION}
queue-short:
image: custom_app/worker:${VERSION}
queue-default:
image: custom_app/worker:${VERSION}
queue-long:
image: custom_app/worker:${VERSION}
scheduler:
image: custom_app/worker:${VERSION}

View File

@@ -0,0 +1,25 @@
APP_NAME="custom_app"
variable "FRAPPE_VERSION" {}
group "default" {
targets = ["backend", "frontend"]
}
target "backend" {
dockerfile = "backend.Dockerfile"
tags = ["custom_app/worker:latest"]
args = {
"FRAPPE_VERSION" = FRAPPE_VERSION
"APP_NAME" = APP_NAME
}
}
target "frontend" {
dockerfile = "frontend.Dockerfile"
tags = ["custom_app/nginx:latest"]
args = {
"FRAPPE_VERSION" = FRAPPE_VERSION
"APP_NAME" = APP_NAME
}
}

View File

@@ -0,0 +1,57 @@
ARG FRAPPE_VERSION
FROM node:14-bullseye-slim as prod_node_modules
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
git \
build-essential \
python \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /root/frappe-bench
RUN mkdir -p sites/assets
ARG FRAPPE_VERSION
RUN git clone --depth 1 -b ${FRAPPE_VERSION} https://github.com/frappe/frappe apps/frappe
RUN cd apps/frappe \
&& if [ "$(uname -m)" = "aarch64" ]; then \
yarn remove svg-sprite || true \
&& yarn add sass; \
fi \
&& yarn
ARG APP_NAME
COPY . apps/${APP_NAME}
# Install production node modules
RUN yarn --cwd apps/${APP_NAME} --prod
FROM prod_node_modules as assets
ARG APP_NAME
# Install development node modules
RUN yarn --cwd apps/${APP_NAME}
# Build assets
RUN echo "frappe\n${APP_NAME}" >sites/apps.txt \
&& yarn --cwd apps/frappe production --app ${APP_NAME} \
&& rm sites/apps.txt
FROM frappe/frappe-nginx:${FRAPPE_VERSION}
ARG APP_NAME
# Copy all not built assets
COPY --from=prod_node_modules /root/frappe-bench/apps/${APP_NAME}/${APP_NAME}/public /usr/share/nginx/html/assets/${APP_NAME}
# Copy production node modules
COPY --from=prod_node_modules /root/frappe-bench/apps/${APP_NAME}/node_modules /usr/share/nginx/html/assets/${APP_NAME}/node_modules
# Copy built assets
COPY --from=assets /root/frappe-bench/sites /usr/share/nginx/html