From 2b2503635f87235d1fc62dd56a01882690f27985 Mon Sep 17 00:00:00 2001 From: Bohdan Kucherivayi Date: Tue, 13 Feb 2024 21:41:40 +0200 Subject: [PATCH] feat: update configuration --- .env.example | 2 +- .github/workflows/production-image.yml | 43 +++++ compose.yaml | 11 +- docker-bake.hcl | 8 + docker-compose.yml | 211 +++++++++++++++++++++++++ images/custom/Containerfile | 20 ++- images/production/Containerfile | 28 ++-- resources/nginx-entrypoint.sh | 8 +- resources/nginx-template.conf | 1 - 9 files changed, 304 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/production-image.yml create mode 100644 docker-compose.yml diff --git a/.env.example b/.env.example index 212bbc3d38..f458f2e3b7 100644 --- a/.env.example +++ b/.env.example @@ -46,4 +46,4 @@ FRAPPE_SITE_NAME_HEADER= # List of sites for letsencrypt certificates quoted with backtick (`) and separated by comma (,) # More https://doc.traefik.io/traefik/routing/routers/#rule # About acme https://doc.traefik.io/traefik/https/acme/#domain-definition -SITES=`erp.zapal.tech` +SITES=`localhost` diff --git a/.github/workflows/production-image.yml b/.github/workflows/production-image.yml new file mode 100644 index 0000000000..bc2e97cc58 --- /dev/null +++ b/.github/workflows/production-image.yml @@ -0,0 +1,43 @@ +name: Create and publish a Docker image + +on: + push: + branches: ['production'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: 'DOTENV_KEY=${{ secrets.DOTENV_KEY }}' \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index b8ebd2cb90..059139532c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -9,7 +9,7 @@ x-depends-on-configurator: &depends_on_configurator x-backend-defaults: &backend_defaults <<: [*depends_on_configurator, *customizable_image] volumes: - - ./sites:/home/frappe/frappe-bench/sites + - sites:/home/zapal/frappe-bench/sites services: configurator: @@ -52,7 +52,7 @@ services: PROXY_READ_TIMEOUT: ${PROXY_READ_TIMEOUT:-120} CLIENT_MAX_BODY_SIZE: ${CLIENT_MAX_BODY_SIZE:-50m} volumes: - - ./sites:/home/frappe/frappe-bench/sites + - sites:/home/zapal/frappe-bench/sites depends_on: - backend - websocket @@ -61,9 +61,9 @@ services: <<: [*depends_on_configurator, *customizable_image] command: - node - - /home/frappe/frappe-bench/apps/frappe/socketio.js + - /home/zapal/frappe-bench/apps/frappe/socketio.js volumes: - - ./sites:/home/frappe/frappe-bench/sites + - sites:/home/zapal/frappe-bench/sites queue-short: <<: *backend_defaults @@ -76,3 +76,6 @@ services: scheduler: <<: *backend_defaults command: bench schedule + +volumes: + sites: diff --git a/docker-bake.hcl b/docker-bake.hcl index 9d2b8cf39a..27794d0f52 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -21,6 +21,10 @@ variable "HRMS_VERSION" { default = "version-15" } +variable "INSIGHTS_VERSION" { + default = "develop" +} + variable "FRAPPE_REPO" { default = "https://github.com/zapal-tech/erp-frappe" } @@ -33,6 +37,10 @@ variable "HRMS_REPO" { default = "https://github.com/zapal-tech/erp-hrms" } +variable "INSIGHTS_REPO" { + default = "https://github.com/zapal-tech/erp-insights" +} + variable "BENCH_REPO" { default = "https://github.com/frappe/bench" } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..11cb2a5cf2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,211 @@ +name: erp +services: + backend: + depends_on: + configurator: + condition: service_completed_successfully + required: true + image: zapal-tech/erp:latest + networks: + default: null + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} + configurator: + command: + - | + ls -1 apps > sites/apps.txt; 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"; bench set-config -g redis_queue "redis://$$REDIS_QUEUE"; bench set-config -g redis_socketio "redis://$$REDIS_QUEUE"; bench set-config -gp socketio_port $$SOCKETIO_PORT; + depends_on: + db: + condition: service_healthy + required: true + redis-cache: + condition: service_started + required: true + redis-queue: + condition: service_started + required: true + entrypoint: + - bash + - -c + environment: + DB_HOST: db + DB_PORT: "3306" + REDIS_CACHE: redis-cache:6379 + REDIS_QUEUE: redis-queue:6379 + SOCKETIO_PORT: "9000" + image: zapal-tech/erp:latest + networks: + default: null + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} + db: + command: + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_unicode_ci + - --skip-character-set-client-handshake + - --skip-innodb-read-only-compressed + environment: + MYSQL_ROOT_PASSWORD: "123" + healthcheck: + test: + - CMD-SHELL + - mysqladmin ping -h localhost --password=123 + interval: 1s + retries: 15 + image: mariadb:10.6 + networks: + default: null + volumes: + - type: volume + source: db-data + target: /var/lib/mysql + volume: {} + frontend: + command: + - nginx-entrypoint.sh + depends_on: + backend: + condition: service_started + required: true + websocket: + condition: service_started + required: true + environment: + BACKEND: backend:8000 + CLIENT_MAX_BODY_SIZE: 50m + FRAPPE_SITE_NAME_HEADER: $$host + PROXY_READ_TIMEOUT: "120" + SOCKETIO: websocket:9000 + UPSTREAM_REAL_IP_ADDRESS: 127.0.0.1 + UPSTREAM_REAL_IP_HEADER: X-Forwarded-For + UPSTREAM_REAL_IP_RECURSIVE: "off" + image: zapal-tech/erp:latest + networks: + default: null + ports: + - mode: ingress + target: 8080 + published: "8080" + protocol: tcp + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} + queue-long: + command: + - bench + - worker + - --queue + - long,default,short + depends_on: + configurator: + condition: service_completed_successfully + required: true + image: zapal-tech/erp:latest + networks: + default: null + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} + queue-short: + command: + - bench + - worker + - --queue + - short,default + depends_on: + configurator: + condition: service_completed_successfully + required: true + image: zapal-tech/erp:latest + networks: + default: null + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} + redis-cache: + image: redis:6.2-alpine + networks: + default: null + volumes: + - type: volume + source: redis-cache-data + target: /data + volume: {} + redis-queue: + image: redis:6.2-alpine + networks: + default: null + volumes: + - type: volume + source: redis-queue-data + target: /data + volume: {} + scheduler: + command: + - bench + - schedule + depends_on: + configurator: + condition: service_completed_successfully + required: true + image: zapal-tech/erp:latest + networks: + default: null + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} + websocket: + command: + - node + - /home/zapal/frappe-bench/apps/frappe/socketio.js + depends_on: + configurator: + condition: service_completed_successfully + required: true + image: zapal-tech/erp:latest + networks: + default: null + volumes: + - type: volume + source: sites + target: /home/zapal/frappe-bench/sites + volume: {} +networks: + default: + name: erp_default +volumes: + db-data: + name: erp_db-data + redis-cache-data: + name: erp_redis-cache-data + redis-queue-data: + name: erp_redis-queue-data + sites: + name: erp_sites +x-backend-defaults: + depends_on: + configurator: + condition: service_completed_successfully + image: zapal-tech/erp:latest + volumes: + - sites:/home/zapal/frappe-bench/sites +x-customizable-image: + image: zapal-tech/erp:latest +x-depends-on-configurator: + depends_on: + configurator: + condition: service_completed_successfully diff --git a/images/custom/Containerfile b/images/custom/Containerfile index f4f08cfeea..8250db807e 100644 --- a/images/custom/Containerfile +++ b/images/custom/Containerfile @@ -121,19 +121,25 @@ RUN bench init \ --no-backups \ --skip-redis-config-generation \ --verbose \ - /home/zapal/frappe-bench && \ - cd /home/zapal/frappe-bench && \ - bench get-app --branch=${ERPNEXT_BRANCH} --resolve-deps erpnext ${ERPNEXT_REPO} && \ - bench get-app --branch=${HRMS_BRANCH} --resolve-deps hrms ${HRMS_REPO} && \ - bench get-app --branch=${INSIGHTS_BRANCH} --resolve-deps insights ${INSIGHTS_REPO} && \ - echo "{}" > sites/common_site_config.json && \ - find apps -mindepth 1 -path "*/.git" | xargs rm -fr + /home/zapal/frappe-bench + +WORKDIR /home/zapal/frappe-bench + +RUN bench get-app --branch=${ERPNEXT_BRANCH} --resolve-deps erpnext ${ERPNEXT_REPO} +RUN bench get-app --branch=${HRMS_BRANCH} --resolve-deps hrms ${HRMS_REPO} +# RUN bench get-app --branch=${INSIGHTS_BRANCH} --resolve-deps insights ${INSIGHTS_REPO} + +RUN echo "frappe\nhrms\nerpnext" > sites/apps.txt +RUN echo "{}" > sites/common_site_config.json +RUN find apps -mindepth 1 -path "*/.git" | xargs rm -fr FROM base as erp USER zapal COPY --from=builder --chown=zapal:zapal /home/zapal/frappe-bench /home/zapal/frappe-bench +COPY /templates/nginx/erp.conf.template /templates/nginx/erp.conf.template +COPY /usr/local/bin/nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh WORKDIR /home/zapal/frappe-bench diff --git a/images/production/Containerfile b/images/production/Containerfile index 81ec6badd6..8fe46340f0 100644 --- a/images/production/Containerfile +++ b/images/production/Containerfile @@ -8,6 +8,9 @@ ARG NODE_VERSION=18.18.2 ENV NVM_DIR=/home/zapal/.nvm ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin/:${PATH} +COPY resources/nginx-template.conf /templates/nginx/erp.conf.template +COPY resources/nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh + RUN useradd -ms /bin/bash zapal \ && apt-get update \ && apt-get install --no-install-recommends -y \ @@ -64,10 +67,9 @@ RUN useradd -ms /bin/bash zapal \ && chown -R zapal:zapal /etc/nginx/nginx.conf \ && chown -R zapal:zapal /var/log/nginx \ && chown -R zapal:zapal /var/lib/nginx \ - && chown -R zapal:zapal /run/nginx.pid - -COPY resources/nginx-template.conf /templates/nginx/erp.conf.template -COPY resources/nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh + && chown -R zapal:zapal /run/nginx.pid \ + && chmod 755 /usr/local/bin/nginx-entrypoint.sh \ + && chmod 644 /templates/nginx/erp.conf.template FROM base AS builder @@ -113,13 +115,17 @@ RUN bench init \ --no-backups \ --skip-redis-config-generation \ --verbose \ - /home/zapal/frappe-bench && \ - cd /home/zapal/frappe-bench && \ - bench get-app --branch=${ERPNEXT_BRANCH} --resolve-deps erpnext ${ERPNEXT_REPO} && \ - bench get-app --branch=${HRMS_BRANCH} --resolve-deps hrms ${HRMS_REPO} && \ - bench get-app --branch=${INSIGHTS_BRANCH} --resolve-deps insights ${INSIGHTS_REPO} && \ - echo "{}" > sites/common_site_config.json && \ - find apps -mindepth 1 -path "*/.git" | xargs rm -fr + /home/zapal/frappe-bench + +WORKDIR /home/zapal/frappe-bench + +RUN bench get-app --branch=${ERPNEXT_BRANCH} --resolve-deps erpnext ${ERPNEXT_REPO} +RUN bench get-app --branch=${HRMS_BRANCH} --resolve-deps hrms ${HRMS_REPO} +# RUN bench get-app --branch=${INSIGHTS_BRANCH} --resolve-deps insights ${INSIGHTS_REPO} + +RUN echo "frappe\nhrms\nerpnext" > sites/apps.txt +RUN echo "{}" > sites/common_site_config.json +RUN find apps -mindepth 1 -path "*/.git" | xargs rm -fr FROM base as erp diff --git a/resources/nginx-entrypoint.sh b/resources/nginx-entrypoint.sh index df45d9ef93..bb9fb1fc90 100644 --- a/resources/nginx-entrypoint.sh +++ b/resources/nginx-entrypoint.sh @@ -2,12 +2,12 @@ # Set variables that do not exist if [[ -z "$BACKEND" ]]; then - echo "BACKEND defaulting to 0.0.0.0:8900" - export BACKEND=0.0.0.0:8900 + echo "BACKEND defaulting to 0.0.0.0:8000" + export BACKEND=0.0.0.0:8000 fi if [[ -z "$SOCKETIO" ]]; then - echo "SOCKETIO defaulting to 0.0.0.0:8910" - export SOCKETIO=0.0.0.0:8910 + echo "SOCKETIO defaulting to 0.0.0.0:9000" + export SOCKETIO=0.0.0.0:9000 fi if [[ -z "$UPSTREAM_REAL_IP_ADDRESS" ]]; then echo "UPSTREAM_REAL_IP_ADDRESS defaulting to 127.0.0.1" diff --git a/resources/nginx-template.conf b/resources/nginx-template.conf index 63d57c049e..aeb13ed352 100644 --- a/resources/nginx-template.conf +++ b/resources/nginx-template.conf @@ -8,7 +8,6 @@ upstream socketio-server { server { listen 8080; - server_name ${FRAPPE_SITE_NAME_HEADER}; root /home/zapal/frappe-bench/sites; proxy_buffer_size 128k;