Compare commits

..

56 Commits

Author SHA1 Message Date
5601d97782 Replace the frappe team's "hack" that used docker nested anonymous volumes to pull sites/assets from the base image with a much simpler solution using symlinks 2025-01-15 18:41:48 -05:00
PAlexanderFranklin
82d4412e8f Update docker image instructions, add git pull updating procedure 2024-05-16 15:25:22 -07:00
PAlexanderFranklin
da3b22663c Switch from local image to remote image 2024-05-07 16:00:18 -07:00
PAlexanderFranklin
2fcd3d694d Update readme with instructions for updating erpnext 2024-05-06 11:41:31 -07:00
PAlexanderFranklin
ca83b252b0 Add clean image building, image pushing instructions 2024-04-10 16:03:58 -07:00
PAlexanderFranklin
9eca8b7d4c Comment out unused line, add instructions for seeing our edits. 2024-04-03 17:06:36 -07:00
PAlexanderFranklin
5e684cdcd1 haha funny bug. Copied wrong line. Don't remember doing that. 2024-04-03 15:31:13 -07:00
PAlexanderFranklin
8b49942e84 Add custom image build to readme 2024-04-01 17:12:25 -07:00
PAlexanderFranklin
41219e5df3 Change image to local image 2024-04-01 16:45:17 -07:00
PAlexanderFranklin
83a582bf87 Change custom image in compose.yaml, add apps.json 2024-04-01 16:31:41 -07:00
PAlexanderFranklin
c55ba0302a remove git rm rf 2024-03-25 13:57:21 -07:00
PAlexanderFranklin
4b8817c7a4 Switch back to https for erpnext repo 2024-03-22 14:08:45 -07:00
PAlexanderFranklin
0f566169e2 Change home path 2024-03-22 13:58:18 -07:00
PAlexanderFranklin
6463ff56fe add ~ 2024-03-21 15:05:16 -07:00
PAlexanderFranklin
96e7c027e0 a 2024-03-21 15:00:54 -07:00
PAlexanderFranklin
5067a9640f sdjhfkjds 2024-03-21 14:56:44 -07:00
PAlexanderFranklin
8f48cf379d remove project from build command 2024-03-21 14:56:08 -07:00
PAlexanderFranklin
541ddaeb67 Try docker compose build 2024-03-21 14:47:52 -07:00
PAlexanderFranklin
fba87aaad8 Move ssh key again 2024-03-21 13:48:06 -07:00
PAlexanderFranklin
07b6837b04 Move ssh to compose up instead of build 2024-03-21 13:47:16 -07:00
PAlexanderFranklin
285a6c1636 Switch from secrets to --ssh 2024-03-21 13:37:23 -07:00
PAlexanderFranklin
7be08f459e fix global flag 2024-03-21 13:14:02 -07:00
PAlexanderFranklin
714ce32c08 Add git config 2024-03-21 13:10:49 -07:00
PAlexanderFranklin
69daa7566e Try latest thing 2024-03-21 13:02:08 -07:00
PAlexanderFranklin
c572d297cc move ssh:// 2024-03-21 12:54:22 -07:00
PAlexanderFranklin
149649b6d4 Use argument for ssh test 2024-03-21 12:53:30 -07:00
PAlexanderFranklin
2dcc36ecd1 Try the same thing again 2024-03-21 12:50:48 -07:00
PAlexanderFranklin
9978aebaea Try both quotes and escape 2024-03-21 12:48:02 -07:00
PAlexanderFranklin
aab5999af5 Add escape char instead 2024-03-21 12:46:08 -07:00
PAlexanderFranklin
6d686b3122 Add quotation marks cause ssh -T complained about -e option 2024-03-21 12:44:56 -07:00
PAlexanderFranklin
355e2b383c try it without the symbolic link 2024-03-21 12:43:41 -07:00
PAlexanderFranklin
3982bcbc6d disable verbose, add test ssh connection 2024-03-21 12:37:57 -07:00
PAlexanderFranklin
75852c07e4 Add identityfile to ssh config 2024-03-21 12:20:49 -07:00
PAlexanderFranklin
11a1fce262 Use secrets instead of copy 2024-03-21 11:59:07 -07:00
PAlexanderFranklin
0ef7f29e5a try again 2024-03-21 11:49:42 -07:00
PAlexanderFranklin
b94cffdc34 change to relative path 2024-03-21 11:48:43 -07:00
PAlexanderFranklin
12629a4520 Add absolute paths for ssh 2024-03-21 11:39:24 -07:00
PAlexanderFranklin
b91a9b17a1 ditto 2024-03-20 13:20:10 -07:00
PAlexanderFranklin
f57ead3bd5 Change home to absolute path 2024-03-20 13:18:52 -07:00
PAlexanderFranklin
aceb7f9709 Fix ssh for erpnext 2024-03-20 13:14:58 -07:00
PAlexanderFranklin
82aa5d9570 Remove unfound package openssh-ssh 2024-03-20 12:53:56 -07:00
PAlexanderFranklin
15e61a6655 Add home/ to testfolder cause permissions issues 2024-03-20 12:51:48 -07:00
PAlexanderFranklin
7269b21dd0 move image into root 2024-03-20 12:34:25 -07:00
PAlexanderFranklin
9004454313 Change context back, add dockerfile path 2024-03-20 12:23:33 -07:00
PAlexanderFranklin
b6306af846 fix containerfile case 2024-03-20 11:46:22 -07:00
PAlexanderFranklin
05e9080312 Separate build into context and dockerfile 2024-03-20 11:45:27 -07:00
PAlexanderFranklin
f474f31ca2 Add docker file to end of path 2024-03-20 11:42:19 -07:00
PAlexanderFranklin
2cc5bd4baa build docker file locally 2024-03-20 11:34:52 -07:00
PAlexanderFranklin
0cef52c210 Update readme to use installer 2024-03-13 12:58:13 -07:00
PAlexanderFranklin
ceca0e3332 Change repo relative path from installer 2024-03-13 12:19:10 -07:00
PAlexanderFranklin
5fababa5f9 Revert "change easy-installer repo directory; comment out clone function"
This reverts commit 73139b7a456cb224ea40f6a01989b63ee7637a45.
The new directory did not seem to work, so we changed it back.
2024-03-13 12:17:39 -07:00
PAlexanderFranklin
73139b7a45 change easy-installer repo directory; comment out clone function
Commented because the clone function puts the repo in a different
spot than the check function does.
2024-03-13 12:11:16 -07:00
PAlexanderFranklin
c471c1a9ee Add easy-installer from bench repository 2024-03-13 12:01:10 -07:00
PAlexanderFranklin
0b0646e363 Add tentative ssh environment to docker image 2024-03-13 11:45:21 -07:00
PAlexanderFranklin
9d24abbee4 Fix typos, add env variables to final bench command 2024-03-13 11:36:41 -07:00
PAlexanderFranklin
b1ae5183a7 Add docker instructions to README 2024-03-12 16:58:45 -07:00
9 changed files with 656 additions and 8 deletions

View File

@ -49,6 +49,104 @@ Wait for 5 minutes for ERPNext site to be created or check `create-site` contain
### [Troubleshoot](docs/troubleshoot.md)
### Shiloh Setup
based on: https://raw.githubusercontent.com/frappe/bench/develop/easy-install.py
`git clone ssh://git@githaven.org:2222/Shiloh/frappe_docker.git`
sites = [erp.sprinklersnorthwest.com]
email = support@lasthourhosting.org
`cd frappe_docker`
`cp example.env .env`
Write inside of env:
<!-- Commented items because the script doesn't read them. -->
<!-- f"ERPNEXT_VERSION={erpnext_version}\n", -->
f"DB_PASSWORD={db_pass}\n",
<!-- "DB_HOST=db\n",
"DB_PORT=3306\n",
"REDIS_CACHE=redis-cache:6379\n",
"REDIS_QUEUE=redis-queue:6379\n",
"REDIS_SOCKETIO=redis-socketio:6379\n",
f"LETSENCRYPT_EMAIL={email}\n", -->
f"SITE_ADMIN_PASS={admin_pass}\n",
<!-- f"SITES={quoted_sites}\n", -->
<!-- from inside the frappe-docker repo: -->
<!-- Setup reference to our own erpnext repo -->
`APPS_JSON_BASE64=$(base64 -w 0 ./apps.json)`
<!-- build the docker image -->
`sudo docker build \
--build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \
--build-arg=FRAPPE_BRANCH=version-15 \
--build-arg=PYTHON_VERSION=3.11.6 \
--build-arg=NODE_VERSION=18.18.2 \
--build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
--tag=githaven.org/shiloh/frappe_docker:production \
--file=images/custom/Containerfile \
--rm \
--no-cache \
.`
<!-- Push to githaven -->
<!-- sudo docker image tag NAME:TAG githaven.org/shiloh/frappe_docker:production -->
`sudo docker login githaven.org`
setup credential service to hide password
`sudo docker push githaven.org/shiloh/frappe_docker:production`
https://docs.gitea.com/packages/packages/container
<!-- Install erpnext for first time -->
`sudo python3 easy-installer.py --prod --email support@lasthourhosting.org --site erp.sprinklersnorthwest.com`
`bench use` should already be done by the installer.
<!-- `sudo docker compose -p frappe exec backend bench use erp.sprinklersnorthwest.com` -->
Create a project through the dashboard with the sidebar, then login with the admin account and view the projects page through the other dashboard, you should see edits.
<!-- to enter the container: -->
`sudo docker compose -p frappe exec -it backend bash`
To update erpnext, add any commits you want to use to the "production" branch of the erpnext repo on githaven. Then ensure the "backend" container has git repositories in the frappe and erpnext apps:
`cd ~/frappe-bench/apps/erpnext`
`git init`
`git remote add upstream <repo>`
`git fetch upstream production`
`git checkout production --force`
`git clean -fd`
Then pull the latest erpnext, and it will be updated.
<!-- Bench update hangs on node esbuild, so we're just manually pulling the latest changes rather than doing it through this command. -->
<!-- Then from ./frappe-bench run:
`bench update` -->
<!-- `sudo docker compose --project-name brotherton -f compose.yaml -f overrides/compose.mariadb.yaml -f overrides/compose.redis.yaml -f overrides/compose.https.yaml --env-file .env config`
Make images/production/Containerfile available as a package on githaven? need to replace the erpnext repo argument inside it.
inside of compose.yaml, replace "image: frappe/erpnext" with the above package.
`. .env`
`sudo docker compose -p brotherton -f compose.yaml up -d`
The "erpnext" in this command is probably fine, I think the bench get-app inside the docker compose gets the erpnext repository and puts it into an erpnext "app", regardless of what the erpnext repo env variable is. This command only works if SITES contains a single site.
`sudo docker compose -p brotherton exec backend bench new-site "$SITES" --no-mariadb-socket --db-root-password "$DB_PASSWORD" --admin-password "$SITE_ADMIN_PASS" --install-app erpnext --set-default` -->
# Contributing
If you want to contribute to this repo refer to [CONTRIBUTING.md](CONTRIBUTING.md)

147
Shilohimage Normal file
View File

@ -0,0 +1,147 @@
ARG PYTHON_VERSION=3.11.6
ARG DEBIAN_BASE=bookworm
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_BASE} AS base
ARG WKHTMLTOPDF_VERSION=0.12.6.1-3
ARG WKHTMLTOPDF_DISTRO=bookworm
ARG NODE_VERSION=18.18.2
ENV NVM_DIR=/home/frappe/.nvm
ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/:${PATH}
RUN useradd -ms /bin/bash frappe \
&& apt-get update \
&& apt-get install --no-install-recommends -y \
curl \
git \
vim \
nginx \
gettext-base \
# weasyprint dependencies
libpango-1.0-0 \
libharfbuzz0b \
libpangoft2-1.0-0 \
libpangocairo-1.0-0 \
# For backups
restic \
gpg \
# MariaDB
mariadb-client \
less \
# Postgres
libpq-dev \
postgresql-client \
# For healthcheck
wait-for-it \
jq \
# NodeJS
&& mkdir -p ${NVM_DIR} \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
&& . ${NVM_DIR}/nvm.sh \
&& nvm install ${NODE_VERSION} \
&& nvm use v${NODE_VERSION} \
&& npm install -g yarn \
&& nvm alias default v${NODE_VERSION} \
&& rm -rf ${NVM_DIR}/.cache \
&& echo 'export NVM_DIR="/home/frappe/.nvm"' >>/home/frappe/.bashrc \
&& echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' >>/home/frappe/.bashrc \
&& echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >>/home/frappe/.bashrc \
# Install wkhtmltopdf with patched qt
&& if [ "$(uname -m)" = "aarch64" ]; then export ARCH=arm64; fi \
&& if [ "$(uname -m)" = "x86_64" ]; then export ARCH=amd64; fi \
&& downloaded_file=wkhtmltox_${WKHTMLTOPDF_VERSION}.${WKHTMLTOPDF_DISTRO}_${ARCH}.deb \
&& curl -sLO https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTMLTOPDF_VERSION/$downloaded_file \
&& apt-get install -y ./$downloaded_file \
&& rm $downloaded_file \
# Clean up
&& rm -rf /var/lib/apt/lists/* \
&& rm -fr /etc/nginx/sites-enabled/default \
&& pip3 install frappe-bench \
# Fixes for non-root nginx and logs to stdout
&& sed -i '/user www-data/d' /etc/nginx/nginx.conf \
&& ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log \
&& touch /run/nginx.pid \
&& chown -R frappe:frappe /etc/nginx/conf.d \
&& chown -R frappe:frappe /etc/nginx/nginx.conf \
&& chown -R frappe:frappe /var/log/nginx \
&& chown -R frappe:frappe /var/lib/nginx \
&& chown -R frappe:frappe /run/nginx.pid
COPY resources/nginx-template.conf /templates/nginx/frappe.conf.template
COPY resources/nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh
FROM base AS builder
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
# For frappe framework
wget \
# For psycopg2
libpq-dev \
# Other
libffi-dev \
liblcms2-dev \
libldap2-dev \
libmariadb-dev \
libsasl2-dev \
libtiff5-dev \
libwebp-dev \
redis-tools \
rlwrap \
tk8.6-dev \
cron \
# For pandas
gcc \
build-essential \
libbz2-dev \
# for erpnext repo
openssh-client \
&& rm -rf /var/lib/apt/lists/*
USER frappe
RUN mkdir -p /home/frappe/.ssh
RUN echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /home/frappe/.ssh/config
ARG FRAPPE_BRANCH=version-15
ARG FRAPPE_PATH=https://github.com/frappe/frappe
ARG ERPNEXT_REPO=https://githaven.org/Shiloh/brotherton-erpnext.git
ARG ERPNEXT_BRANCH=production
# RUN ssh -T ${ERPNEXT_REPO}
RUN bench init \
--frappe-branch=${FRAPPE_BRANCH} \
--frappe-path=${FRAPPE_PATH} \
--no-procfile \
--no-backups \
--skip-redis-config-generation \
--verbose \
/home/frappe/frappe-bench && \
cd /home/frappe/frappe-bench && \
bench get-app --branch=${ERPNEXT_BRANCH} --resolve-deps erpnext ${ERPNEXT_REPO} && \
echo "{}" > sites/common_site_config.json
FROM base as erpnext
USER frappe
COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe/frappe-bench
WORKDIR /home/frappe/frappe-bench
VOLUME [ \
"/home/frappe/frappe-bench/sites", \
"/home/frappe/frappe-bench/sites/assets", \
"/home/frappe/frappe-bench/logs" \
]
CMD [ \
"/home/frappe/frappe-bench/env/bin/gunicorn", \
"--chdir=/home/frappe/frappe-bench/sites", \
"--bind=0.0.0.0:8000", \
"--threads=4", \
"--workers=2", \
"--worker-class=gthread", \
"--worker-tmp-dir=/dev/shm", \
"--timeout=120", \
"--preload", \
"frappe.app:application" \
]

6
apps.json Normal file
View File

@ -0,0 +1,6 @@
[
{
"url": "https://githaven.org/Shiloh/brotherton-erpnext.git",
"branch": "production"
}
]

23
build.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
export APPS_JSON='[
{
"url": "https://githaven.org/Shiloh/brotherton-erpnext",
"branch": "production"
},
{
"url": "https://github.com/frappe/hrms",
"branch": "v15.15.0"
}
]'
export APPS_JSON_BASE64=$(echo ${APPS_JSON} | base64 -w 0)
export TAG=1.0.1 # Change this
docker build --platform=linux/amd64 \
--build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \
--build-arg=FRAPPE_BRANCH=v15.15.0 \
--build-arg=PYTHON_VERSION=3.11.6 \
--build-arg=NODE_VERSION=18.18.2 \
--build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
--tag=githaven.org/shiloh/frappe_docker:$TAG \
--file=images/custom/Containerfile .
docker push githaven.org/shiloh/frappe_docker:$TAG

View File

@ -2,7 +2,10 @@ 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: frappe/erpnext:${ERPNEXT_VERSION:?No ERPNext version set}
image: githaven.org/shiloh/frappe_docker:production
# build:
# context: .
# dockerfile: ./Shilohimage
x-depends-on-configurator: &depends_on_configurator
depends_on:
@ -24,6 +27,8 @@ services:
command:
- >
ls -1 apps > sites/apps.txt;
rm -rf sites/assets || true;
ln -s /home/frappe/frappe-bench/assets sites/assets || true;
bench set-config -g db_host $$DB_HOST;
bench set-config -gp db_port $$DB_PORT;
bench set-config -g redis_cache "redis://$$REDIS_CACHE";

363
easy-installer.py Normal file
View File

@ -0,0 +1,363 @@
#!/usr/bin/env python3
import argparse
import fileinput
import logging
import os
import platform
import subprocess
import sys
import time
import urllib.request
from shutil import move, unpack_archive, which
from typing import Dict
logging.basicConfig(
filename="easy-install.log",
filemode="w",
format="%(asctime)s - %(levelname)s - %(message)s",
level=logging.INFO,
)
def cprint(*args, level: int = 1):
"""
logs colorful messages
level = 1 : RED
level = 2 : GREEN
level = 3 : YELLOW
default level = 1
"""
CRED = "\033[31m"
CGRN = "\33[92m"
CYLW = "\33[93m"
reset = "\033[0m"
message = " ".join(map(str, args))
if level == 1:
print(CRED, message, reset)
if level == 2:
print(CGRN, message, reset)
if level == 3:
print(CYLW, message, reset)
def clone_frappe_docker_repo() -> None:
try:
urllib.request.urlretrieve(
"https://github.com/frappe/frappe_docker/archive/refs/heads/main.zip",
"frappe_docker.zip",
)
logging.info("Downloaded frappe_docker zip file from GitHub")
unpack_archive(
"frappe_docker.zip", "."
) # Unzipping the frappe_docker.zip creates a folder "frappe_docker-main"
move("frappe_docker-main", "frappe_docker")
logging.info("Unzipped and Renamed frappe_docker")
os.remove("frappe_docker.zip")
logging.info("Removed the downloaded zip file")
except Exception as e:
logging.error("Download and unzip failed", exc_info=True)
cprint("\nCloning frappe_docker Failed\n\n", "[ERROR]: ", e, level=1)
def get_from_env(dir, file) -> Dict:
env_vars = {}
with open(os.path.join(dir, file)) as f:
for line in f:
if line.startswith("#") or not line.strip():
continue
key, value = line.strip().split("=", 1)
env_vars[key] = value
return env_vars
def write_to_env(
wd: str,
sites,
db_pass: str,
admin_pass: str,
email: str,
erpnext_version: str = None,
) -> None:
quoted_sites = ",".join([f"`{site}`" for site in sites]).strip(",")
example_env = get_from_env(wd, "example.env")
erpnext_version = erpnext_version or example_env["ERPNEXT_VERSION"]
with open(os.path.join(wd, ".env"), "w") as f:
f.writelines(
[
f"ERPNEXT_VERSION={erpnext_version}\n", # defaults to latest version of ERPNext
f"DB_PASSWORD={db_pass}\n",
"DB_HOST=db\n",
"DB_PORT=3306\n",
"REDIS_CACHE=redis-cache:6379\n",
"REDIS_QUEUE=redis-queue:6379\n",
"REDIS_SOCKETIO=redis-socketio:6379\n",
f"LETSENCRYPT_EMAIL={email}\n",
f"SITE_ADMIN_PASS={admin_pass}\n",
f"SITES={quoted_sites}\n",
]
)
def generate_pass(length: int = 12) -> str:
"""Generate random hash using best available randomness source."""
import math
import secrets
if not length:
length = 56
return secrets.token_hex(math.ceil(length / 2))[:length]
def check_repo_exists() -> bool:
return os.path.exists(os.path.join(os.getcwd(), "../frappe_docker"))
def setup_prod(
project: str, sites, email: str, version: str = None, image=None
) -> None:
if len(sites) == 0:
sites = ["site1.localhost"]
if check_repo_exists():
compose_file_name = os.path.join(
os.path.expanduser("~"), f"{project}-compose.yml"
)
docker_repo_path = os.path.join(os.getcwd(), "../frappe_docker")
cprint(
"\nPlease refer to .example.env file in the frappe_docker folder to know which keys to set\n\n",
level=3,
)
admin_pass = ""
db_pass = ""
with open(compose_file_name, "w") as f:
# Writing to compose file
if not os.path.exists(os.path.join(docker_repo_path, ".env")):
admin_pass = generate_pass()
db_pass = generate_pass(9)
write_to_env(
docker_repo_path, sites, db_pass, admin_pass, email, version
)
cprint(
"\nA .env file is generated with basic configs. Please edit it to fit to your needs \n",
level=3,
)
with open(
os.path.join(os.path.expanduser("~"), "passwords.txt"), "w"
) as en:
en.writelines(f"ADMINISTRATOR_PASSWORD={admin_pass}\n")
en.writelines(f"MARIADB_ROOT_PASSWORD={db_pass}\n")
else:
env = get_from_env(docker_repo_path, ".env")
admin_pass = env["SITE_ADMIN_PASS"]
db_pass = env["DB_PASSWORD"]
try:
# TODO: Include flags for non-https and non-erpnext installation
subprocess.run(
[
which("docker"),
"compose",
"--project-name",
project,
"-f",
"compose.yaml",
"-f",
"overrides/compose.mariadb.yaml",
"-f",
"overrides/compose.redis.yaml",
# "-f", "overrides/compose.noproxy.yaml", TODO: Add support for local proxying without HTTPs
"-f",
"overrides/compose.https.yaml",
"--env-file",
".env",
"config",
],
cwd=docker_repo_path,
stdout=f,
check=True,
)
except Exception:
logging.error("Docker Compose generation failed", exc_info=True)
cprint("\nGenerating Compose File failed\n")
sys.exit(1)
# Use custom image
if image:
for line in fileinput.input(compose_file_name, inplace=True):
if "image: frappe/erpnext" in line:
line = line.replace("image: frappe/erpnext", f"image: {image}")
sys.stdout.write(line)
try:
subprocess.run(
[
which("docker"),
"compose",
"-p",
project,
"-f",
compose_file_name,
"up",
"-d",
],
check=True,
)
logging.info(f"Docker Compose file generated at ~/{project}-compose.yml")
except Exception as e:
logging.error("Prod docker-compose failed", exc_info=True)
cprint(" Docker Compose failed, please check the container logs\n", e)
sys.exit(1)
for sitename in sites:
create_site(sitename, project, db_pass, admin_pass)
else:
install_docker()
clone_frappe_docker_repo()
setup_prod(project, sites, email, version, image) # Recursive
def setup_dev_instance(project: str):
if check_repo_exists():
try:
subprocess.run(
[
"docker",
"compose",
"-f",
"devcontainer-example/docker-compose.yml",
"--project-name",
project,
"up",
"-d",
],
cwd=os.path.join(os.getcwd(), "../frappe_docker"),
check=True,
)
cprint(
"Please go through the Development Documentation: https://github.com/frappe/frappe_docker/tree/main/development to fully complete the setup.",
level=2,
)
logging.info("Development Setup completed")
except Exception as e:
logging.error("Dev Environment setup failed", exc_info=True)
cprint("Setting Up Development Environment Failed\n", e)
else:
install_docker()
clone_frappe_docker_repo()
setup_dev_instance(project) # Recursion on goes brrrr
def install_docker():
if which("docker") is not None:
return
cprint("Docker is not installed, Installing Docker...", level=3)
logging.info("Docker not found, installing Docker")
if platform.system() == "Darwin" or platform.system() == "Windows":
print(
f"""
This script doesn't install Docker on {"Mac" if platform.system()=="Darwin" else "Windows"}.
Please go through the Docker Installation docs for your system and run this script again"""
)
logging.debug("Docker setup failed due to platform is not Linux")
sys.exit(1)
try:
ps = subprocess.run(
["curl", "-fsSL", "https://get.docker.com"],
capture_output=True,
check=True,
)
subprocess.run(["/bin/bash"], input=ps.stdout, capture_output=True)
subprocess.run(
["sudo", "usermod", "-aG", "docker", str(os.getenv("USER"))], check=True
)
cprint("Waiting Docker to start", level=3)
time.sleep(10)
subprocess.run(["sudo", "systemctl", "restart", "docker.service"], check=True)
except Exception as e:
logging.error("Installing Docker failed", exc_info=True)
cprint("Failed to Install Docker\n", e)
cprint("\n Try Installing Docker Manually and re-run this script again\n")
sys.exit(1)
def create_site(
sitename: str,
project: str,
db_pass: str,
admin_pass: str,
):
cprint(f"\nCreating site: {sitename} \n", level=3)
try:
subprocess.run(
[
which("docker"),
"compose",
"-p",
project,
"exec",
"backend",
"bench",
"new-site",
sitename,
"--no-mariadb-socket",
"--db-root-password",
db_pass,
"--admin-password",
admin_pass,
"--install-app",
"erpnext",
"--set-default",
],
check=True,
)
logging.info("New site creation completed")
except Exception as e:
logging.error(f"Bench site creation failed for {sitename}", exc_info=True)
cprint(f"Bench Site creation failed for {sitename}\n", e)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Install Frappe with Docker")
parser.add_argument(
"-p", "--prod", help="Setup Production System", action="store_true"
)
parser.add_argument(
"-d", "--dev", help="Setup Development System", action="store_true"
)
parser.add_argument(
"-s",
"--sitename",
help="Site Name(s) for your production bench",
default=[],
action="append",
dest="sites",
)
parser.add_argument("-n", "--project", help="Project Name", default="frappe")
parser.add_argument("-i", "--image", help="Full Image Name")
parser.add_argument(
"--email", help="Add email for the SSL.", required="--prod" in sys.argv
)
parser.add_argument(
"-v", "--version", help="ERPNext version to install, defaults to latest stable"
)
args = parser.parse_args()
if args.dev:
cprint("\nSetting Up Development Instance\n", level=2)
logging.info("Running Development Setup")
setup_dev_instance(args.project)
elif args.prod:
cprint("\nSetting Up Production Instance\n", level=2)
logging.info("Running Production Setup")
if "example.com" in args.email:
cprint("Emails with example.com not acceptable", level=1)
sys.exit(1)
setup_prod(args.project, args.sites, args.email, args.version, args.image)
else:
parser.print_help()

View File

@ -131,11 +131,9 @@ COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe
WORKDIR /home/frappe/frappe-bench
VOLUME [ \
"/home/frappe/frappe-bench/sites", \
"/home/frappe/frappe-bench/sites/assets", \
"/home/frappe/frappe-bench/logs" \
]
# Move the generated assets folder out of the "sites" folder, which will be attached to a volume and thus persisted
# So that it can be referenced by symlink even after "sites" is replaced with the volume
RUN mv /home/frappe/frappe-bench/sites/assets /home/frappe/frappe-bench/assets
CMD [ \
"/home/frappe/frappe-bench/env/bin/gunicorn", \

View File

@ -93,13 +93,19 @@ RUN apt-get update \
gcc \
build-essential \
libbz2-dev \
# for erpnext repo
openssh-ssh \
&& rm -rf /var/lib/apt/lists/*
USER frappe
ARG SSH_PRIVATE_KEY
RUN mkdir ~/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_ed25519
ARG FRAPPE_BRANCH=version-15
ARG FRAPPE_PATH=https://github.com/frappe/frappe
ARG ERPNEXT_REPO=https://github.com/frappe/erpnext
ARG ERPNEXT_REPO=ssh://git@githaven.org:2222/Shiloh/brotherton-erpnext.git
ARG ERPNEXT_BRANCH=version-15
RUN bench init \
--frappe-branch=${FRAPPE_BRANCH} \
@ -118,6 +124,8 @@ FROM base as erpnext
USER frappe
RUN mkdir testFolder
COPY --from=builder --chown=frappe:frappe /home/frappe/frappe-bench /home/frappe/frappe-bench
WORKDIR /home/frappe/frappe-bench

View File

@ -1 +1 @@
pytest==8.1.1
pytest==8.1.0