pipech / erpnext-docker-debian

:whale: Self-contained ERPNext Docker Image base on Debian
MIT License
197 stars 122 forks source link

Reducing Image Size #25

Closed pipech closed 5 years ago

pipech commented 6 years ago

I've tried.

It didn't works.

FROM debian:9.3

ENV systemUser=frappe \
    # set local
    LC_ALL=en_US.UTF-8 \
    LC_CTYPE=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    # frappe related env
    easyinstallRepo='https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py' \
    benchPath=bench-repo \
    benchRepo='https://github.com/frappe/bench' \
    benchBranch=master \
    frappeRepo='https://github.com/frappe/frappe' \
    frappeBranch=master \
    # for python 2 use = python
    # for python 3 use = python3 or python3.6 for centos
    pythonVersion=python \
    benchFolderName=bench \
    erpnextRepo='https://github.com/frappe/erpnext' \
    erpnextBranch=master \
    siteName=site1.local \
    branch=master \
    adminPass=12345 \
    mysqlPass=travis \
    # mysql remote user
    remoteUser=remote \
    remotePass=12345

# install prerequisite
RUN apt-get -y update \
    && apt-get -y install \
    build-essential \
    python-setuptools \
    curl \
    wget \
    nano \
    cron \
    gettext-base \
    sudo \
    locales \
    supervisor \
    nginx \
    && apt-get autoremove --purge \
    && apt-get clean \
    # work around for  "cmd": "chsh frappe -s $(which bash)", "stderr": "Password: chsh: PAM: Authentication failure"
    # caused by > bench/playbooks/create_user.yml > shell: "chsh {{ frappe_user }} -s $(which bash)"
    && sed -i 's/auth       required   pam_shells.so/auth       sufficient   pam_shells.so/' /etc/pam.d/chsh \
    # Set locales
    && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
    && locale-gen \
    # change user and workdir
    && adduser --disabled-password --gecos "" $systemUser \
    && usermod -aG sudo $systemUser \
    && echo "%sudo  ALL=(ALL)  NOPASSWD: ALL" > /etc/sudoers.d/sudoers \
    # install bench prerequisite
    && wget $easyinstallRepo \
    && python install.py \
    --without-bench-setup \
    --user $systemUser \
    # change directory
    && cd /home/$systemUser \
    # install bench & init bench folder
    && sudo -u $systemUser git clone --branch $benchBranch --depth 1 --origin upstream $benchRepo $benchPath  \
    && pip install -e $benchPath \
    && sudo -u $systemUser bench init $benchFolderName --frappe-path $frappeRepo --frappe-branch $frappeBranch --python $pythonVersion \
    # cd to bench folder and start mysql service
    && cd /home/$systemUser/$benchFolderName \
    && service mysql start \
    # create new site
    && sudo -u $systemUser bench new-site $siteName \
    --mariadb-root-password $mysqlPass  \
    --admin-password $adminPass \
    # install erpnext
    && sudo -u $systemUser bench get-app erpnext $erpnextRepo --branch $erpnextBranch \
    && sudo -u $systemUser bench --site $siteName install-app erpnext \
    # fix for Setup failed >> Could not start up: Error in setup
    && sudo -u $systemUser bench update --patch \
    # add mysql remote user, so we can connect to mysql inside container from host
    && mysql -u "root" "-p$mysqlPass" -e "CREATE USER '$remoteUser'@'%' IDENTIFIED BY '$remotePass';" \
    && mysql -u "root" "-p$mysqlPass" -e "GRANT ALL ON *.* TO '$remoteUser'@'%';" \
    # change back config for work around for  "cmd": "chsh frappe -s $(which bash)", "stderr": "Password: chsh: PAM: Authentication failure"
    && sed -i 's/auth       sufficient   pam_shells.so/auth       required   pam_shells.so/' /etc/pam.d/chsh

# set user and workdir
WORKDIR /home/$syste
mUser/$benchFolderName

# copy production config
COPY production_setup/conf/frappe-docker-conf /home/$systemUser/production_config
# fix for [docker Error response from daemon OCI runtime create failed starting container process caused "permission denied" unknown]
RUN sudo chmod +x /home/$systemUser/production_config/entrypoint_prd.sh

# run start mysql service when container start
COPY entrypoint.sh /usr/local/bin/
# fix for [docker Error response from daemon OCI runtime create failed starting container process caused "permission denied" unknown]
RUN sudo chmod +x /usr/local/bin/entrypoint.sh
CMD ["/usr/local/bin/entrypoint.sh"]

# expose port
EXPOSE 8000-8005 9000-9005 3306-3307
pipech commented 5 years ago

Detail disscus here. ERPNext Docker Image as an alternative to Official ERPNext Docker Repo