Manual deployment basics

更新时间:
复制 MD 格式

This document explains how to deploy and run application artifacts for different programming languages (Java, Go, Python, C++, and Node.js) on an Alibaba Cloud ECS instance.

The role of manual deployment in CI/CD

Manual deployment serves several purposes in automation:

  • Baseline for automation: Exposes efficiency bottlenecks and quality issues to drive optimization.

  • Bridge to automation: Enables gradual script development and integration into CI/CD tools.

  • Emergency fallback: Acts as a temporary replacement for a failed automated process.

  • Gatekeeper for critical steps: Allows for manual approval and data validation for high-risk operations.

  • Training tool: Helps teams understand underlying logic through manual server configuration and failure recovery.

Important

Strengthen error handling during the transition phase. After an emergency operation, update the automation configuration accordingly. Limit manual intervention to high-risk scenarios. Supplement training with documentation to prevent knowledge gaps.

Pros and cons of manual deployment

Pros:

  • Low barrier to entry: You can quickly validate small project prototypes without setting up a complex automation toolchain.

  • Flexibility: Developers can adjust the process, such as by skipping test steps or directly accessing the server to respond to urgent changes.

  • Control and visibility: Full manual control ensures transparent and manageable operations, making it easier to troubleshoot issues.

  • Fallback mechanism: Serves as an emergency solution when automation fails. It is especially useful for systems with infrequent deployments or strict security and compliance requirements, such as in finance or government.

Cons:

  • Inefficient and hard to scale: Repetitive manual tasks are slow and difficult to adapt across multiple environments.

  • Prone to errors: Environmental differences, such as local dependency versions, and human errors, like configuration mistakes or missed tests, can lead to unstable deployments and even production issues.

  • Difficult to track and roll back: The lack of version history and a rollback mechanism makes it hard to trace deployments. It can also create knowledge silos in team collaboration, cause resource conflicts in parallel tasks, and hinder continuous delivery.

Manual deployment practices

Transfer files to an ECS instance

Before deploying your application, transfer your code or build artifacts to an ECS instance. ECS offers several methods for file transfer. For more information, see Select a method to transfer files.

Build practices for multiple languages

Java

Environment configuration

  1. Configure the Java environment. For instructions, see Deploy a Java environment.

  2. Install a build tool.

    For Java web projects, we recommend using Maven or Gradle as your build tool.

Deploy and run

This example uses the demo-template-thymeleaf module from the open-source project spring-boot-demo.

  1. Clone the project by using Git:

    sudo git clone https://github.com/xkcoding/spring-boot-demo.git
  2. Build the project by using Maven:

    sudo cd spring-boot-demo/demo-template-thymeleaf
    sudo mvn clean package

    The build is complete when you see the following output.

    image

  3. Start the project in the background by using nohup:

    sudo nohup java -jar target/demo-template-thymeleaf.jar > app.log 2>&1 &
    • nohup: Prevents the process from receiving a hang-up (HUP) signal when the terminal is closed.

    • > app.log: Redirects the standard output to the app.log file.

    • 2>&1: Redirects the standard error to the same location as the standard output, which is app.log.

    • &: Runs the process in the background.

  4. View the logs:

    sudo tail -f app.log

    The service starts successfully when you see the following output in the logs.

    image

  5. In a web browser, open http://<your_ecs_public_ip>:8080/demo to view the project page.

Go

Environment configuration

  1. Note: This project requires Go 1.24 or later. Run the following commands to install the Go compiler.

    # The following commands use Go 1.24.0 as an example.
    
    # Download the Go installation package.
    sudo wget https://go.dev/dl/go1.24.0.linux-amd64.tar.gz
    # Extract the package.
    sudo tar -zxvf go1.24.0.linux-amd64.tar.gz -C /usr/local/
    # Configure the environment variable.
    sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile && source ~/.bash_profile
  2. Verify the Go version:

    go version

    The Go environment is configured when you see the following output.

    image

Build and run

This example uses the open-source project go-admin, a permission management system boilerplate built with Gin, Vue, Element UI, Arco Design, and Ant Design, featuring a decoupled frontend and backend.

  1. Create a development directory:

    # Create a development directory.
    mkdir goadmin && cd goadmin
  2. Clone the source code for the frontend and backend.

    Important

    The two projects must be in the same directory.

    # Get the backend code.
    sudo git clone https://github.com/go-admin-team/go-admin.git
    
    # Get the frontend code.
    sudo git clone https://github.com/go-admin-team/go-admin-ui.git
Start the backend
  1. Update project dependencies and build the project:

    # Go to the go-admin backend project directory.
    cd ./go-admin
    # Update and tidy dependencies.
    sudo go mod tidy
    # Compile the project.
    sudo go build
  2. Deploy a MySQL database. For instructions, see Deploy a MySQL database.

  3. Create a new database named go_admin:

    sudo create database go_admin;
  4. Modify the configuration file:

    # Modify the configuration. 
    # File path: go-admin/config/settings.yml
    sudo vim ./config/settings.yml

    In the configuration file, you can change the service port and database-related parameters.

    image

  5. Initialize the database:

    sudo ./go-admin migrate -c config/settings.yml

    When the console displays the message 数据库基础数据初始化成功 (Database basic data initialized successfully), the database initialization is complete.

    image

  6. Start the go-admin service:

    sudo ./go-admin server -c config/settings.yml -a true

    The service starts successfully when the console displays the service URL.

    image

Start the frontend
  1. Install dependencies:

    sudo npm install --registry=https://registry.npmmirror.com
  2. Start the frontend service:

    sudo npm run dev

    The service starts successfully when you see the following output in the console.

    image

  3. In a web browser, open <your_ecs_public_ip>:9527. The service is deployed successfully when the following page appears. Follow the on-screen instructions to configure the system.

    image

C++

Environment configuration

Install the build tools for C++ compilation:

# For Ubuntu/Debian 
sudo apt update
sudo apt install build-essential
# For CentOS/RHEL
sudo yum groupinstall "Development Tools"

Create a C++ source file

Use a text editor such as nano or vim to create a new C++ file. For example, create a simple Hello World program.

// hello.cpp
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Compile and run

  1. Compile the program:

    sudo g++ hello.cpp -o hello

    This command generates an executable file named hello.

  2. Run the compiled program:

    sudo ./hello

    The program runs successfully when you see the following output.

    image

  3. For larger projects, consider using a build system like Makefile or CMake to manage the compilation process.

    1. Create a file named Makefile and add the following content.

      all: hello
      
      hello: hello.cpp
          g++ hello.cpp -o hello
      
      clean:
          rm -f hello
    2. Use the make command to compile and generate the executable file.

Python

Deploy and run

This example uses the open-source project Qexo, a fast, powerful, and elegant online static blog editor.

  1. Configure the Python environment. For instructions, see Deploy a Python environment.

  2. Clone the Qexo source code by using Git:

    sudo git clone https://github.com/Qexo/Qexo.git
  3. Install the required project dependencies:

    sudo pip3 install -r requirements.txt
  4. Deploy a MySQL database. For instructions, see Deploy a MySQL database.

  5. Create a new database for Qexo named qexo_ecs:

    create database qexo_ecs;
  6. In the project's root directory, open the configuration file:

    sudo cp configs.example.py configs.py
    sudo vim configs.py

    Add the following configuration to the file. Replace the database IP address, username, and password with your actual information.

    import pymysql
    pymysql.install_as_MySQLdb()
    DOMAINS = ["127.0.0.1", "yoursite.com", "localhost"]
    DATABASES = {
        'default': {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': 'qexo',
                'USER': 'root',
                'PASSWORD': '',
                'HOST': '127.0.0.1',
                'PORT': '3306',
                'OPTIONS': {
                    "init_command": "SET sql_mode='STRICT_TRANS_TABLES'"
                }
        }
    }
    
  7. Start the service:

    sudo python3 manage.py makemigrations
    sudo python3 manage.py migrate
    sudo python3 manage.py runserver 0.0.0.0:8000 --noreload
  8. Allow traffic on port 8000 in the security group of the instance. For instructions, see Add security group rules.

  9. In a web browser, open <your_ecs_public_ip>:8000. The service is deployed successfully when the following page appears. Follow the on-screen instructions to configure the system.

    image

Node.js

This example uses the open-source project vue-naive-admin, a lightweight admin template built with Vue3, Vite, Pinia, Unocss, and Naive UI. Both the frontend and backend of the project are built with Node.js.

Backend
  1. Configure the Node.js environment. For instructions, see Deploy a Node.js environment.

  2. Clone the backend source code for the project:

    sudo git clone https://github.com/zclzone/isme-nest-serve.git
  3. Install dependencies:

    sudo npm i
  4. Deploy a MySQL database. For instructions, see Deploy a MySQL database.

  5. Create a new database named isme:

    create database isme;
  6. Initialize the project's database:

     mysql -u -p isme < init.sql
  7. Open the configuration file and modify the database connection information:

    sudo vim .env
  8. In the configuration file, modify the service port and database-related parameters.

    # Service port
    APP_PORT=8085
    
    # DB
    DB_HOST=localhost
    DB_PORT=3306
    DB_USER=
    DB_PWD=
    DB_DATABASE=isme
    DB_SYNC=true  # Specifies whether to enable synchronization. Set to false in a production environment.
    
    # Redis
    REDIS_URL=redis://default:123456@localhost:6379
    
    # JWT
    JWT_SECRET="d0!doc15415B0*4G0`"
    
    # Specifies whether it is a preview environment.
    IS_PREVIEW=false 
  9. Start the service:

    sudo npm run start:dev

    The service starts successfully when the running logs are displayed in the console.

    image

Frontend
  1. Clone the frontend source code for the project:

    sudo git clone -b 2.x https://github.com/zclzone/vue-naive-admin.git
  2. Install the project dependencies:

    sudo cd vue-naive-admin/
    sudo npm i
  3. Start the project:

    sudo npm run dev

    The project starts successfully when the access URL is displayed in the console.

    image

  4. In a web browser, open http://<your_ecs_public_ip>:3200. The project is deployed successfully when the following page appears.

    image

System monitoring and log analysis

image

After you configure and build your system, monitor system metrics and perform log collection, analysis, and alerting. Alibaba Cloud offers a comprehensive solution for system monitoring and log analysis. For details on configuring system monitoring, alerting, and log analysis, see the following documents: