2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-12-23 18:48:58 +00:00

Merge pull request #476 from revant/feat

This commit is contained in:
Chinmay Pai 2021-05-21 19:10:37 +05:30 committed by GitHub
commit 5c3e8b1467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 150 additions and 69 deletions

View File

@ -1,5 +1,9 @@
# Frappe Bench Dockerfile
FROM debian:buster-slim
ARG GIT_REPO=https://github.com/frappe/bench.git
ARG GIT_BRANCH=develop
LABEL author=frappé
RUN apt-get update -y && apt-get install \
@ -71,7 +75,7 @@ WORKDIR /home/frappe
# Clone and install bench in the local user home directory
# For development, bench source is located in ~/.bench
RUN git clone https://github.com/frappe/bench.git .bench \
RUN git clone ${GIT_REPO} -b ${GIT_BRANCH} .bench \
&& pip3 install --user -e .bench
# Export python executables for Dockerfile
@ -87,13 +91,12 @@ RUN bash -c "bench --version"
# !!! UPDATE NODEJS PERIODICALLY WITH LATEST VERSIONS !!!
# https://nodejs.org/en/about/releases/
# https://nodejs.org/download/release/latest-v10.x/
# https://nodejs.org/download/release/latest-v12.x/
# https://nodejs.org/download/release/latest-v13.x/
ENV NODE_VERSION=12.20.0
ENV NODE_VERSION_FRAPPEV11=10.23.0
# https://nodejs.org/download/release/latest-v14.x/
ENV NODE_VERSION=14.17.0
ENV NODE_VERSION_FRAPPEV11=10.24.1
# Install nvm with node
RUN wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh
RUN wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh
RUN chmod +x install.sh
RUN ./install.sh
ENV NVM_DIR=/home/frappe/.nvm

View File

@ -1,9 +1,12 @@
ARG NODE_IMAGE_TAG=12-buster-slim
ARG GIT_BRANCH=develop
ARG NODE_IMAGE_TAG=14-buster-slim
ARG DOCKER_REGISTRY_PREFIX=frappe
ARG IMAGE_TAG=develop
FROM node:${NODE_IMAGE_TAG}
ARG GIT_BRANCH
ARG GIT_REPO=https://github.com/frappe/erpnext
ARG GIT_BRANCH=develop
COPY build/erpnext-nginx/install_app.sh /install_app
RUN chmod +x /install_app && \
apt-get update -y && \
@ -11,9 +14,9 @@ RUN chmod +x /install_app && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN /install_app erpnext https://github.com/frappe/erpnext ${GIT_BRANCH}
RUN /install_app erpnext ${GIT_REPO} ${GIT_BRANCH}
FROM ${DOCKER_REGISTRY_PREFIX}/frappe-nginx:${GIT_BRANCH}
FROM ${DOCKER_REGISTRY_PREFIX}/frappe-nginx:${IMAGE_TAG}
COPY --from=0 /home/frappe/frappe-bench/sites/ /var/www/html/
COPY --from=0 /rsync /rsync

View File

@ -1,6 +1,8 @@
ARG GIT_BRANCH=develop
ARG IMAGE_TAG=develop
ARG DOCKER_REGISTRY_PREFIX=frappe
FROM ${DOCKER_REGISTRY_PREFIX}/frappe-worker:${GIT_BRANCH}
FROM ${DOCKER_REGISTRY_PREFIX}/frappe-worker:${IMAGE_TAG}
ARG GIT_BRANCH
RUN install_app erpnext https://github.com/frappe/erpnext ${GIT_BRANCH}
ARG GIT_REPO=https://github.com/frappe/erpnext
ARG GIT_BRANCH=develop
RUN install_app erpnext ${GIT_REPO} ${GIT_BRANCH}

View File

@ -4,14 +4,17 @@
# by Website Manager role in Frappe Framework
FROM python:3.7-slim-buster
ARG GIT_REPO=https://github.com/frappe/frappe
ARG GIT_BRANCH=develop
ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=12.20.0
ENV NODE_VERSION=14.17.0
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN apt-get update -y \
&& apt-get install wget python2 git build-essential -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh \
&& wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh \
&& chmod +x install.sh \
&& ./install.sh \
&& . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} \
@ -21,10 +24,9 @@ WORKDIR /home/frappe/frappe-bench
RUN mkdir -p /home/frappe/frappe-bench/sites \
&& echo "frappe" > /home/frappe/frappe-bench/sites/apps.txt
ARG GIT_BRANCH=develop
RUN mkdir -p apps sites/assets/css \
&& cd apps \
&& git clone --depth 1 https://github.com/frappe/frappe --branch $GIT_BRANCH
&& git clone --depth 1 ${GIT_REPO} --branch $GIT_BRANCH
RUN cd /home/frappe/frappe-bench/apps/frappe \
&& yarn \

View File

@ -6,9 +6,8 @@
set -e
rsync -a --delete /var/www/html/assets/js /assets
rsync -a --delete /var/www/html/assets/css /assets
rsync -a --delete /var/www/html/assets/frappe /assets
rsync -a --delete /var/www/html/assets/* /assets
. /rsync
touch /var/www/html/sites/.build -r $(ls -td /assets/* | head -n 1)

View File

@ -1,3 +1,10 @@
FROM alpine/git
ARG GIT_REPO=https://github.com/frappe/frappe.git
ARG GIT_BRANCH=develop
RUN git clone ${GIT_REPO} /opt/frappe -b ${GIT_BRANCH} --depth 1
FROM node:buster-slim
# Add frappe user
@ -9,15 +16,8 @@ RUN mkdir -p /home/frappe/frappe-bench/sites /home/frappe/frappe-bench/apps/frap
# Download socketio and purge curl package
COPY build/frappe-socketio/package.json /home/frappe/frappe-bench/apps/frappe
ARG GIT_BRANCH=develop
RUN apt-get update && apt-get install -y curl \
&& cd /home/frappe/frappe-bench/apps/frappe \
&& curl "https://raw.githubusercontent.com/frappe/frappe/$GIT_BRANCH/socketio.js" \
--output /home/frappe/frappe-bench/apps/frappe/socketio.js \
&& curl "https://raw.githubusercontent.com/frappe/frappe/$GIT_BRANCH/node_utils.js" \
--output /home/frappe/frappe-bench/apps/frappe/node_utils.js \
&& apt-get purge -y curl && apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
COPY --from=0 /opt/frappe/socketio.js /home/frappe/frappe-bench/apps/frappe/socketio.js
COPY --from=0 /opt/frappe/node_utils.js /home/frappe/frappe-bench/apps/frappe/node_utils.js
RUN cd /home/frappe/frappe-bench/apps/frappe \
&& npm install --only=production \

View File

@ -1,6 +1,6 @@
{
"name": "frappe-socketio",
"version": "1.0.0",
"version": "1.0.1",
"description": "Frappe SocketIO Server",
"main": "socketio.js",
"scripts": {
@ -10,8 +10,8 @@
"license": "MIT",
"dependencies": {
"express": "^4.17.1",
"redis": "^2.8.0",
"socket.io": "^2.3.0",
"redis": "^3.1.1",
"socket.io": "^2.4.0",
"superagent": "^5.1.0"
}
}

View File

@ -3,11 +3,12 @@ FROM python:3.7-slim-buster
# Add non root user without password
RUN useradd -ms /bin/bash frappe
ARG GIT_REPO=https://github.com/frappe/frappe
ARG GIT_BRANCH=develop
ARG ARCH=amd64
ENV PYTHONUNBUFFERED 1
ENV NVM_DIR=/home/frappe/.nvm
ENV NODE_VERSION=12.20.0
ENV NODE_VERSION=14.17.0
ENV PATH="/home/frappe/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
# Install dependencies
@ -44,7 +45,7 @@ RUN apt-get update -y && apt-get install \
&& if [ `uname -m` = 'x86_64' ]; then export ARCH=amd64; fi \
&& wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_${ARCH}.deb \
&& dpkg -i wkhtmltox_0.12.6-1.buster_${ARCH}.deb && rm wkhtmltox_0.12.6-1.buster_${ARCH}.deb \
&& wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh \
&& wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh \
&& chown -R frappe:frappe /home/frappe
# Setup docker-entrypoint
@ -68,7 +69,7 @@ RUN python -m venv env \
&& pip3 install --upgrade pip \
&& pip3 install gevent \
&& cd apps \
&& git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch ${GIT_BRANCH} \
&& git clone --depth 1 -o upstream ${GIT_REPO} --branch ${GIT_BRANCH} \
&& pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe
# Copy scripts and templates

View File

@ -12,7 +12,6 @@
"args": [
"frappe", "serve", "--port", "8000", "--noreload", "--nothreading"
],
"pythonPath": "${workspaceFolder}/frappe-bench/env/bin/python",
"cwd": "${workspaceFolder}/frappe-bench/sites",
"env": {
"DEV_SERVER": "1"
@ -26,7 +25,6 @@
"args": [
"frappe", "worker", "--queue", "default"
],
"pythonPath": "${workspaceFolder}/frappe-bench/env/bin/python",
"cwd": "${workspaceFolder}/frappe-bench/sites",
"env": {
"DEV_SERVER": "1"
@ -40,7 +38,6 @@
"args": [
"frappe", "worker", "--queue", "short"
],
"pythonPath": "${workspaceFolder}/frappe-bench/env/bin/python",
"cwd": "${workspaceFolder}/frappe-bench/sites",
"env": {
"DEV_SERVER": "1"
@ -54,7 +51,6 @@
"args": [
"frappe", "worker", "--queue", "long"
],
"pythonPath": "${workspaceFolder}/frappe-bench/env/bin/python",
"cwd": "${workspaceFolder}/frappe-bench/sites",
"env": {
"DEV_SERVER": "1"
@ -64,7 +60,6 @@
"name": "Honcho SocketIO Watch Schedule Worker",
"type": "python",
"request": "launch",
"pythonPath": "/usr/bin/python3",
"program": "/home/frappe/.local/bin/honcho",
"cwd": "${workspaceFolder}/frappe-bench",
"console": "internalConsole",

View File

@ -59,6 +59,7 @@ services:
- REDIS_SOCKETIO=redis-socketio:6379
- SOCKETIO_PORT=9000
- AUTO_MIGRATE=1
- WORKER_CLASS=${WORKER_CLASS}
volumes:
- sites-vol:/home/frappe/frappe-bench/sites:rw
- assets-vol:/home/frappe/frappe-bench/sites/assets:rw

View File

@ -15,3 +15,4 @@ HTTPS_REDIRECT_ENTRYPOINT_LABEL=erpnext.local.no-entrypoint
HTTPS_REDIRECT_MIDDLEWARE_LABEL=erpnext.local.no-middleware
HTTPS_USE_REDIRECT_MIDDLEWARE_LABEL=erpnext.local-no-redirect-middleware
SKIP_NGINX_TEMPLATE_GENERATION=0
WORKER_CLASS=gthread

View File

@ -15,3 +15,4 @@ HTTPS_REDIRECT_ENTRYPOINT_LABEL=traefik.http.routers.http-catchall.entrypoints=w
HTTPS_REDIRECT_MIDDLEWARE_LABEL=traefik.http.routers.http-catchall.middlewares=redirect-to-https
HTTPS_USE_REDIRECT_MIDDLEWARE_LABEL=traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
SKIP_NGINX_TEMPLATE_GENERATION=0
WORKER_CLASS=gthread

127
travis.py
View File

@ -4,37 +4,104 @@ import argparse
import subprocess
import os
def parse_args():
parser = argparse.ArgumentParser(description='frappe_docker common CI elements', add_help=True)
parser.add_argument('service', action='store', type=str, help='Name of the service to build: "erpnext" or "frappe"')
parser.add_argument('-o', '--tag-only', required=False, action='store_true', dest='tag_only', help='Only tag an image and push it.')
parser.add_argument('-b', '--is-beta', required=False, default=False, action='store_true', dest='is_beta', help='Specify if tag is beta')
def parse_args():
parser = argparse.ArgumentParser(
description="frappe_docker common CI elements", add_help=True
)
parser.add_argument(
"service",
action="store",
type=str,
help='Name of the service to build: "erpnext" or "frappe"',
)
parser.add_argument(
"-o",
"--tag-only",
required=False,
action="store_true",
dest="tag_only",
help="Only tag an image and push it.",
)
parser.add_argument(
"-b",
"--is-beta",
required=False,
default=False,
action="store_true",
dest="is_beta",
help="Specify if tag is beta",
)
image_type = parser.add_mutually_exclusive_group(required=True)
image_type.add_argument('-a', '--nginx', action='store_const', dest='image_type', const='nginx', help='Build the nginx + static assets image')
image_type.add_argument('-s', '--socketio', action='store_const', dest='image_type', const='socketio', help='Build the frappe-socketio image')
image_type.add_argument('-w', '--worker', action='store_const', dest='image_type', const='worker', help='Build the python environment image')
image_type.add_argument(
"-a",
"--nginx",
action="store_const",
dest="image_type",
const="nginx",
help="Build the nginx + static assets image",
)
image_type.add_argument(
"-s",
"--socketio",
action="store_const",
dest="image_type",
const="socketio",
help="Build the frappe-socketio image",
)
image_type.add_argument(
"-w",
"--worker",
action="store_const",
dest="image_type",
const="worker",
help="Build the python environment image",
)
tag_type = parser.add_mutually_exclusive_group(required=True)
tag_type.add_argument('-g', '--git-version', action='store', type=str, dest='version', help='The version number of service (i.e. "11", "12", etc.)')
tag_type.add_argument('-t', '--tag', action='store', type=str, dest='tag', help='The image tag (i.e. erpnext-worker:$TAG )')
tag_type.add_argument(
"-g",
"--git-version",
action="store",
type=str,
dest="version",
help='The version number of service (i.e. "11", "12", etc.)',
)
tag_type.add_argument(
"-t",
"--tag",
action="store",
type=str,
dest="tag",
help="The image tag (i.e. erpnext-worker:$TAG )",
)
args = parser.parse_args()
return args
def git_version(service, version, branch, is_beta=False):
print(f'Pulling {service} v{version}')
subprocess.run(f'git clone https://github.com/frappe/{service} --branch {branch}', shell=True)
print(f"Pulling {service} v{version}")
subprocess.run(
f"git clone https://github.com/frappe/{service} --branch {branch}", shell=True
)
cd = os.getcwd()
os.chdir(os.getcwd() + f'/{service}')
subprocess.run('git fetch --tags', shell=True)
os.chdir(os.getcwd() + f"/{service}")
subprocess.run("git fetch --tags", shell=True)
# XX-beta becomes XX for tags search
version = version.split('-')[0]
version = version.split("-")[0]
version_tag = subprocess.check_output(f'git tag --list --sort=-version:refname "v{version}*" | sed -n 1p | sed -e \'s#.*@\(\)#\\1#\'', shell=True).strip().decode('ascii')
version_tag = (
subprocess.check_output(
f"git tag --list --sort=-version:refname \"v{version}*\" | sed -n 1p | sed -e 's#.*@\(\)#\\1#'",
shell=True,
)
.strip()
.decode("ascii")
)
if not is_beta:
version_tag = version_tag.split("-")[0]
@ -44,34 +111,40 @@ def git_version(service, version, branch, is_beta=False):
def build(service, tag, image, branch):
build_args = f'--build-arg GIT_BRANCH={branch}'
if service == 'nginx' and branch == 'version-11':
build_args += f' --build-arg NODE_IMAGE_TAG=10-prod'
build_args = f"--build-arg GIT_BRANCH={branch}"
if service == "erpnext":
build_args += f" --build-arg IMAGE_TAG={branch}"
if image == "nginx" and branch == "version-11":
build_args += f" --build-arg NODE_IMAGE_TAG=10-prod"
print(f'Building {service} {image} image')
subprocess.run(f'docker build {build_args} -t {service}-{image} -f build/{service}-{image}/Dockerfile .', shell=True)
tag_and_push(f'{service}-{image}', tag)
print(f"Building {service} {image} image")
subprocess.run(
f"docker build {build_args} -t {service}-{image} -f build/{service}-{image}/Dockerfile .",
shell=True,
)
tag_and_push(f"{service}-{image}", tag)
def tag_and_push(image_name, tag):
print(f'Tagging {image_name} as "{tag}" and pushing')
subprocess.run(f'docker tag {image_name} frappe/{image_name}:{tag}', shell=True)
subprocess.run(f'docker push frappe/{image_name}:{tag}', shell=True)
subprocess.run(f"docker tag {image_name} frappe/{image_name}:{tag}", shell=True)
subprocess.run(f"docker push frappe/{image_name}:{tag}", shell=True)
def main():
args = parse_args()
tag = args.tag
branch = 'develop'
branch = "develop"
if args.version:
branch = 'version-' + args.version
branch = "version-" + args.version
tag = git_version(args.service, args.version, branch, args.is_beta)
if args.tag_only:
tag_and_push(f'{args.service}-{args.image_type}', tag)
tag_and_push(f"{args.service}-{args.image_type}", tag)
else:
build(args.service, tag, args.image_type, branch)
if __name__ == "__main__":
main()