Packaging Script
This section provides an example packaging script to illustrate how to package source components. The script packages the Docker source component (configuration file) into DockerConf.tar.gz following the original directory structure.
This script is only a packaging example and does not involve risky operations or cause source code leak.
- Create an .sh script file (for example, pack_docker_sources.sh) in any directory on the source VM. For details about the script content, see pack_docker_sources.sh.
- Run the script to complete the packaging process. After the packaging is complete, you can obtain the package file as prompted.
bash /path/to/pack_docker_sources.sh
View the following command output. The content in bold is the package path.
Checking the configuration files... Starting to compress the configuration files... /root/.docker/config.json /etc/docker/daemon.json /etc/systemd/system/docker.service.d/http-proxy.conf DockerConf/ DockerConf/config.json.tar.gz DockerConf/daemon.json.tar.gz DockerConf/http-proxy.conf.tar.gz Compression completed. The package is saved as /root/DockerConf.tar.gz.
/path/to: path to the script.
If you create a script on Windows and use it on Linux, the following error message may be displayed. This is because the two OSs use different newline characters. To rectify this error, perform the following steps:1-bash: ./pack_docker_sources.sh: /bin/bash^M: bad interpreter: No such file or directory
- Install dos2unix.
1yum install dos2unix
- After the installation is successful, run the following command:
1dos2unix pack_docker_sources.sh - After the execution is complete, restart the script.
If no Yum source is available and the installation fails, run the following command. After the execution is complete, restart the script.1sed -i 's/\r//g' pack_docker_sources.sh
- Install dos2unix.
- Obtain the source components using either of the following methods:
- If you select the Upload source component package option, return to the Add Component Information tab, and click Upload next to Upload source component package to upload the source component package.
- If you select the Obtain from node server option, run the following command to decompress the source component package.
- Log in to the tool through SSH and upload the package to the user-defined directory on Target Node.
- Set the package path to Source Component Path, for example, /home/DockerConf.tar.gz.
pack_docker_sources.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #!/bin/bash # Set the script error handling. set -e # Define the file path array to be checked. files=( "${HOME}/.docker/config.json" "/etc/docker/daemon.json" "/etc/systemd/system/docker.service.d/http-proxy.conf" ) # Check whether the configuration files exist. echo "Checking the configuration files..." existing_files=() for file in "${files[@]}"; do if [ -f "$file" ]; then existing_files+=("$file") fi done # If files are found, compression starts. if [ ${#existing_files[@]} -gt 0 ]; then echo "Starting to compress the configuration files..." # Create a temporary directory for storing the configuration files. temp_dir="${HOME}/DockerConf" mkdir -p "$temp_dir" # Compress the existing configuration files. for file in "${existing_files[@]}"; do file_name=$(basename "$file") tar -Pczvf "$temp_dir/${file_name}.tar.gz" "$file" done # Compress the Docker configuration files. cd "$HOME" && tar -czvf DockerConf.tar.gz DockerConf && rm -rf "$temp_dir" echo "Compression completed. The package is saved as ${HOME}/DockerConf.tar.gz" else echo "No configuration files are found for any of the source components. Select No source component available to migrate the middleware." fi |
Parent topic: Packaging the Docker Source Components