tron-diasporapsycofr

php_ipfs_combo0

Jan 5th, 2025 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 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. sript bash: start.sh
  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
Advertisement
Add Comment
Please, Sign In to add comment