Prechádzať zdrojové kódy

:bug: fix container's volume

Jeremy Zheng 1 rok pred
rodič
commit
9a72619d55

+ 5 - 49
deploy/mint.yml

@@ -49,53 +49,9 @@
     - fpm
   roles:
     - mint-php-fpm
-# FIXME
-# - name: Setup database
-#   hosts:
-#     - fort
-#   tasks:
-#     - name: Run all of outstanding migrations
-#       ansible.builtin.command:
-#         argv:
-#           - "{{ app_deploy_target }}/docker/mint/run.sh"
-#           - "{{ app_mint_image_name }}"
-#           - db-migrate
-#         chdir: "{{ app_deploy_target }}/"
-#       register: mint_db_migrate_output
-#       changed_when: mint_db_migrate_output.rc != 0
 
-# - name: Build backend v8
-#   hosts: fort
-#   roles:
-#     - mint-backend-v8-build
-
-# - name: Build backend v8
-#   hosts: fort
-#   roles:
-#     - mint-backend-v8-build
-
-# - name: Setup backend servers
-#   hosts:
-#     - web
-#     - fpm
-#     - task
-#   roles:
-#     - mint-v2
-
-# - name: Setup backend servers
-#   hosts:
-#     - web
-#     - fpm
-#     - task
-#   roles:
-#     - mint-v2
-
-# - name: Setup nginx
-#   hosts: web
-#   roles:
-#     - mint-nginx
-
-# - name: Setup workers
-#   hosts: tasks
-#   roles:
-#     - mint-workers
+- name: Setup nginx
+  hosts:
+    - web
+  roles:
+    - mint-nginx

+ 27 - 0
deploy/roles/mint-fort/tasks/main.yml

@@ -0,0 +1,27 @@
+- name: Upload script for schedule-run
+  ansible.builtin.copy:
+    src: schedule-run.sh
+    dest: "{{ app_deploy_target }}/scripts/worker-{{ zone_name }}-{{ worker_name }}.sh"
+    mode: "0555"
+
+- name: Stop schedule-run
+  containers.podman.podman_container:
+    name: "{{ app_domain }}-worker-schedule-run"
+    state: absent
+
+- name: Start schedule-run
+  containers.podman.podman_container:
+    name: "{{ app_domain }}-worker-schedule-run"
+    image: "{{ app_mint_image_name }}"
+    command: "{{ app_deploy_target }}/scripts/worker-schedule-run.sh"
+    volumes:
+      - "{{ app_deploy_target }}:{{ app_deploy_target }}:z"
+    workdir: "{{ app_deploy_target }}"
+    # auto_remove: true
+    generate_systemd:
+      path: "{{ app_deploy_target | dirname }}/systemd"
+      container_prefix: mint
+      names: true
+      restart_policy: always
+      stop_timeout: 120
+# TODO timer

+ 12 - 0
deploy/roles/mint-fort/templates/schedule-run.j2

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+set -e
+
+export WORK_DIR="{{ app_deploy_target }}"
+
+export NVM_DIR="$HOME/.nvm"
+source "$NVM_DIR/nvm.sh"
+
+cd $WORK_DIR/api-v8/
+
+php artisan schedule:run

+ 21 - 0
deploy/roles/mint-nginx/tasks/main.yml

@@ -0,0 +1,21 @@
+- name: Create nginx logs folder
+  become: true
+  ansible.builtin.file:
+    path: "{{ app_deploy_target | dirname }}/logs"
+    state: directory
+    owner: www-data
+    mode: "0755"
+
+- name: Upload nginx-fpm.sh
+  become: true
+  ansible.builtin.template:
+    src: fpm.conf.j2
+    dest: /etc/nginx/sites-enabled/{{ app_domain }}-fpm.conf
+    mode: "0644"
+
+- name: Upload nginx.conf
+  become: true
+  ansible.builtin.template:
+    src: nginx.conf.j2
+    dest: /etc/nginx/sites-enabled/{{ app_domain }}.conf
+    mode: "0644"

+ 7 - 0
deploy/roles/mint-nginx/templates/fpm.conf.j2

@@ -0,0 +1,7 @@
+upstream php_fpm_{{ app_php_fpm_port }} {
+   least_conn;
+
+   # server 192.168.0.11:{{ app_php_fpm_port }} weight=10;   
+
+   server 127.0.0.1:{{ app_php_fpm_port }} backup;
+}

+ 56 - 0
deploy/roles/mint-nginx/templates/nginx.conf.j2

@@ -0,0 +1,56 @@
+# https://laravel.com/docs/12.x/deployment#nginx
+
+server {
+    listen 80;
+    server_name {{ app_domain }};
+    root {{ app_deploy_target | dirname }}/current/api-v8/public;
+ 
+    add_header X-Frame-Options "SAMEORIGIN";
+    add_header X-Content-Type-Options "nosniff";
+ 
+    index index.php index.html;
+ 
+    charset utf-8;
+    gzip_comp_level 9;
+    gzip_min_length 1k;
+    gzip_types text/plain text/css application/xml application/javascript;
+    gzip_vary on;
+    client_max_body_size 512M;
+
+    access_log {{ app_deploy_target | dirname }}/logs/access.log;
+    error_log {{ app_deploy_target | dirname }}/logs/error.log warn;
+    # access_log syslog:server=unix:/dev/log,tag={{ app_domain }},nohostname,severity=info combined;
+    # error_log  syslog:server=unix:/dev/log,tag={{ app_domain }},nohostname,severity=error;
+
+    location {{ app_dashboard_base_path }}/ {
+            alias {{ app_deploy_target | dirname }}/current/dashboard-v4/dashboard/dist/;
+            try_files $uri $uri/ {{ app_dashboard_base_path }}/index.html;
+
+            location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
+            access_log off;
+            expires max;
+        }
+    }
+ 
+    location / {
+        try_files $uri $uri/ /index.php?$query_string;
+    }
+ 
+    location = /favicon.ico { access_log off; log_not_found off; }
+    location = /robots.txt  { access_log off; log_not_found off; }
+ 
+    error_page 404 /index.php;
+ 
+    location ~ \.php$ {
+        fastcgi_pass php_fpm_{{ app_php_fpm_port }};
+        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
+        include fastcgi_params;
+        fastcgi_hide_header X-Powered-By;
+    }
+ 
+    location ~ /\.(?!well-known).* {
+        deny all;
+    }
+    
+}
+

+ 3 - 2
deploy/roles/mint-php-fpm/tasks/main.yml

@@ -13,9 +13,10 @@
   containers.podman.podman_container:
     name: "{{ app_domain }}-fpm-{{ app_php_fpm_port }}"
     image: "{{ app_mint_image_name }}"
-    command: "/srv/scripts/php-fpm.sh"
+    command: "{{ app_deploy_target }}/scripts/php-fpm.sh"
     ports:
       - "0.0.0.0:{{ app_php_fpm_port }}:9000/tcp"
     volumes:
-      - "{{ app_deploy_target }}:/srv:z"
+      - "{{ app_deploy_target }}:{{ app_deploy_target }}:z"
+    workdir: "{{ app_deploy_target }}"
     # auto_remove: true

+ 12 - 5
deploy/roles/mint-v2.1/tasks/laravel.yml

@@ -17,8 +17,8 @@
     mode: "0444"
 
 - name: Upload vendors.sh
-  ansible.builtin.copy:
-    src: vendors.sh
+  ansible.builtin.template:
+    src: containers/vendors.sh.j2
     dest: "{{ app_deploy_target }}/scripts/"
     mode: "0555"
 
@@ -26,7 +26,14 @@
   containers.podman.podman_container:
     name: "{{ app_domain }}-initialize"
     image: "{{ app_mint_image_name }}"
-    command: /srv/scripts/vendors.sh
+    command: "{{ app_deploy_target }}/scripts/vendors.sh"
     volumes:
-      - "{{ app_deploy_target }}:/srv"
-    auto_remove: true
+      - "{{ app_deploy_target }}:{{ app_deploy_target }}:z"
+    workdir: "{{ app_deploy_target }}"
+    # auto_remove: true
+
+- name: Create a current link
+  ansible.builtin.file:
+    src: "{{ app_deploy_target }}"
+    dest: "{{ app_deploy_target | dirname }}/current"
+    state: link

+ 1 - 1
deploy/roles/mint-v2.1/templates/containers/shell.sh.j2

@@ -1,3 +1,3 @@
 #!/bin/sh
 
-podman run --rm -it --events-backend=file --hostname=mint --network host -v {{ app_deploy_target }}:/srv:z {{ app_mint_image_name }} /bin/bash -l
+podman run --rm -it --events-backend=file --hostname=mint --network host -w {{ app_deploy_target }} -v {{ app_deploy_target }}:{{ app_deploy_target }}:z {{ app_mint_image_name }} /bin/bash -l

+ 1 - 1
deploy/roles/mint-v2.1/files/vendors.sh → deploy/roles/mint-v2.1/templates/containers/vendors.sh.j2

@@ -2,7 +2,7 @@
 
 set -e
 
-export WORK_DIR="/srv"
+export WORK_DIR="{{ app_deploy_target }}"
 
 export NVM_DIR="$HOME/.nvm"
 source "$NVM_DIR/nvm.sh"

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

@@ -12,9 +12,3 @@
     - ai.translate
   loop_control:
     loop_var: worker_name
-
-- name: Setup laravel scheduler
-  ansible.builtin.include_tasks: worker.yml
-  vars:
-    zone_name: schedule
-    worker_name: run

+ 3 - 2
deploy/roles/mint-workers/tasks/worker.yml

@@ -13,7 +13,8 @@
   containers.podman.podman_container:
     name: "{{ app_domain }}-worker-{{ zone_name }}-{{ worker_name }}"
     image: "{{ app_mint_image_name }}"
-    command: "/srv/scripts/worker-{{ zone_name }}-{{ worker_name }}.sh"
+    command: "{{ app_deploy_target }}/scripts/worker-{{ zone_name }}-{{ worker_name }}.sh"
     volumes:
-      - "{{ app_deploy_target }}:/srv:z"
+      - "{{ app_deploy_target }}:{{ app_deploy_target }}:z"
+    workdir: "{{ app_deploy_target }}"
     # auto_remove: true

+ 1 - 1
deploy/roles/mint-workers/tasks/templates/worker.sh.j2 → deploy/roles/mint-workers/templates/worker.sh.j2

@@ -2,7 +2,7 @@
 
 set -e
 
-export WORK_DIR="/srv"
+export WORK_DIR="{{ app_deploy_target }}"
 
 export NVM_DIR="$HOME/.nvm"
 source "$NVM_DIR/nvm.sh"