From 7106124a0741eae3e9b14ea9f66b48a37c48e596 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Sat, 27 Jun 2020 23:44:13 +0530 Subject: [PATCH] refactor: reuse Dockerfile(s) --- build/erpnext-nginx/Dockerfile | 8 ++-- build/erpnext-nginx/v11.Dockerfile | 16 ------- build/erpnext-nginx/v12.Dockerfile | 16 ------- build/erpnext-nginx/v13-beta.Dockerfile | 16 ------- build/erpnext-worker/Dockerfile | 6 ++- build/erpnext-worker/v11.Dockerfile | 3 -- build/erpnext-worker/v12.Dockerfile | 3 -- build/erpnext-worker/v13-beta.Dockerfile | 3 -- build/frappe-nginx/Dockerfile | 22 +++------- build/frappe-nginx/build.sh | 23 ++++++++++ build/frappe-nginx/v11.Dockerfile | 42 ------------------ build/frappe-nginx/v12.Dockerfile | 42 ------------------ build/frappe-nginx/v13-beta.Dockerfile | 52 ----------------------- build/frappe-socketio/Dockerfile | 28 ++++++------ build/frappe-socketio/health.js | 19 --------- build/frappe-socketio/v11.Dockerfile | 36 ---------------- build/frappe-socketio/v12.Dockerfile | 36 ---------------- build/frappe-socketio/v13-beta.Dockerfile | 36 ---------------- build/frappe-worker/Dockerfile | 31 +++++++++----- build/frappe-worker/v11.Dockerfile | 45 -------------------- build/frappe-worker/v12.Dockerfile | 48 --------------------- build/frappe-worker/v13-beta.Dockerfile | 48 --------------------- travis.py | 31 ++++++++------ 23 files changed, 90 insertions(+), 520 deletions(-) delete mode 100644 build/erpnext-nginx/v11.Dockerfile delete mode 100644 build/erpnext-nginx/v12.Dockerfile delete mode 100644 build/erpnext-nginx/v13-beta.Dockerfile delete mode 100644 build/erpnext-worker/v11.Dockerfile delete mode 100644 build/erpnext-worker/v12.Dockerfile delete mode 100644 build/erpnext-worker/v13-beta.Dockerfile create mode 100755 build/frappe-nginx/build.sh delete mode 100644 build/frappe-nginx/v11.Dockerfile delete mode 100644 build/frappe-nginx/v12.Dockerfile delete mode 100644 build/frappe-nginx/v13-beta.Dockerfile delete mode 100644 build/frappe-socketio/health.js delete mode 100644 build/frappe-socketio/v11.Dockerfile delete mode 100644 build/frappe-socketio/v12.Dockerfile delete mode 100644 build/frappe-socketio/v13-beta.Dockerfile delete mode 100644 build/frappe-worker/v11.Dockerfile delete mode 100644 build/frappe-worker/v12.Dockerfile delete mode 100644 build/frappe-worker/v13-beta.Dockerfile diff --git a/build/erpnext-nginx/Dockerfile b/build/erpnext-nginx/Dockerfile index 0bbd2dc6..7eb1d2e6 100644 --- a/build/erpnext-nginx/Dockerfile +++ b/build/erpnext-nginx/Dockerfile @@ -1,10 +1,12 @@ -FROM bitnami/node:12-prod +ARG NODE_IMAGE_TAG=12-prod +FROM bitnami/node:${NODE_IMAGE_TAG} COPY build/erpnext-nginx/install_app.sh /install_app -RUN /install_app erpnext https://github.com/frappe/erpnext +ARG GIT_BRANCH=develop +RUN /install_app erpnext https://github.com/frappe/erpnext ${GIT_BRANCH} -FROM frappe/frappe-nginx:develop +FROM frappe/frappe-nginx:${GIT_BRANCH} COPY --from=0 /home/frappe/frappe-bench/sites/ /var/www/html/ COPY --from=0 /rsync /rsync diff --git a/build/erpnext-nginx/v11.Dockerfile b/build/erpnext-nginx/v11.Dockerfile deleted file mode 100644 index be288a18..00000000 --- a/build/erpnext-nginx/v11.Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM bitnami/node:10-prod - -COPY build/erpnext-nginx/install_app.sh /install_app - -RUN /install_app erpnext https://github.com/frappe/erpnext version-11 - -FROM frappe/frappe-nginx:v11 - -COPY --from=0 /home/frappe/frappe-bench/sites/ /var/www/html/ -COPY --from=0 /rsync /rsync -RUN echo -n "\nerpnext" >> /var/www/html/apps.txt - -VOLUME [ "/assets" ] - -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/build/erpnext-nginx/v12.Dockerfile b/build/erpnext-nginx/v12.Dockerfile deleted file mode 100644 index 90f02904..00000000 --- a/build/erpnext-nginx/v12.Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM bitnami/node:12-prod - -COPY build/erpnext-nginx/install_app.sh /install_app - -RUN /install_app erpnext https://github.com/frappe/erpnext version-12 - -FROM frappe/frappe-nginx:v12 - -COPY --from=0 /home/frappe/frappe-bench/sites/ /var/www/html/ -COPY --from=0 /rsync /rsync -RUN echo -n "\nerpnext" >> /var/www/html/apps.txt - -VOLUME [ "/assets" ] - -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/build/erpnext-nginx/v13-beta.Dockerfile b/build/erpnext-nginx/v13-beta.Dockerfile deleted file mode 100644 index 952859aa..00000000 --- a/build/erpnext-nginx/v13-beta.Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM bitnami/node:12-prod - -COPY build/erpnext-nginx/install_app.sh /install_app - -RUN /install_app erpnext https://github.com/frappe/erpnext version-13-beta - -FROM frappe/frappe-nginx:v13-beta - -COPY --from=0 /home/frappe/frappe-bench/sites/ /var/www/html/ -COPY --from=0 /rsync /rsync -RUN echo -n "\nerpnext" >> /var/www/html/apps.txt - -VOLUME [ "/assets" ] - -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/build/erpnext-worker/Dockerfile b/build/erpnext-worker/Dockerfile index 88af72f6..32dd3348 100644 --- a/build/erpnext-worker/Dockerfile +++ b/build/erpnext-worker/Dockerfile @@ -1,3 +1,5 @@ -FROM frappe/frappe-worker:develop +ARG GIT_BRANCH=develop +FROM frappe/frappe-worker:${GIT_BRANCH}} -RUN install_app erpnext https://github.com/frappe/erpnext \ No newline at end of file +ARG GIT_BRANCH=develop +RUN install_app erpnext https://github.com/frappe/erpnext ${GIT_BRANCH} diff --git a/build/erpnext-worker/v11.Dockerfile b/build/erpnext-worker/v11.Dockerfile deleted file mode 100644 index b17c7aaa..00000000 --- a/build/erpnext-worker/v11.Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM frappe/frappe-worker:v11 - -RUN install_app erpnext https://github.com/frappe/erpnext version-11 \ No newline at end of file diff --git a/build/erpnext-worker/v12.Dockerfile b/build/erpnext-worker/v12.Dockerfile deleted file mode 100644 index 2bade604..00000000 --- a/build/erpnext-worker/v12.Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM frappe/frappe-worker:v12 - -RUN install_app erpnext https://github.com/frappe/erpnext version-12 \ No newline at end of file diff --git a/build/erpnext-worker/v13-beta.Dockerfile b/build/erpnext-worker/v13-beta.Dockerfile deleted file mode 100644 index cfb4ca08..00000000 --- a/build/erpnext-worker/v13-beta.Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM frappe/frappe-worker:v13-beta - -RUN install_app erpnext https://github.com/frappe/erpnext version-13-beta \ No newline at end of file diff --git a/build/frappe-nginx/Dockerfile b/build/frappe-nginx/Dockerfile index a4684140..fc17a7b6 100644 --- a/build/frappe-nginx/Dockerfile +++ b/build/frappe-nginx/Dockerfile @@ -1,4 +1,5 @@ -FROM bitnami/node:12-prod +ARG NODE_IMAGE_TAG=12-prod +FROM bitnami/node:${NODE_IMAGE_TAG} WORKDIR /home/frappe/frappe-bench RUN mkdir -p /home/frappe/frappe-bench/sites \ @@ -6,26 +7,17 @@ RUN mkdir -p /home/frappe/frappe-bench/sites \ RUN install_packages git +ARG GIT_BRANCH=develop RUN mkdir -p apps sites/assets/css \ && cd apps \ - && git clone --depth 1 https://github.com/frappe/frappe + && git clone --depth 1 https://github.com/frappe/frappe --branch $GIT_BRANCH COPY build/frappe-nginx/generate_standard_style_css.js \ /home/frappe/frappe-bench/apps/frappe/generate_standard_style_css.js -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && yarn \ - && yarn run production \ - && yarn add nunjucks -D \ - && node generate_standard_style_css.js \ - frappe/website/doctype/website_theme/website_theme_template.scss > \ - /home/frappe/standard_templates_string \ - && node generate_bootstrap_theme.js \ - /home/frappe/frappe-bench/sites/assets/css/standard_style.css \ - "$(cat /home/frappe/standard_templates_string)" \ - && rm -fr node_modules \ - && yarn install --production=true \ - && node --version \ +COPY build/frappe-nginx/build.sh /build.sh +RUN /build.sh +RUN node --version \ && npm --version \ && yarn --version diff --git a/build/frappe-nginx/build.sh b/build/frappe-nginx/build.sh new file mode 100755 index 00000000..370e2104 --- /dev/null +++ b/build/frappe-nginx/build.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +function nodeCleanUp() { + rm -fr node_modules + yarn install --production=true +} + +cd /home/frappe/frappe-bench/apps/frappe +yarn +yarn run production +yarn add nunjucks -D + +if [[ "$GIT_BRANCH" =~ ^(version-12|version-11)$ ]]; then + nodeCleanUp +else + node generate_standard_style_css.js \ + frappe/website/doctype/website_theme/website_theme_template.scss > \ + /home/frappe/standard_templates_string + node generate_bootstrap_theme.js \ + /home/frappe/frappe-bench/sites/assets/css/standard_style.css \ + "$(cat /home/frappe/standard_templates_string)" + nodeCleanUp +fi diff --git a/build/frappe-nginx/v11.Dockerfile b/build/frappe-nginx/v11.Dockerfile deleted file mode 100644 index a1852f8d..00000000 --- a/build/frappe-nginx/v11.Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -FROM bitnami/node:10-prod - -WORKDIR /home/frappe/frappe-bench -RUN mkdir -p /home/frappe/frappe-bench/sites \ - && echo "frappe" > /home/frappe/frappe-bench/sites/apps.txt - -RUN install_packages git - -RUN mkdir -p apps sites/assets \ - && cd apps \ - && git clone --depth 1 https://github.com/frappe/frappe --branch version-11 - -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && yarn \ - && yarn run production \ - && rm -fr node_modules \ - && yarn install --production=true \ - && node --version \ - && npm --version \ - && yarn --version - -RUN git clone --depth 1 https://github.com/frappe/bench /tmp/bench \ - && mkdir -p /var/www/error_pages \ - && cp -r /tmp/bench/bench/config/templates /var/www/error_pages - -RUN cp -R /home/frappe/frappe-bench/apps/frappe/frappe/public/* /home/frappe/frappe-bench/sites/assets/frappe \ - && cp -R /home/frappe/frappe-bench/apps/frappe/node_modules /home/frappe/frappe-bench/sites/assets/frappe/ - -FROM nginx:latest -COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ -COPY --from=0 /var/www/error_pages /var/www/ -COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/frappe-nginx/docker-entrypoint.sh / - -RUN apt-get update && apt-get install -y rsync && apt-get clean \ - && echo "#!/bin/bash" > /rsync \ - && chmod +x /rsync - -VOLUME [ "/assets" ] - -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/build/frappe-nginx/v12.Dockerfile b/build/frappe-nginx/v12.Dockerfile deleted file mode 100644 index c883ea4e..00000000 --- a/build/frappe-nginx/v12.Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -FROM bitnami/node:12-prod - -WORKDIR /home/frappe/frappe-bench -RUN mkdir -p /home/frappe/frappe-bench/sites \ - && echo "frappe" > /home/frappe/frappe-bench/sites/apps.txt - -RUN install_packages git - -RUN mkdir -p apps sites/assets \ - && cd apps \ - && git clone --depth 1 https://github.com/frappe/frappe --branch version-12 - -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && yarn \ - && yarn run production \ - && rm -fr node_modules \ - && yarn install --production=true \ - && node --version \ - && npm --version \ - && yarn --version - -RUN git clone --depth 1 https://github.com/frappe/bench /tmp/bench \ - && mkdir -p /var/www/error_pages \ - && cp -r /tmp/bench/bench/config/templates /var/www/error_pages - -RUN cp -R /home/frappe/frappe-bench/apps/frappe/frappe/public/* /home/frappe/frappe-bench/sites/assets/frappe \ - && cp -R /home/frappe/frappe-bench/apps/frappe/node_modules /home/frappe/frappe-bench/sites/assets/frappe/ - -FROM nginx:latest -COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ -COPY --from=0 /var/www/error_pages /var/www/ -COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/frappe-nginx/docker-entrypoint.sh / - -RUN apt-get update && apt-get install -y rsync && apt-get clean \ - && echo "#!/bin/bash" > /rsync \ - && chmod +x /rsync - -VOLUME [ "/assets" ] - -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/build/frappe-nginx/v13-beta.Dockerfile b/build/frappe-nginx/v13-beta.Dockerfile deleted file mode 100644 index 1a6577bc..00000000 --- a/build/frappe-nginx/v13-beta.Dockerfile +++ /dev/null @@ -1,52 +0,0 @@ -FROM bitnami/node:12-prod - -WORKDIR /home/frappe/frappe-bench -RUN mkdir -p /home/frappe/frappe-bench/sites \ - && echo "frappe" > /home/frappe/frappe-bench/sites/apps.txt - -RUN install_packages git - -RUN mkdir -p apps sites/assets/css \ - && cd apps \ - && git clone --depth 1 https://github.com/frappe/frappe --branch version-13-beta - -COPY build/frappe-nginx/generate_standard_style_css.js \ - /home/frappe/frappe-bench/apps/frappe/generate_standard_style_css.js - -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && yarn \ - && yarn run production \ - && yarn add nunjucks -D \ - && node generate_standard_style_css.js \ - frappe/website/doctype/website_theme/website_theme_template.scss > \ - /home/frappe/standard_templates_string \ - && node generate_bootstrap_theme.js \ - /home/frappe/frappe-bench/sites/assets/css/standard_style.css \ - "$(cat /home/frappe/standard_templates_string)" \ - && rm -fr node_modules \ - && yarn install --production=true \ - && node --version \ - && npm --version \ - && yarn --version - -RUN git clone --depth 1 https://github.com/frappe/bench /tmp/bench \ - && mkdir -p /var/www/error_pages \ - && cp -r /tmp/bench/bench/config/templates /var/www/error_pages - -RUN cp -R /home/frappe/frappe-bench/apps/frappe/frappe/public/* /home/frappe/frappe-bench/sites/assets/frappe \ - && cp -R /home/frappe/frappe-bench/apps/frappe/node_modules /home/frappe/frappe-bench/sites/assets/frappe/ - -FROM nginx:latest -COPY --from=0 /home/frappe/frappe-bench/sites /var/www/html/ -COPY --from=0 /var/www/error_pages /var/www/ -COPY build/common/nginx-default.conf.template /etc/nginx/conf.d/default.conf.template -COPY build/frappe-nginx/docker-entrypoint.sh / - -RUN apt-get update && apt-get install -y rsync && apt-get clean \ - && echo "#!/bin/bash" > /rsync \ - && chmod +x /rsync - -VOLUME [ "/assets" ] - -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/build/frappe-socketio/Dockerfile b/build/frappe-socketio/Dockerfile index da9462c1..9455dbd7 100644 --- a/build/frappe-socketio/Dockerfile +++ b/build/frappe-socketio/Dockerfile @@ -1,31 +1,29 @@ FROM node:slim -# Install needed packages -RUN apt-get update && apt-get install -y curl && apt-get clean - +# Add frappe user RUN useradd -ms /bin/bash frappe -# Make bench directories -RUN mkdir -p /home/frappe/frappe-bench/sites /home/frappe/frappe-bench/apps/frappe +# Create bench directories and set ownership +RUN mkdir -p /home/frappe/frappe-bench/sites /home/frappe/frappe-bench/apps/frappe \ + && chown -R frappe:frappe /home/frappe +# Download socketio and purge curl package COPY build/frappe-socketio/package.json /home/frappe/frappe-bench/apps/frappe - - -# get socketio -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && curl https://raw.githubusercontent.com/frappe/frappe/develop/socketio.js \ +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/develop/node_utils.js \ - --output /home/frappe/frappe-bench/apps/frappe/node_utils.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/* RUN cd /home/frappe/frappe-bench/apps/frappe \ && npm install --only=production \ && node --version \ && npm --version -COPY build/frappe-socketio/health.js /home/frappe/frappe-bench/apps/frappe/health.js -RUN chown -R frappe:frappe /home/frappe - # Setup docker-entrypoint COPY build/frappe-socketio/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat diff --git a/build/frappe-socketio/health.js b/build/frappe-socketio/health.js deleted file mode 100644 index b85981bd..00000000 --- a/build/frappe-socketio/health.js +++ /dev/null @@ -1,19 +0,0 @@ -var net = require('net'); -var { get_conf } = require('./node_utils'); - -var conf = get_conf(); -var server = ['localhost', conf.socketio_port || 9000]; - -var sock = new net.Socket(); -sock.setTimeout(2500); -sock.on('connect', function() { - console.info(server[0]+':'+server[1]+' is up.'); - sock.destroy(); - process.exit(); -}).on('error', function(e) { - console.error(server[0]+':'+server[1]+' is down: ' + e.message); - process.exit(1); -}).on('timeout', function(e) { - console.error(server[0]+':'+server[1]+' is down: timeout'); - process.exit(1); -}).connect(server[1], server[0]); diff --git a/build/frappe-socketio/v11.Dockerfile b/build/frappe-socketio/v11.Dockerfile deleted file mode 100644 index ed3885fc..00000000 --- a/build/frappe-socketio/v11.Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM node:slim - -# Install needed packages -RUN apt-get update && apt-get install -y curl && apt-get clean - -RUN useradd -ms /bin/bash frappe - -# Make bench directories -RUN mkdir -p /home/frappe/frappe-bench/sites /home/frappe/frappe-bench/apps/frappe - -COPY build/frappe-socketio/package.json /home/frappe/frappe-bench/apps/frappe - - -# get socketio -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && curl https://raw.githubusercontent.com/frappe/frappe/version-11/socketio.js \ - --output /home/frappe/frappe-bench/apps/frappe/socketio.js \ - && curl https://raw.githubusercontent.com/frappe/frappe/version-11/node_utils.js \ - --output /home/frappe/frappe-bench/apps/frappe/node_utils.js - -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && npm install --only=production \ - && node --version \ - && npm --version - -COPY build/frappe-socketio/health.js /home/frappe/frappe-bench/apps/frappe/health.js -RUN chown -R frappe:frappe /home/frappe - -# Setup docker-entrypoint -COPY build/frappe-socketio/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat - -WORKDIR /home/frappe/frappe-bench/sites - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["start"] diff --git a/build/frappe-socketio/v12.Dockerfile b/build/frappe-socketio/v12.Dockerfile deleted file mode 100644 index e0cf42b8..00000000 --- a/build/frappe-socketio/v12.Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM node:slim - -# Install needed packages -RUN apt-get update && apt-get install -y curl && apt-get clean - -RUN useradd -ms /bin/bash frappe - -# Make bench directories -RUN mkdir -p /home/frappe/frappe-bench/sites /home/frappe/frappe-bench/apps/frappe - -COPY build/frappe-socketio/package.json /home/frappe/frappe-bench/apps/frappe - - -# get socketio -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && curl https://raw.githubusercontent.com/frappe/frappe/version-12/socketio.js \ - --output /home/frappe/frappe-bench/apps/frappe/socketio.js \ - && curl https://raw.githubusercontent.com/frappe/frappe/version-12/node_utils.js \ - --output /home/frappe/frappe-bench/apps/frappe/node_utils.js - -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && npm install --only=production \ - && node --version \ - && npm --version - -COPY build/frappe-socketio/health.js /home/frappe/frappe-bench/apps/frappe/health.js -RUN chown -R frappe:frappe /home/frappe - -# Setup docker-entrypoint -COPY build/frappe-socketio/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat - -WORKDIR /home/frappe/frappe-bench/sites - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["start"] diff --git a/build/frappe-socketio/v13-beta.Dockerfile b/build/frappe-socketio/v13-beta.Dockerfile deleted file mode 100644 index 4ae4f7ea..00000000 --- a/build/frappe-socketio/v13-beta.Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -FROM node:slim - -# Install needed packages -RUN apt-get update && apt-get install -y curl && apt-get clean - -RUN useradd -ms /bin/bash frappe - -# Make bench directories -RUN mkdir -p /home/frappe/frappe-bench/sites /home/frappe/frappe-bench/apps/frappe - -COPY build/frappe-socketio/package.json /home/frappe/frappe-bench/apps/frappe - - -# get socketio -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && curl https://raw.githubusercontent.com/frappe/frappe/version-13-beta/socketio.js \ - --output /home/frappe/frappe-bench/apps/frappe/socketio.js \ - && curl https://raw.githubusercontent.com/frappe/frappe/version-13-beta/node_utils.js \ - --output /home/frappe/frappe-bench/apps/frappe/node_utils.js - -RUN cd /home/frappe/frappe-bench/apps/frappe \ - && npm install --only=production \ - && node --version \ - && npm --version - -COPY build/frappe-socketio/health.js /home/frappe/frappe-bench/apps/frappe/health.js -RUN chown -R frappe:frappe /home/frappe - -# Setup docker-entrypoint -COPY build/frappe-socketio/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat - -WORKDIR /home/frappe/frappe-bench/sites - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["start"] diff --git a/build/frappe-worker/Dockerfile b/build/frappe-worker/Dockerfile index 33e034ec..3e8190b5 100644 --- a/build/frappe-worker/Dockerfile +++ b/build/frappe-worker/Dockerfile @@ -1,45 +1,56 @@ -FROM bitnami/python:latest-prod +FROM bitnami/python:3.7-prod RUN useradd -ms /bin/bash frappe + +ARG GIT_BRANCH=develop + +# Install dependencies WORKDIR /home/frappe/frappe-bench RUN install_packages \ git \ - wkhtmltopdf \ mariadb-client \ + postgresql-client \ gettext-base \ wget \ # for PDF + libjpeg62-turbo \ + libx11-6 \ + libxcb1 \ + libxext6 \ + libxrender1 \ libssl-dev \ fonts-cantarell \ xfonts-75dpi \ xfonts-base \ # For psycopg2 libpq-dev \ - build-essential - -# Install wkhtmltox correctly -RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb -RUN dpkg -i wkhtmltox_0.12.5-1.buster_amd64.deb && rm wkhtmltox_0.12.5-1.buster_amd64.deb + && wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb \ + && dpkg -i wkhtmltox_0.12.5-1.buster_amd64.deb && rm wkhtmltox_0.12.5-1.buster_amd64.deb \ + && apt-get purge -y wget && apt-get autoremove -y +# Create frappe-bench directories RUN mkdir -p apps logs commands /home/frappe/backups +# Setup python environment RUN virtualenv env \ && . env/bin/activate \ && cd apps \ - && git clone --depth 1 -o upstream https://github.com/frappe/frappe \ + && git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch ${GIT_BRANCH} \ && pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe +# Copy scripts and templates COPY build/common/commands/* /home/frappe/frappe-bench/commands/ COPY build/common/common_site_config.json.template /opt/frappe/common_site_config.json.template +COPY build/common/worker/install_app.sh /usr/local/bin/install_app # Setup docker-entrypoint COPY build/common/worker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat -COPY build/common/worker/install_app.sh /usr/local/bin/install_app - +# Use sites volume as working directory WORKDIR /home/frappe/frappe-bench/sites +# Set ownership of sites directory RUN chown -R frappe:frappe /home/frappe/frappe-bench/sites /home/frappe/backups VOLUME [ "/home/frappe/frappe-bench/sites", "/home/frappe/backups" ] diff --git a/build/frappe-worker/v11.Dockerfile b/build/frappe-worker/v11.Dockerfile deleted file mode 100644 index 055db258..00000000 --- a/build/frappe-worker/v11.Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -FROM bitnami/python:latest-prod - -RUN useradd -ms /bin/bash frappe -WORKDIR /home/frappe/frappe-bench -RUN install_packages \ - git \ - wkhtmltopdf \ - mariadb-client \ - gettext-base \ - wget \ - # for PDF - libssl-dev \ - fonts-cantarell \ - xfonts-75dpi \ - xfonts-base - -# Install wkhtmltox correctly -RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb -RUN dpkg -i wkhtmltox_0.12.5-1.buster_amd64.deb && rm wkhtmltox_0.12.5-1.buster_amd64.deb - -RUN mkdir -p apps logs commands /home/frappe/backups - -RUN virtualenv env \ - && . env/bin/activate \ - && cd apps \ - && git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch version-11 \ - && pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe - -COPY build/common/commands/* /home/frappe/frappe-bench/commands/ -COPY build/common/common_site_config.json.template /opt/frappe/common_site_config.json.template - -# Setup docker-entrypoint -COPY build/common/worker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat - -COPY build/common/worker/install_app.sh /usr/local/bin/install_app - -WORKDIR /home/frappe/frappe-bench/sites - -RUN chown -R frappe:frappe /home/frappe/frappe-bench/sites /home/frappe/backups - -VOLUME [ "/home/frappe/frappe-bench/sites", "/home/frappe/backups" ] - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["start"] diff --git a/build/frappe-worker/v12.Dockerfile b/build/frappe-worker/v12.Dockerfile deleted file mode 100644 index 2e6a11f8..00000000 --- a/build/frappe-worker/v12.Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -FROM bitnami/python:latest-prod - -RUN useradd -ms /bin/bash frappe -WORKDIR /home/frappe/frappe-bench -RUN install_packages \ - git \ - wkhtmltopdf \ - mariadb-client \ - gettext-base \ - wget \ - # for PDF - libssl-dev \ - fonts-cantarell \ - xfonts-75dpi \ - xfonts-base \ - # For psycopg2 - libpq-dev \ - build-essential - -# Install wkhtmltox correctly -RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb -RUN dpkg -i wkhtmltox_0.12.5-1.buster_amd64.deb && rm wkhtmltox_0.12.5-1.buster_amd64.deb - -RUN mkdir -p apps logs commands /home/frappe/backups - -RUN virtualenv env \ - && . env/bin/activate \ - && cd apps \ - && git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch version-12 \ - && pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe - -COPY build/common/commands/* /home/frappe/frappe-bench/commands/ -COPY build/common/common_site_config.json.template /opt/frappe/common_site_config.json.template - -# Setup docker-entrypoint -COPY build/common/worker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat - -COPY build/common/worker/install_app.sh /usr/local/bin/install_app - -WORKDIR /home/frappe/frappe-bench/sites - -RUN chown -R frappe:frappe /home/frappe/frappe-bench/sites /home/frappe/backups - -VOLUME [ "/home/frappe/frappe-bench/sites", "/home/frappe/backups" ] - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["start"] diff --git a/build/frappe-worker/v13-beta.Dockerfile b/build/frappe-worker/v13-beta.Dockerfile deleted file mode 100644 index 1ea82ac4..00000000 --- a/build/frappe-worker/v13-beta.Dockerfile +++ /dev/null @@ -1,48 +0,0 @@ -FROM bitnami/python:latest-prod - -RUN useradd -ms /bin/bash frappe -WORKDIR /home/frappe/frappe-bench -RUN install_packages \ - git \ - wkhtmltopdf \ - mariadb-client \ - gettext-base \ - wget \ - # for PDF - libssl-dev \ - fonts-cantarell \ - xfonts-75dpi \ - xfonts-base \ - # For psycopg2 - libpq-dev \ - build-essential - -# Install wkhtmltox correctly -RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.buster_amd64.deb -RUN dpkg -i wkhtmltox_0.12.5-1.buster_amd64.deb && rm wkhtmltox_0.12.5-1.buster_amd64.deb - -RUN mkdir -p apps logs commands /home/frappe/backups - -RUN virtualenv env \ - && . env/bin/activate \ - && cd apps \ - && git clone --depth 1 -o upstream https://github.com/frappe/frappe --branch version-13-beta \ - && pip3 install --no-cache-dir -e /home/frappe/frappe-bench/apps/frappe - -COPY build/common/commands/* /home/frappe/frappe-bench/commands/ -COPY build/common/common_site_config.json.template /opt/frappe/common_site_config.json.template - -# Setup docker-entrypoint -COPY build/common/worker/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat - -COPY build/common/worker/install_app.sh /usr/local/bin/install_app - -WORKDIR /home/frappe/frappe-bench/sites - -RUN chown -R frappe:frappe /home/frappe/frappe-bench/sites /home/frappe/backups - -VOLUME [ "/home/frappe/frappe-bench/sites", "/home/frappe/backups" ] - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["start"] diff --git a/travis.py b/travis.py index a9cb936e..40edf5c5 100755 --- a/travis.py +++ b/travis.py @@ -15,14 +15,14 @@ image_type.add_argument('-s', '--socketio', action='store_const', dest='image_ty 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('-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() -def git_version(service, version): +def git_version(service, version, branch): print(f'Pulling {service} v{version}') - subprocess.run(f'git clone https://github.com/frappe/{service} --branch version-{version}', shell=True) + 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) @@ -34,9 +34,15 @@ def git_version(service, version): os.chdir(cd) return version_tag -def build(service, tag, image, dockerfile): - print(f'Building {service} {image} image using {dockerfile}') - subprocess.run(f'docker build -t {service}-{image} -f build/{service}-{image}/{dockerfile} .', shell=True) +def build(service, tag, image, branch): + build_args = '' + if branch != 'develop': + 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' + + 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): @@ -45,19 +51,16 @@ def tag_and_push(image_name, tag): subprocess.run(f'docker push frappe/{image_name}:{tag}', shell=True) def main(): - global tag - global dockerfile + tag = args.tag + branch = 'develop' if args.version: - tag = git_version(args.service, args.version) - dockerfile = f'v{args.version}.Dockerfile' - else: - tag = args.tag - dockerfile = 'Dockerfile' + branch = 'version-' + args.version + tag = git_version(args.service, args.version, branch) if args.tag_only: tag_and_push(f'{args.service}-{args.image_type}', tag) else: - build(args.service, tag, args.image_type, dockerfile) + build(args.service, tag, args.image_type, branch) main()