Skip to content

Commit

Permalink
docs: quick build command (#1500)
Browse files Browse the repository at this point in the history
* docs: quick build command

* chore: fix pre-commit lint for md file
  • Loading branch information
revant authored Oct 27, 2024
1 parent 3d6fb8c commit a919f44
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 49 deletions.
103 changes: 55 additions & 48 deletions docs/custom-apps.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
### Clone frappe_docker and switch directory

```shell
git clone https://github.com/frappe/frappe_docker
cd frappe_docker
```
### Load custom apps through apps.json file

### Load custom apps through json
Base64 encoded string of `apps.json` file needs to be passed in as build arg environment variable.

`apps.json` needs to be passed in as build arg environment variable.
Create following `apps.json` file:

```shell
export APPS_JSON='[
```json
[
{
"url": "https://github.com/frappe/erpnext",
"branch": "version-15"
Expand All @@ -23,20 +18,24 @@ export APPS_JSON='[
"url": "https://{{ PAT }}@git.example.com/project/repository.git",
"branch": "main"
}
]'

export APPS_JSON_BASE64=$(echo ${APPS_JSON} | base64 -w 0)
]
```

You can also generate base64 string from json file:
Note:

- `url` needs to be http(s) git url with personal access tokens without username eg:- `http://{{PAT}}@github.com/project/repository.git` in case of private repo.
- Add dependencies manually in `apps.json` e.g. add `erpnext` if you are installing `hrms`.
- Use fork repo or branch for ERPNext in case you need to use your fork or test a PR.

Generate base64 string from json file:

```shell
export APPS_JSON_BASE64=$(base64 -w 0 /path/to/apps.json)
```

Test the Previous Step: Decode the Base64-encoded Environment Variable

To verify the previous step, decode the APPS_JSON_BASE64 environment variable (which is Base64-encoded) into a JSON file. Follow the steps below:
To verify the previous step, decode the `APPS_JSON_BASE64` environment variable (which is Base64-encoded) into a JSON file. Follow the steps below:

1. Use the following command to decode and save the output into a JSON file named apps-test-output.json:

Expand All @@ -46,29 +45,48 @@ echo -n ${APPS_JSON_BASE64} | base64 -d > apps-test-output.json

2. Open the apps-test-output.json file to review the JSON output and ensure that the content is correct.

Note:
### Clone frappe_docker and switch directory

- `url` needs to be http(s) git url with personal access tokens without username eg:- http://{{PAT}}@github.com/project/repository.git in case of private repo.
- add dependencies manually in `apps.json` e.g. add `payments` if you are installing `erpnext`
- use fork repo or branch for ERPNext in case you need to use your fork or test a PR.
```shell
git clone https://github.com/frappe/frappe_docker
cd frappe_docker
```

### Build Image
### Configure build

Common build args.

- `FRAPPE_PATH`, customize the source repo for frappe framework. Defaults to `https://github.com/frappe/frappe`
- `FRAPPE_BRANCH`, customize the source repo branch for frappe framework. Defaults to `version-15`.
- `APPS_JSON_BASE64`, correct base64 encoded JSON string generated from `apps.json` file.

Notes

- Use `buildah` or `docker` as per your setup.
- Make sure `APPS_JSON_BASE64` variable has correct base64 encoded JSON string. It is consumed as build arg, base64 encoding ensures it to be friendly with environment variables. Use `jq empty apps.json` to validate `apps.json` file.
- Make sure the `--tag` is valid image name that will be pushed to registry. See section [below](#use-images) for remarks about its use.
- `.git` directories for all apps are removed from the image.

### Quick build image

This method uses pre-built `frappe/base:${FRAPPE_BRANCH}` and `frappe/build:${FRAPPE_BRANCH}` image layers which come with required Python and NodeJS runtime. It speeds up the build time.

It uses `images/layered/Containerfile`.

```shell
docker build \
--build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \
--build-arg=FRAPPE_BRANCH=version-15 \
--build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
--tag=ghcr.io/user/repo/custom:1.0.0 \
--file=images/custom/Containerfile .
--file=images/layered/Containerfile .
```

Note:
### Custom build image

- Use `buildah` instead of `docker` as per your setup.
- Make sure `APPS_JSON_BASE64` variable has correct base64 encoded JSON string. It is consumed as build arg, base64 encoding ensures it to be friendly with environment variables. Use `jq empty apps.json` to validate `apps.json` file.
- Make sure the `--tag` is valid image name that will be pushed to registry. See section [below](#use-images) for remarks about its use.
- `.git` directories for all apps are removed from the image.
This method builds the base and build layer every time, it allows to customize Python and NodeJS runtime versions. It takes more time to build.

Customize these optional `--build-arg`s to use a different Frappe Framework repo and branch, or version of Python and NodeJS:
It uses `images/custom/Containerfile`.

```shell
docker build \
Expand All @@ -81,39 +99,28 @@ docker build \
--file=images/custom/Containerfile .
```

Custom build args,

- `PYTHON_VERSION`, use the specified python version for base image. Default is `3.11.6`.
- `NODE_VERSION`, use the specified nodejs version, Default `18.18.2`.
- `DEBIAN_BASE` use the base Debian version, defaults to `bookworm`.
- `WKHTMLTOPDF_VERSION`, use the specified qt patched `wkhtmltopdf` version. Default is `0.12.6.1-3`.
- `WKHTMLTOPDF_DISTRO`, use the specified distro for debian package. Default is `bookworm`.

### Push image to use in yaml files

Login to `docker` or `buildah`

```shell
buildah login
docker login
```

Push image

```shell
buildah push ghcr.io/user/repo/custom:1.0.0
```

### Use Kaniko

Following executor args are required. Example runs locally in docker container.
You can run it part of CI/CD or part of your cluster.

```shell
podman run --rm -it \
-v "$HOME"/.docker/config.json:/kaniko/.docker/config.json \
gcr.io/kaniko-project/executor:latest \
--dockerfile=images/custom/Containerfile \
--context=git://github.com/frappe/frappe_docker \
--build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
--cache=true \
--destination=ghcr.io/user/repo/custom:1.0.0 \
--destination=ghcr.io/user/repo/custom:latest
docker push ghcr.io/user/repo/custom:1.0.0
```

More about [kaniko](https://github.com/GoogleContainerTools/kaniko)

### Use Images

In the [compose.yaml](../compose.yaml), you can set the image name and tag through environment variables, making it easier to customize.
Expand Down
13 changes: 12 additions & 1 deletion images/layered/Containerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
ARG FRAPPE_BRANCH=version-15
ARG FRAPPE_PATH=https://github.com/frappe/frappe

FROM frappe/build:${FRAPPE_BRANCH} AS builder

ARG FRAPPE_BRANCH=version-15
ARG FRAPPE_PATH=https://github.com/frappe/frappe
ARG APPS_JSON_BASE64

USER root

RUN if [ -n "${APPS_JSON_BASE64}" ]; then \
mkdir /opt/frappe && echo "${APPS_JSON_BASE64}" | base64 -d > /opt/frappe/apps.json; \
fi

USER frappe

RUN export APP_INSTALL_ARGS="" && \
if [ -n "${APPS_JSON_BASE64}" ]; then \
export APP_INSTALL_ARGS="--apps_path=/opt/frappe/apps.json"; \
Expand Down

0 comments on commit a919f44

Please sign in to comment.