iT邦幫忙

2024 iThome 鐵人賽

DAY 3
0
Odoo

豬神器在囧途 (LLM Prompting x odoo 17)系列 第 3

開始實作 --- 平台為 Native Linux or Linux VM

  • 分享至 

  • xImage
  •  

依照之前的需求開始實作

專案目錄結構

/opt/odoo-project/
├── docker-compose.yml
├── odoo-config/
├── odoo-addons/
├── postgresql-data/
└── portainer-data/

作法

  1. 直接下載ubuntu 22.04 乾淨的VM來使用
  2. 將之前的需求丟給GenAI去生成

Prompt

Generate tbe docker compose yaml file include the odoo 17 (docker user is root), postgres 16 and portainer. The most useful folder should be bind to the external system folder and create a basic odoo.conf. This config file can prevent the memory leak issue.
  1. 看到生成後的內容,筆者覺得好麻煩,乾脆直接讓GenAI直接幫我把上面那堆東西跟可能存在的相依性問題整合在一個腳本內

prompt

create one script to integrate the previous content and install the dependency package through apt and create the one project folder, all of data should be stored in this folder with correct permission under ubuntu 22.04 platform. 

response

#!/bin/bash

# Set up error handling
set -e

# Define variables
PROJECT_NAME="odoo_project"
PROJECT_DIR="/opt/$PROJECT_NAME"
DOCKER_COMPOSE_FILE="$PROJECT_DIR/docker-compose.yml"

# Function to check if a command exists
command_exists() {
    command -v "$1" >/dev/null 2>&1
}

# Create project directory and set permissions
create_project_structure() {
    sudo mkdir -p "$PROJECT_DIR"
    sudo mkdir -p "$PROJECT_DIR/odoo-data"
    sudo mkdir -p "$PROJECT_DIR/odoo-config"
    sudo mkdir -p "$PROJECT_DIR/odoo-addons"
    sudo mkdir -p "$PROJECT_DIR/postgres-data"
    sudo mkdir -p "$PROJECT_DIR/portainer-data"
    sudo chown -R $USER:$USER "$PROJECT_DIR"
    echo "Project directory structure created."
}

# Install dependencies
install_dependencies() {
    sudo apt update
    sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

    # Install Docker if not already installed
    if ! command_exists docker; then
        curl -fsSL https://get.docker.com -o get-docker.sh
        sudo sh get-docker.sh
        sudo usermod -aG docker $USER
        echo "Docker installed successfully."
    else
        echo "Docker is already installed."
    fi

    # Install Docker Compose if not already installed
    if ! command_exists docker-compose; then
        sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
        sudo chmod +x /usr/local/bin/docker-compose
        echo "Docker Compose installed successfully."
    else
        echo "Docker Compose is already installed."
    fi
}

# Create Docker Compose file
create_docker_compose_file() {
    cat << EOF > "$DOCKER_COMPOSE_FILE"
version: '3.8'
services:
  odoo:
    image: odoo:17
    user: root
    depends_on:
      - db
    ports:
      - "8069:8069"
    volumes:
      - ./odoo-data:/var/lib/odoo
      - ./odoo-config:/etc/odoo
      - ./odoo-addons:/mnt/extra-addons
    environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=odoo_password
    restart: unless-stopped
    command: ["--limit-memory-hard", "0", "--limit-memory-soft", "0"]
  db:
    image: postgres:16
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_PASSWORD=odoo_password
      - POSTGRES_USER=odoo
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    restart: unless-stopped
  portainer:
    image: portainer/portainer-ce:latest
    ports:
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./portainer-data:/data
    restart: unless-stopped
EOF
    echo "Docker Compose file created."
}

# Main execution
echo "Starting Odoo project setup..."

create_project_structure
install_dependencies
create_docker_compose_file

echo "Setup complete. Your Odoo project is ready at $PROJECT_DIR"
echo "To start the services, run: cd $PROJECT_DIR && docker-compose up -d"
echo "Remember to change the default passwords in the docker-compose.yml file before deploying in production."
  • chmod +x odoo-setup-project.sh (賦予權限)
  • ./odoo-setup-project.sh (展開跟安裝)
  • docker-compose up -d (執行容器)
  1. 複製上面的腳本內容到VM中後直接執行
  2. 接著,跟著指令直接啟用服務
    image
  3. 服務順利啟動
    image

image

image


雷點在哪?

  • docker file 中odoo的片段需要指定user為root,否則執行後網頁就會出現internal error相關的錯誤訊息
  • prompt 忘記給參數就可能會造成一連串要持續溝通的窘況

上一篇
需求分析
下一篇
開始實作 --- 平台為 Synology NAS
系列文
豬神器在囧途 (LLM Prompting x odoo 17)12
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言