Skip to content

Commit

Permalink
Merge branch 'frappe:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kemboi22 authored Dec 27, 2024
2 parents c3db2fb + d048f2b commit 24d3532
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: echo "LATEST_BENCH_RELEASE=$(curl -s 'https://api.github.com/repos/frappe/bench/releases/latest' | jq -r '.tag_name')" >> "$GITHUB_ENV"

- name: Build and test
uses: docker/bake-action@v5.10.0
uses: docker/bake-action@v5.11.0
with:
targets: bench-test

Expand All @@ -51,7 +51,7 @@ jobs:

- name: Push
if: ${{ github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' }}
uses: docker/bake-action@v5.10.0
uses: docker/bake-action@v5.11.0
with:
targets: bench
push: true
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ jobs:
image: registry:2
ports:
- 5000:5000
strategy:
matrix:
arch: [amd64, arm64]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
platforms: linux/${{ matrix.arch }}

- name: Get latest versions
run: python3 ./.github/scripts/get_latest_tags.py --repo ${{ inputs.repo }} --version ${{ inputs.version }}
Expand All @@ -71,7 +78,7 @@ jobs:
fi
- name: Build
uses: docker/bake-action@v5.10.0
uses: docker/bake-action@v5.11.0
with:
push: true
set: |
Expand Down Expand Up @@ -101,6 +108,6 @@ jobs:

- name: Push
if: ${{ inputs.push }}
uses: docker/bake-action@v5.10.0
uses: docker/bake-action@v5.11.0
with:
push: true
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: end-of-file-fixer

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py37-plus]
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,29 @@ cd frappe_docker

Then run: `docker compose -f pwd.yml up -d`

### To run on ARM64 architecture follow this instructions

After cloning the repo run this command to build multi-architecture images specifically for ARM64.

`docker buildx bake --no-cache --set "*.platform=linux/arm64"`

and then

- add `platform: linux/arm64` to all services in the pwd.yaml
- replace the current specified versions of erpnext image on `pwd.yml` with `:latest`

Then run: `docker compose -f pwd.yml up -d`

## Final steps

Wait for 5 minutes for ERPNext site to be created or check `create-site` container logs before opening browser on port 8080. (username: `Administrator`, password: `admin`)

If you ran in a Dev Docker environment, to view container logs: `docker compose -f pwd.yml -d`. Don't worry about some of the initial error messages, some services take a while to become ready, and then they go away.
If you ran in a Dev Docker environment, to view container logs: `docker compose -f pwd.yml logs -f create-site`. Don't worry about some of the initial error messages, some services take a while to become ready, and then they go away.

# Documentation

### [Frequently Asked Questions](https://github.com/frappe/frappe_docker/wiki/Frequently-Asked-Questions)

### [Production](#production)

- [List of containers](docs/list-of-containers.md)
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ x-customizable-image: &customizable_image
# By default the image used only contains the `frappe` and `erpnext` apps.
# See https://github.com/frappe/frappe_docker/blob/main/docs/custom-apps.md
# about using custom images.
image: ${CUSTOM_IMAGE:-frappe/erpnext}:${CUSTOM_TAG:-${ERPNEXT_VERSION:?No ERPNext version or tag set}}
image: ${CUSTOM_IMAGE:-frappe/erpnext}:${CUSTOM_TAG:-$ERPNEXT_VERSION}
pull_policy: ${PULL_POLICY:-always}

x-depends-on-configurator: &depends_on_configurator
Expand Down
2 changes: 1 addition & 1 deletion development/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def create_site_in_bench(args):
"new-site",
f"--db-host=mariadb", # Should match the compose service name
f"--db-type={args.db_type}", # Add the selected database type
f"--no-mariadb-socket",
f"--mariadb-user-host-login-scope=%",
f"--db-root-password=123", # Replace with your MariaDB password
f"--admin-password={args.admin_password}",
]
Expand Down
22 changes: 21 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ target "bench-test" {
# Base for all other targets

group "default" {
targets = ["erpnext"]
targets = ["erpnext", "base", "build"]
}

function "tag" {
params = [repo, version]
result = [
# Push frappe or erpnext branch as tag
"${REGISTRY_USER}/${repo}:${version}",
# If `version` param is develop (development build) then use tag `latest`
"${version}" == "develop" ? "${REGISTRY_USER}/${repo}:latest" : "${REGISTRY_USER}/${repo}:${version}",
# Make short tag for major version if possible. For example, from v13.16.0 make v13.
can(regex("(v[0-9]+)[.]", "${version}")) ? "${REGISTRY_USER}/${repo}:${regex("(v[0-9]+)[.]", "${version}")[0]}" : "",
# Make short tag for major version if possible. For example, from v13.16.0 make version-13.
can(regex("(v[0-9]+)[.]", "${version}")) ? "${REGISTRY_USER}/${repo}:version-${regex("([0-9]+)[.]", "${version}")[0]}" : "",
]
}

Expand All @@ -94,3 +98,19 @@ target "erpnext" {
target = "erpnext"
tags = tag("erpnext", "${ERPNEXT_VERSION}")
}

target "base" {
inherits = ["default-args"]
context = "."
dockerfile = "images/production/Containerfile"
target = "base"
tags = tag("base", "${FRAPPE_VERSION}")
}

target "build" {
inherits = ["default-args"]
context = "."
dockerfile = "images/production/Containerfile"
target = "build"
tags = tag("build", "${ERPNEXT_VERSION}")
}
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
10 changes: 5 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,26 @@ sed -i '/redis/d' ./Procfile
You can create a new site with the following command:

```shell
bench new-site --no-mariadb-socket sitename
bench new-site --mariadb-user-host-login-scope=% sitename
```

sitename MUST end with .localhost for trying deployments locally.

for example:

```shell
bench new-site --no-mariadb-socket development.localhost
bench new-site --mariadb-user-host-login-scope=% development.localhost
```

The same command can be run non-interactively as well:

```shell
bench new-site --mariadb-root-password 123 --admin-password admin --no-mariadb-socket development.localhost
bench new-site --db-root-password 123 --admin-password admin --mariadb-user-host-login-scope=% development.localhost
```

The command will ask the MariaDB root password. The default root password is `123`.
This will create a new site and a `development.localhost` directory under `frappe-bench/sites`.
The option `--no-mariadb-socket` will configure site's database credentials to work with docker.
The option `--mariadb-user-host-login-scope=%` will configure site's database credentials to work with docker.
You may need to configure your system /etc/hosts if you're on Linux, Mac, or its Windows equivalent.

To setup site with PostgreSQL as database use option `--db-type postgres` and `--db-host postgresql`. (Available only v12 onwards, currently NOT available for ERPNext).
Expand Down Expand Up @@ -238,7 +238,7 @@ Note: To start bench with debugger refer section for debugging.

Most developers work with numerous clients and versions. Moreover, apps may be required to be installed by everyone on the team working for a client.

This is simplified using a script to automate the process of creating a new bench / site and installing the required apps. `Administrator` password is for created sites is `admin`.
This is simplified using a script to automate the process of creating a new bench / site and installing the required apps. The `Administrator` password for created sites is `admin`.

Sample `apps-example.json` is used by default, it installs erpnext on current stable release. To install custom apps, copy the `apps-example.json` to custom json file and make changes to list of apps. Pass this file to the `installer.py` script.

Expand Down
8 changes: 4 additions & 4 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To bypass `nginx-entrypoint.sh`, mount desired `/etc/nginx/conf.d/default.conf`

## Configuration

We use environment variables to configure our setup. docker-compose uses variables from `.env` file. To get started, copy `example.env` to `.env`.
We use environment variables to configure our setup. docker-compose uses variables from the `environment:` section of the services defined within and the`.env` file, if present. Variables defined in the `.env` file are referenced via `${VARIABLE_NAME}` within the docker-compose `.yml` file. `example.env` contains a non-exhaustive list of possible configuration variables. To get started, copy `example.env` to `.env`.

### `FRAPPE_VERSION`

Expand All @@ -27,19 +27,19 @@ Password for MariaDB (or Postgres) database.

### `DB_HOST`

Hostname for MariaDB (or Postgres) database. Set only if external service for database is used.
Hostname for MariaDB (or Postgres) database. Set only if external service for database is used or the container can not be reached by its service name (db) by other containers.

### `DB_PORT`

Port for MariaDB (3306) or Postgres (5432) database. Set only if external service for database is used.

### `REDIS_CACHE`

Hostname for redis server to store cache. Set only if external service for redis is used.
Hostname for redis server to store cache. Set only if external service for redis is used or the container can not be reached by its service name (redis-cache) by other containers.

### `REDIS_QUEUE`

Hostname for redis server to store queue data and socketio. Set only if external service for redis is used.
Hostname for redis server to store queue data and socketio. Set only if external service for redis is used or the container can not be reached by its service name (redis-queue) by other containers.

### `ERPNEXT_VERSION`

Expand Down
Loading

0 comments on commit 24d3532

Please sign in to comment.