Jelajahi Sumber

:bug: fix docker starter for composer/npm

Jeremy Zheng 1 tahun lalu
induk
melakukan
b91329383d

+ 1 - 1
deploy/group_vars/all.yml

@@ -2,7 +2,7 @@ ansible_user: "deploy"
 ansible_python_interpreter: /usr/bin/python3
 ansible_ssh_private_key_file: "{{ inventory_dir }}/.ssh/id_ed25519"
 
-app_deploy_target: "/mnt/www/{{ inventory_hostname }}/mint-{{ mint_version }}"
+app_deploy_target: "/mnt/{{ app_domain }}/mint-{{ mint_version }}"
 app_downloads: "{{ ansible_env.HOME }}/downloads"
 
 app_dashboard_base_path: "/pcd"

+ 0 - 145
deploy/roles/mint-v2.0/tasks/laravel-v8.yml

@@ -1,145 +0,0 @@
-- name: Upload nodejs packages for v1
-  ansible.builtin.copy:
-    src: "{{ playbook_dir }}/tmp/mint/api-v8/public/node_modules"
-    dest: "{{ app_deploy_target }}/mint/api-v8/public/node_modules"
-    mode: "0755"
-    creates: "{{ app_deploy_target }}/mint/api-v8/public/node_modules"
-
-- name: Upload nodejs packages for v2
-  ansible.builtin.copy:
-    src: "{{ playbook_dir }}/tmp/mint/api-v8/node_modules"
-    dest: "{{ app_deploy_target }}/mint/api-v8/node_modules"
-    mode: "0755"
-    creates: "{{ app_deploy_target }}/mint/api-v8/node_modules"
-
-- name: Upload .env(v2)                                                                                                                                                      10:53:42 [82/293]
-  become: true
-  ansible.builtin.template:
-    src: v2/env.j2
-    dest: "{{ app_deploy_target }}/mint/api-v8/.env"
-    owner: www-data
-    group: www-data
-    mode: "0444"
-
-- name: Upload config.php(v1)
-  ansible.builtin.become: true
-  ansible.builtin.template:
-    src: v1/config.php.j2
-    dest: "{{ app_deploy_target }}/mint/api-v8/public/app/config.php"
-    owner: www-data
-    group: www-data
-    mode: "0444"
-
-- name: Upload config.js(v1)
-  become: true
-  template:
-    src: v1/config.js.j2
-    dest: "{{ app_deploy_target }}/mint/api-v8/public/app/config.js"
-    owner: www-data
-    group: www-data
-    mode: "0444"
-
-- name: Setup bootstrap folder for {{ ansible_user }}
-  become: true
-  ansible.builtin.file:
-    path: "{{ app_deploy_target }}/mint/api-v8/bootstrap/cache"
-    state: directory
-    owner: "{{ ansible_user }}"
-    group: "{{ ansible_user }}"
-    recurse: true
-
-- name: Auto-loader optimization for v2
-  ansible.builtin.command:
-    argv:
-      - /usr/bin/composer
-      - update
-      - --optimize-autoloader
-      - --no-dev
-    chdir: "{{ app_deploy_target }}/api-v8"
-
-- name: Auto-loader optimization for v1
-  ansible.builtin.command:
-    argv:
-      - /usr/bin/composer
-      - update
-      - --optimize-autoloader
-      - --no-dev
-    chdir: "{{ app_deploy_target }}/mint/api-v8/public"
-
-- name: Setup storage folder for v2 for php-fpm
-  become: true
-  ansible.builtin.file:
-    path: "{{ app_deploy_target }}/mint/api-v8/storage"
-    state: directory
-    owner: www-data
-    group: www-data
-    recurse: true
-
-- name: Caching configuration
-  become: true
-  become_user: www-data
-  ansible.builtin.command:
-    argv:
-      - /usr/bin/php
-      - artisan
-      - config:cache
-    chdir: "{{ app_deploy_target}}/api-v8"
-
-- name: Caching events
-  become: true
-  become_user: www-data
-  ansible.builtin.command:
-    argv:
-      - /usr/bin/php
-      - artisan
-      - event:cache
-    chdir: "{{ app_deploy_target }}/api-v8"
-
-- name: Caching routes
-  become: true
-  become_user: www-data
-  ansible.builtin.command:
-    argv:
-      - /usr/bin/php
-      - artisan
-      - route:cache
-    chdir: "{{ app_deploy_target }}/api-v8"
-
-- name: Caching views
-  become: true
-  become_user: www-data
-  ansible.builtin.shell:
-    argv:
-      - /usr/bin/php
-      - artisan
-      - view:cache
-    chdir: "{{ app_deploy_target }}/api-v8"
-
-- name: Setup sqlite3 db for v1
-  become: true
-  ansible.builtin.file:
-    src: /var/www/shared/appdata
-    dest: "{{ app_deploy_target }}/mint/api-v8/storage/app/data"
-    state: link
-
-# https://laravel.com/docs/10.x/scheduling#running-the-scheduler
-- name: Upload scheduler service
-  become: true
-  ansible.builtin.template:
-    src: v2/scheduler.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-scheduler.service
-    owner: root
-    group: root
-    mode: "0644"
-
-- name: Setup laravel queue workers
-  ansible.builtin.import_tasks: queue-workers.yml
-
-- name: Setup morus service
-  ansible.builtin.import_tasks: morus.yml
-
-- name: Setup lily service
-  ansible.builtin.import_tasks: lily.yml
-
-- name: Setup tulip service
-  ansible.builtin.import_tasks: tulip.yml

+ 0 - 6
deploy/roles/mint-v2.0/tasks/main.yml

@@ -32,12 +32,6 @@
 
 - name: Setup dashboard
   ansible.builtin.import_tasks: antd-v4.yml
-- name: Setup laravel
-  ansible.builtin.import_tasks: laravel-v8.yml
 - name: Setup systemd services
   ansible.builtin.import_tasks: systemd.yml
 
-- name: Force systemd to reread configs
-  become: true
-  ansible.builtin.systemd:
-    daemon_reload: true

+ 33 - 0
deploy/roles/mint-v2.1/files/launch.sh

@@ -0,0 +1,33 @@
+#!/bin/bash
+
+set -e
+
+export USAGE="USAGE: $0 COMMAND"
+
+if [ "$#" -lt 1 ]; then
+    echo $USAGE
+    exit 1
+fi
+
+export WORK_DIR="/srv"
+
+export NVM_DIR="$HOME/.nvm"
+source "$NVM_DIR/nvm.sh"
+
+if [ "$1" == "setup" ]; then
+    cd $WORK_DIR/api-v8/
+    echo "install v2 laravel vendors"
+    composer update --optimize-autoloader --no-dev
+    echo "install v2 nodejs packages"
+    npm install --production
+
+    cd $WORK_DIR/api-v8/public/
+    echo "install v1 vendors"
+    composer update --optimize-autoloader --no-dev
+    echo "install v1 nodejs packages"
+    npm install --production
+else
+    $@
+fi
+
+exit 0

+ 151 - 0
deploy/roles/mint-v2.1/tasks/laravel-v8.yml

@@ -0,0 +1,151 @@
+- name: Upload launch.sh
+  ansible.builtin.template:
+    src: launch.sh
+    dest: "{{ app_deploy_target }}/scripts/"
+    mode: "0555"
+
+- name: Setup third packages
+  ansible.builtin.command:
+    argv:
+      - "{{ app_deploy_target }}/docker/mint/run.sh"
+      - "{{ app_mint_image_name }}"
+      - setup
+    chdir: "{{ app_deploy_target }}/"
+    creates: "{{ app_deploy_target }}/api-v8/public/node_modules"
+# - name: Setup nodejs packages for v2
+#   ansible.builtin.command:
+#     argv:
+#       - "{{ app_deploy_target }}/docker/mint/run.sh"
+#       - "{{ app_mint_image_name }}"
+#       - npm
+#       - install
+#     chdir: "{{ app_deploy_target }}/api-v8"
+#     creates: "{{ app_deploy_target }}/api-v8/node_modules"
+# - name: Upload .env(v2)
+#   become: true
+#   ansible.builtin.template:
+#     src: v2/env.j2
+#     dest: "{{ app_deploy_target }}/mint/api-v8/.env"
+#     owner: www-data
+#     group: www-data
+#     mode: "0444"
+
+# - name: Upload config.php(v1)
+#   ansible.builtin.become: true
+#   ansible.builtin.template:
+#     src: v1/config.php.j2
+#     dest: "{{ app_deploy_target }}/mint/api-v8/public/app/config.php"
+#     owner: www-data
+#     group: www-data
+#     mode: "0444"
+
+# - name: Upload config.js(v1)
+#   become: true
+#   ansible.builtin.template:
+#     src: v1/config.js.j2
+#     dest: "{{ app_deploy_target }}/mint/api-v8/public/app/config.js"
+#     owner: www-data
+#     group: www-data
+#     mode: "0444"
+
+# - name: Setup bootstrap folder for {{ ansible_user }}
+#   become: true
+#   ansible.builtin.file:
+#     path: "{{ app_deploy_target }}/mint/api-v8/bootstrap/cache"
+#     state: directory
+#     owner: "{{ ansible_user }}"
+#     group: "{{ ansible_user }}"
+#     recurse: true
+
+# - name: Auto-loader optimization for v2
+#   ansible.builtin.command:
+#     argv:
+#       - /usr/bin/composer
+#       - update
+#       - --optimize-autoloader
+#       - --no-dev
+#     chdir: "{{ app_deploy_target }}/api-v8"
+
+# - name: Auto-loader optimization for v1
+#   ansible.builtin.command:
+#     argv:
+
+#     chdir: "{{ app_deploy_target }}/mint/api-v8/public"
+
+# - name: Setup storage folder for v2 for php-fpm
+#   become: true
+#   ansible.builtin.file:
+#     path: "{{ app_deploy_target }}/mint/api-v8/storage"
+#     state: directory
+#     owner: www-data
+#     group: www-data
+#     recurse: true
+
+# - name: Caching configuration
+#   become: true
+#   become_user: www-data
+#   ansible.builtin.command:
+#     argv:
+#       - /usr/bin/php
+#       - artisan
+#       - config:cache
+#     chdir: "{{ app_deploy_target}}/api-v8"
+
+# - name: Caching events
+#   become: true
+#   become_user: www-data
+#   ansible.builtin.command:
+#     argv:
+#       - /usr/bin/php
+#       - artisan
+#       - event:cache
+#     chdir: "{{ app_deploy_target }}/api-v8"
+
+# - name: Caching routes
+#   become: true
+#   become_user: www-data
+#   ansible.builtin.command:
+#     argv:
+#       - /usr/bin/php
+#       - artisan
+#       - route:cache
+#     chdir: "{{ app_deploy_target }}/api-v8"
+
+# - name: Caching views
+#   become: true
+#   become_user: www-data
+#   ansible.builtin.shell:
+#     argv:
+#       - /usr/bin/php
+#       - artisan
+#       - view:cache
+#     chdir: "{{ app_deploy_target }}/api-v8"
+
+# - name: Setup sqlite3 db for v1
+#   become: true
+#   ansible.builtin.file:
+#     src: /var/www/shared/appdata
+#     dest: "{{ app_deploy_target }}/mint/api-v8/storage/app/data"
+#     state: link
+
+# # https://laravel.com/docs/10.x/scheduling#running-the-scheduler
+# - name: Upload scheduler service
+#   become: true
+#   ansible.builtin.template:
+#     src: v2/scheduler.service.j2
+#     dest: /usr/lib/systemd/system/{{ inventory_hostname }}-scheduler.service
+#     owner: root
+#     group: root
+#     mode: "0644"
+
+# - name: Setup laravel queue workers
+#   ansible.builtin.import_tasks: queue-workers.yml
+
+# - name: Setup morus service
+#   ansible.builtin.import_tasks: morus.yml
+
+# - name: Setup lily service
+#   ansible.builtin.import_tasks: lily.yml
+
+# - name: Setup tulip service
+#   ansible.builtin.import_tasks: tulip.yml

+ 13 - 28
deploy/roles/mint-v2.1/tasks/main.yml

@@ -1,42 +1,27 @@
 - name: Create www folder
   become: true
   ansible.builtin.file:
-    path: "/mnt/www/{{ inventory_hostname }}"
+    path: "/mnt/{{ app_domain }}"
     state: directory
+    owner: "{{ ansible_user }}"
     mode: "0755"
 
 - name: Download source code
   ansible.builtin.unarchive:
     src: https://github.com/iapt-platform/mint/archive/{{ mint_version }}.zip
-    dest: "/mnt/www/{{ inventory_hostname }}"
+    dest: "/mnt/{{ app_domain }}"
     remote_src: true
     creates: "{{ app_deploy_target }}"
 
-# - name: Install third packages
-#   ansible.builtin.command: docker/mint/run.sh {{ app_mint_image_name }} setup
-#   args:
-#     chdir: "{{ ansible_env.HOME }}/build/mint-{{ mint_version }}"
-#     creates: "{{ ansible_env.HOME }}/build/mint-{{ mint_version }}/api-v8/public/node_modules"
-
-# if [ "$1" == "fpm" ]; then
-#     echo "start fpm worker"
-#     # TODO
-# elif [ "$1" == "setup" ]; then
-#     cd $WORK_DIR/api-v8/
-#     composer install --optimize-autoloader --no-dev
-#     npm install
-#     cd $WORK_DIR/api-v8/public/
-#     composer install --optimize-autoloader --no-dev
-#     npm install
-# elif [ "$1" == "db-migrate" ]; then
-#     echo "migrate database"
-#     # TODO
-# else
-#     echo $USAGE
-#     exit 1
-# fi
-
 - name: Upload dashboard-v4 dist
   ansible.posix.synchronize:
-    src: "{{ playbook_dir }}/tmp/mint/dashboard-v4/dashboard/dist-{{ mint_version }}"
-    dest: "{{ app_deploy_target }}/dashboard-v4/dashboard"
+    src: "{{ playbook_dir }}/tmp/mint/dashboard-v4/dashboard/dist-{{ mint_version }}/"
+    dest: "{{ app_deploy_target }}/dashboard-v4/dashboard/dist/"
+
+- name: Setup laravel
+  ansible.builtin.import_tasks: laravel-v8.yml
+
+- name: Force systemd to reread configs
+  become: true
+  ansible.builtin.systemd:
+    daemon_reload: true

+ 0 - 0
deploy/roles/mint-v2.0/tasks/queue-workers.yml → deploy/roles/mint-v2.1/tasks/queue-workers.yml


+ 0 - 0
deploy/roles/mint-v2.0/templates/v1/config.js.j2 → deploy/roles/mint-v2.1/templates/v1/config.js.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v1/config.php.j2 → deploy/roles/mint-v2.1/templates/v1/config.php.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/env.j2 → deploy/roles/mint-v2.1/templates/v2/env.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/lily/config.toml.j2 → deploy/roles/mint-v2.1/templates/v2/lily/config.toml.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/lily/services/server.service.j2 → deploy/roles/mint-v2.1/templates/v2/lily/services/server.service.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/lily/services/worker.service.j2 → deploy/roles/mint-v2.1/templates/v2/lily/services/worker.service.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/morus.service.j2 → deploy/roles/mint-v2.1/templates/v2/morus.service.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/queue-worker.service.j2 → deploy/roles/mint-v2.1/templates/v2/queue-worker.service.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/scheduler.service.j2 → deploy/roles/mint-v2.1/templates/v2/scheduler.service.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/scheduler.timer.j2 → deploy/roles/mint-v2.1/templates/v2/scheduler.timer.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/tulip/config.php.j2 → deploy/roles/mint-v2.1/templates/v2/tulip/config.php.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/tulip/db/env.j2 → deploy/roles/mint-v2.1/templates/v2/tulip/db/env.j2


+ 0 - 0
deploy/roles/mint-v2.0/templates/v2/tulip/service.conf.j2 → deploy/roles/mint-v2.1/templates/v2/tulip/service.conf.j2


+ 1 - 1
docker/mint/run.sh

@@ -9,7 +9,7 @@ if [[ "$#" -lt 2 ]]; then
     exit 2
 fi
 
-podman run --rm -it --events-backend=file --hostname=mint --network host -v $PWD:/srv:z $@
+export LAUNCH_MINT_CONTAINER="podman run --rm -it --events-backend=file --hostname=mint --network host -v $PWD:/srv:z $1"
 
 if [ "$2" == "shell" ]; then
     $LAUNCH_MINT_CONTAINER /bin/bash

+ 0 - 19
scripts/launch.sh

@@ -1,19 +0,0 @@
-#!/bin/bash
-
-set -e
-
-export USAGE="USAGE: $0 COMMAND"
-
-if [ "$#" -lt 1 ]; then
-    echo $USAGE
-    exit 1
-fi
-
-export WORK_DIR="/srv"
-
-export NVM_DIR="$HOME/.nvm"
-source "$NVM_DIR/nvm.sh"
-
-$@
-
-exit 0