Skip to content

Commit

Permalink
Merge pull request #118 from rtCamp/develop
Browse files Browse the repository at this point in the history
Bump v0.11.0
  • Loading branch information
Xieyt authored Feb 29, 2024
2 parents dfd6f8e + f928791 commit 0c39c54
Show file tree
Hide file tree
Showing 37 changed files with 1,532 additions and 454 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/bake-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish image

on:
schedule:
- cron: '0 2 * * *'
push:
tags:
- v*

jobs:
build-and-push:
name: Build and push image
strategy:
matrix:
os: [self-hosted-arm64,ubuntu-latest]
platform: [linux/amd64, linux/arm64]
service_name: [frappe, mailhog, nginx]
exclude:
- os: ubuntu-latest
platform: linux/arm64
- os: self-hosted-arm64
platform: linux/amd64

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up tag
id: set-tag
run: |
latest_tag=$(git describe --abbrev=0 --tags)
if [[ "${{ github.ref == 'refs/tags/v*' }}" == 'true' ]]; then
latest-tag=${GITHUB_REF/refs\/tags\//}
fi
owner=$( echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]' )
echo "Checkout: $latest_tag"
git checkout "$latest_tag"
tag=$( cat "$GITHUB_WORKSPACE/Docker/images-tag.json" | jq -rc .${{ matrix.service_name }})
echo "image_name=ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}:${tag}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ matrix.platform }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: Docker/${{ matrix.service_name }}/.
push: true
platforms: ${{ matrix.platform }}
tags: ${{ env.image_name }}
37 changes: 0 additions & 37 deletions .github/workflows/docker-push.yml

This file was deleted.

103 changes: 71 additions & 32 deletions Docker/frappe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ FROM ubuntu:22.04 as bench

LABEL author=rtCamp
LABEL org.opencontainers.image.source=https://github.com/rtcamp/Frappe-Manager

ARG PYTHON_VERSION=3.11.0
ARG PREBAKE_APPS='erpnext:version-15,hrms:version-15'
ARG PREBAKE_FRAPPE_BRANCH='version-15'

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
# For frappe framework
Expand All @@ -15,7 +18,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-instal
xfonts-75dpi \
xfonts-base \
libssl-dev \
fonts-cantarell \
fonts-cantarell \
libpangocairo-1.0-0 \
# to work inside the container
locales \
Expand Down Expand Up @@ -75,52 +78,61 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-instal
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales

# Detect arch and install wkhtmltopdf
ENV WKHTMLTOPDF_VERSION 0.12.6.1-3
RUN if [ "$(uname -m)" = "aarch64" ]; then export ARCH=arm64; fi \
&& if [ "$(uname -m)" = "x86_64" ]; then export ARCH=amd64; fi \
&& downloaded_file=wkhtmltox_$WKHTMLTOPDF_VERSION.jammy_${ARCH}.deb \
&& wget -q https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTMLTOPDF_VERSION/$downloaded_file \
&& dpkg -i $downloaded_file \
&& rm $downloaded_file
# setup user
RUN export NAME='frappe' && \
groupadd -g 1000 $NAME && \
useradd --no-log-init -r -m -u 1000 -g 1000 -G sudo -s /usr/bin/zsh -d /workspace "$NAME" && \
usermod -a -G tty "$NAME" && \
echo "$NAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

RUN echo PREBAKE_APPS="$PREBAKE_APPS" >> /prebake_info && echo PREBAKE_FRAPPE_BRANCH="$PREBAKE_FRAPPE_BRANCH" >> /prebake_info

# Install Python via pyenv
ENV PYENV_ROOT /opt/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

# for bench wrapper
ENV PATH /opt/user/.bin:${PATH}

# for nvm
ENV NODE_VERSION=18.17.0
ENV NVM_DIR /opt/.nvm
ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/:${PATH}

From bench as prebake

RUN chown -R frappe:frappe /opt

USER frappe

ENV USERZSHRC /opt/user/.zshrc
ENV USERPROFILE /opt/user/.profile

# From https://github.com/pyenv/pyenv#basic-github-checkout
WORKDIR /opt

RUN mkdir -p /opt/user && touch /opt/user/.profile
RUN mkdir -p /opt/user && touch /opt/user/.profile && ls -lah

ENV ZSH /opt/user/.oh-my-zsh
ENV DISABLE_UPDATE_PROMPT true

# install ohmyzsh
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended

RUN unset ZSH

COPY ./zshrc /opt/user/.zshrc
COPY --chown=frappe:frappe ./zshrc /opt/user/.zshrc

RUN git clone --depth 1 https://github.com/pyenv/pyenv.git .pyenv \
&& pyenv install $PYTHON_VERSION \
&& PYENV_VERSION=$PYTHON_VERSION pip install --no-cache-dir virtualenv \
&& pyenv global $PYTHON_VERSION \
&& echo 'export PYENV_ROOT="/opt/.pyenv"' >> "$USERZSHRC" \
&& echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> "$USERZSHRC" \
&& echo 'eval "$(pyenv init --path)"' >>"$USERZSHRC"
&& echo 'eval "$(pyenv init --path)"' >>"$USERZSHRC" \
# remove *.pyc and *.pyo as used here in official docker image to reduce size
# https://github.com/docker-library/python/blob/789d789e4a8db71d3d393667971c49b845ffdc3f/3.11/alpine3.19/Dockerfile#L106-L111
&& find /opt/.pyenv/versions -depth \( \( -type d -a \( -name test -o -name tests -o -name idle_test \) \) -o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name 'libpython*.a' \) \) \) -exec rm -rf '{}' + ;

RUN pip install frappe-bench

# Install Node via nvm
ENV NODE_VERSION=18.17.0

ENV NVM_DIR /opt/.nvm
ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/:${PATH}

RUN mkdir -p /opt/.nvm \
&& wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
&& . ${NVM_DIR}/nvm.sh \
Expand All @@ -133,28 +145,55 @@ RUN mkdir -p /opt/.nvm \
&& echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' >> "$USERZSHRC" \
&& echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$USERZSHRC"


RUN mkdir -p /workspace

WORKDIR /workspace

RUN mkdir -p /opt/user/.bin
ENV PATH /opt/user/.bin:${PATH}

RUN echo 'export PATH="/opt/user/.bin:$PATH"' >> "$USERZSHRC"

COPY ./supervisord.conf /opt/user/
COPY ./bench-dev-server /opt/user/
COPY ./frappe-dev.conf /opt/user/
COPY ./bench-wrapper.sh /opt/user/.bin/bench
COPY --chown=frappe:frappe ./supervisord.conf /opt/user/
COPY --chown=frappe:frappe ./frappe-dev.conf /opt/user/
COPY --chown=frappe:frappe --chmod=0755 ./bench-dev-watch.sh /opt/user/
COPY --chown=frappe:frappe --chmod=0755 ./bench-dev-server /opt/user/
COPY --chown=frappe:frappe --chmod=0755 ./bench-wrapper.sh /opt/user/.bin/bench

COPY ./entrypoint.sh /
COPY ./user-script.sh /scripts/
COPY ./launch.sh /scripts/
COPY ./divide-supervisor-conf.py /scripts/
COPY --chmod=0755 ./prebake.sh /scripts/
COPY --chmod=0755 ./helper-function.sh /scripts/
COPY --chmod=0755 ./divide-supervisor-conf.py /scripts/

RUN ls -lah /workspace && /scripts/prebake.sh && mv /workspace/frappe-bench/apps/* /workspace/

FROM bench as fm_image

# Detect arch and install wkhtmltopdf
ENV WKHTMLTOPDF_VERSION 0.12.6.1-3
RUN if [ "$(uname -m)" = "aarch64" ]; then export ARCH=arm64; fi \
&& if [ "$(uname -m)" = "x86_64" ]; then export ARCH=amd64; fi \
&& downloaded_file=wkhtmltox_$WKHTMLTOPDF_VERSION.jammy_${ARCH}.deb \
&& wget -q https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTMLTOPDF_VERSION/$downloaded_file \
&& dpkg -i $downloaded_file \
&& rm $downloaded_file

RUN mkdir -p /scripts

RUN sudo chmod +x /entrypoint.sh /scripts/user-script.sh /scripts/launch.sh /scripts/divide-supervisor-conf.py /opt/user/bench-dev-server /opt/user/.bin/bench
COPY --chmod=0755 ./entrypoint.sh /
COPY --chmod=0755 ./user-script.sh /scripts/
COPY --chmod=0755 ./launch.sh /scripts/
COPY --chmod=0755 ./divide-supervisor-conf.py /scripts/
COPY --chmod=0755 ./helper-function.sh /scripts/

RUN rm -rf /opt && mkdir -p /workspace /opt

WORKDIR /workspace

COPY --from=prebake --chown=frappe:frappe /workspace/frappe-bench /workspace/frappe-bench
COPY --from=prebake --chown=frappe:frappe /workspace/frappe /workspace/frappe-bench/apps/frappe
COPY --from=prebake --chown=frappe:frappe /workspace/erpnext /workspace/frappe-bench/apps/erpnext
COPY --from=prebake --chown=frappe:frappe /workspace/hrms /workspace/frappe-bench/apps/hrms
COPY --from=prebake --chown=frappe:frappe /opt/.pyenv /opt/.pyenv
COPY --from=prebake --chown=frappe:frappe /opt/.nvm /opt/.nvm
COPY --from=prebake --chown=frappe:frappe /opt/user /opt/user

ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
1 change: 1 addition & 0 deletions Docker/frappe/bench-dev-server
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
trap "kill -- -$$" EXIT
fuser -k 80/tcp
bench serve --port 80
3 changes: 3 additions & 0 deletions Docker/frappe/bench-dev-watch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
trap "kill -- -$$" EXIT
bench watch
14 changes: 10 additions & 4 deletions Docker/frappe/bench-wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/bash
after_command() {
supervisorctl -c /opt/user/supervisord.conf restart frappe-bench-dev:
restart_command() {
supervisorctl -c /opt/user/supervisord.conf restart frappe-bench-dev:
}
status_command() {
supervisorctl -c /opt/user/supervisord.conf status frappe-bench-dev:
}

if [[ "$@" =~ ^restart[[:space:]]* ]]; then
after_command
restart_command
elif [[ "$@" =~ ^status[[:space:]]* ]]; then
status_command
else
/opt/.pyenv/shims/bench "$@"
/opt/.pyenv/shims/bench "$@"
fi
15 changes: 5 additions & 10 deletions Docker/frappe/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source /scripts/helper-function.sh

emer() {
echo "$1"
exit 1
Expand All @@ -10,11 +12,7 @@ emer() {

echo "Setting up user"

NAME='frappe'
groupadd -g "$USERGROUP" $NAME
useradd --no-log-init -r -m -u "$USERID" -g "$USERGROUP" -G sudo -s /usr/bin/zsh -d /workspace "$NAME"
usermod -a -G tty "$NAME"
echo "$NAME ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
update_uid_gid "${USERID}" "${USERGROUP}" "frappe" "frappe"

mkdir -p /opt/user/conf.d

Expand All @@ -32,12 +30,9 @@ if [[ ! -f "/workspace/.profile" ]]; then
cat /opt/user/.profile > /workspace/.profile
fi

chown "$USERID":"$USERGROUP" /workspace /workspace/frappe-bench

if [[ ! -d '/workspace/frappe-bench' ]]; then
chown -R "$USERID":"$USERGROUP" /workspace
# find /workspace -type d -print0 | xargs -0 -n 200 -P "$(nproc)" chown "$USERID":"$USERGROUP"
# find /workspace -type f -print0 | xargs -0 -n 200 -P "$(nproc)" chown "$USERID":"$USERGROUP"
fi
ls -p /workspace | grep -v 'frappe-bench/' | xargs -I{} chown -R "$USERID":"$USERGROUP" /workspace{}


if [ "$#" -gt 0 ]; then
Expand Down
4 changes: 3 additions & 1 deletion Docker/frappe/frappe-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ user=frappe
directory=/workspace/frappe-bench

[program:frappe-bench-frappe-watch]
command=bench watch
command=/opt/user/bench-dev-watch.sh
priority=4
autostart=true
autorestart=false
stdout_logfile=/workspace/frappe-bench/logs/watch.dev.log
redirect_stderr=true
user=frappe
directory=/workspace/frappe-bench
stopasgroup=true
stopsignal=QUIT

[group:frappe-bench-dev]
programs=frappe-bench-frappe-dev,frappe-bench-frappe-watch
Loading

0 comments on commit 0c39c54

Please sign in to comment.