tron-diasporapsycofr

phpIpfsCombo4

Jan 7th, 2025 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | Source Code | 0 0
  1. #Dockerfile for image Drakkar_ipfs update: 36161998
  2. #Use: docker run -d -p 5001:5001 -p 8080:8080 -p 8000:8000 -p 4001:4001 -v ipfsStorage:/root/.ipfs -v "$(pwd)":/var/www/html --name php_ipfs0 php-ipfs-combo4;
  3. FROM debian:bullseye-slim
  4.  
  5. # Install necessary dependencies, including PHP
  6. RUN apt-get update && apt-get install -y \
  7. curl tar php \
  8. && echo "Dependencies installed."
  9.  
  10. # Copy IPFS tarball from the host project directory into the container
  11. COPY go-ipfs_v0.14.0_linux-amd64.tar.gz /tmp/
  12.  
  13. # Extracting IPFS version v0.14.0 tarball... previous downloading to the projectBlank folder
  14. RUN tar -xvzf /tmp/go-ipfs_v0.14.0_linux-amd64.tar.gz -C /tmp/ \
  15. && mv /tmp/go-ipfs/ipfs /usr/local/bin/ \
  16. && chmod +x /usr/local/bin/ipfs \
  17. && rm -rf /tmp/go-ipfs /tmp/go-ipfs_v0.14.0_linux-amd64.tar.gz
  18.  
  19. # Expose the default IPFS API, Gateway, and PHP ports
  20. EXPOSE 5001
  21. EXPOSE 8080
  22. EXPOSE 8000
  23. EXPOSE 4001
  24.  
  25. # Copy the start.sh script and make it executable
  26. COPY start.sh /start.sh
  27. RUN chmod +x /start.sh
  28.  
  29. # Set working directory (for PHP server)
  30. WORKDIR /var/www/html
  31.  
  32. # Run the script when the container starts
  33. CMD ["/start.sh"]
  34.  
  35. Bash script
  36. #!/bin/bash
  37. #update: 36161998
  38.  
  39. HOST_DOCKERFILE_PATH="$(pwd)/Dockerfile"
  40. HOST_START_SH_PATH="$(pwd)/start.sh"
  41. HOST_LOG_PATH="$(pwd)/startup_log.txt"
  42.  
  43. CONTAINER_HOME_DOCKERFILE="/home/Dockerfile"
  44. CONTAINER_HOME_STARTUP="/home/start.sh"
  45. CONTAINER_HOME_LOG="/home/startup_log.txt"
  46.  
  47. # Function to write logs to both the host log file and standard output
  48. log_message() {
  49. echo "$1" | tee -a "$HOST_LOG_PATH"
  50. }
  51.  
  52. # Check if the volume ipfsStorage exists
  53. log_message "Checking if volume ipfsStorage exists..."
  54. if ! docker volume inspect ipfsStorage > /dev/null 2>&1; then
  55. log_message "Volume ipfsStorage does not exist. Creating it now..."
  56. docker volume create ipfsStorage
  57. else
  58. log_message "Volume ipfsStorage exists."
  59. fi
  60.  
  61. # Ensure correct file permissions for /mnt/ipfsStorage
  62. log_message "Ensuring correct file permissions for /mnt/ipfsStorage..."
  63. sudo chmod -R 700 "$volume_mountpoint"
  64. sudo chown -R $(id -u):$(id -g) "$volume_mountpoint"
  65.  
  66. # Initialize IPFS if not already initialized
  67. log_message "Checking if IPFS is initialized..."
  68. if [ ! -f "$volume_mountpoint/config" ]; then
  69. log_message "IPFS is not initialized. Initializing now..."
  70. ipfs init --profile server
  71. else
  72. log_message "IPFS is already initialized."
  73. fi
  74.  
  75. # Remove the repo.lock file if it exists (to avoid lock conflicts during startup)
  76. log_message "Checking for repo.lock to avoid conflicts..."
  77. lock_file="$volume_mountpoint/repo.lock"
  78. if [ -f "$lock_file" ]; then
  79. log_message "Removing repo.lock file to avoid conflicts..."
  80. rm -f "$lock_file"
  81. fi
  82.  
  83. # Configure IPFS API and Gateway to listen on 0.0.0.0
  84. log_message "Configuring IPFS API and Gateway to listen on 0.0.0.0..."
  85. ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
  86. ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
  87.  
  88. # Start the IPFS daemon in the background
  89. log_message "Starting the IPFS daemon..."
  90. ipfs daemon &
  91.  
  92. # Start the PHP built-in server on port 8000
  93. log_message "#Give the little birdie a drink, or it'll croak!."
  94. cp "$HOST_DOCKERFILE_PATH" "$CONTAINER_HOME_DOCKERFILE"
  95. cp "$HOST_START_SH_PATH" "$CONTAINER_HOME_STARTUP"
  96. log_message "#Starting the PHP server on port 8000 ... Startup process complete."
  97. cp "$HOST_LOG_PATH" "$CONTAINER_HOME_LOG"
  98.  
  99. #Remove the host log file
  100. rm -f "$HOST_LOG_PATH"
  101.  
  102. php -S 0.0.0.0:8000 -t /var/www/html
  103.  
  104. Script: start.sh
  105. #!/bin/bash
  106. #update: 36161998
  107.  
  108. HOST_DOCKERFILE_PATH="$(pwd)/Dockerfile"
  109. HOST_START_SH_PATH="$(pwd)/start.sh"
  110. HOST_LOG_PATH="$(pwd)/startup_log.txt"
  111.  
  112. CONTAINER_HOME_DOCKERFILE="/home/Dockerfile"
  113. CONTAINER_HOME_STARTUP="/home/start.sh"
  114. CONTAINER_HOME_LOG="/home/startup_log.txt"
  115.  
  116. # Function to write logs to both the host log file and standard output
  117. log_message() {
  118. echo "$1" | tee -a "$HOST_LOG_PATH"
  119. }
  120.  
  121. # Check if the volume ipfsStorage exists
  122. log_message "Checking if volume ipfsStorage exists..."
  123. if ! docker volume inspect ipfsStorage > /dev/null 2>&1; then
  124. log_message "Volume ipfsStorage does not exist. Creating it now..."
  125. docker volume create ipfsStorage
  126. else
  127. log_message "Volume ipfsStorage exists."
  128. fi
  129.  
  130. # Ensure correct file permissions for /mnt/ipfsStorage
  131. log_message "Ensuring correct file permissions for /mnt/ipfsStorage..."
  132. sudo chmod -R 700 "$volume_mountpoint"
  133. sudo chown -R $(id -u):$(id -g) "$volume_mountpoint"
  134.  
  135. # Initialize IPFS if not already initialized
  136. log_message "Checking if IPFS is initialized..."
  137. if [ ! -f "$volume_mountpoint/config" ]; then
  138. log_message "IPFS is not initialized. Initializing now..."
  139. ipfs init --profile server
  140. else
  141. log_message "IPFS is already initialized."
  142. fi
  143.  
  144. # Remove the repo.lock file if it exists (to avoid lock conflicts during startup)
  145. log_message "Checking for repo.lock to avoid conflicts..."
  146. lock_file="$volume_mountpoint/repo.lock"
  147. if [ -f "$lock_file" ]; then
  148. log_message "Removing repo.lock file to avoid conflicts..."
  149. rm -f "$lock_file"
  150. fi
  151.  
  152. # Configure IPFS API and Gateway to listen on 0.0.0.0
  153. log_message "Configuring IPFS API and Gateway to listen on 0.0.0.0..."
  154. ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
  155. ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
  156.  
  157. # Start the IPFS daemon in the background
  158. log_message "Starting the IPFS daemon..."
  159. ipfs daemon &
  160.  
  161. # Start the PHP built-in server on port 8000
  162. log_message "#Give the little birdie a drink, or it'll croak!."
  163. cp "$HOST_DOCKERFILE_PATH" "$CONTAINER_HOME_DOCKERFILE"
  164. cp "$HOST_START_SH_PATH" "$CONTAINER_HOME_STARTUP"
  165. log_message "#Starting the PHP server on port 8000 ... Startup process complete."
  166. cp "$HOST_LOG_PATH" "$CONTAINER_HOME_LOG"
  167.  
  168. #Remove the host log file
  169. rm -f "$HOST_LOG_PATH"
  170.  
  171. php -S 0.0.0.0:8000 -t /var/www/html
Tags: php p2p ipfs
Advertisement
Add Comment
Please, Sign In to add comment