Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

create.sh 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #! /bin/sh
  2. #
  3. if [ ! -f "${PWD}/.env" ]; then
  4. echo "missing env file in ${PWD}"
  5. exit 1
  6. fi
  7. set -a
  8. . "${PWD}/.env"
  9. . "${PWD}/env_files/certs.env"
  10. . "${PWD}/env_files/project.env"
  11. set +a
  12. mkdir -p "/tmp/${PREFIX}"
  13. echo "Setting up docker volumes"
  14. docker volume create "${PREFIX}-db"
  15. docker volume create "${PREFIX}-root"
  16. docker volume create "${PREFIX}-traefik-certs"
  17. docker volume create "${PREFIX}-traefik-dynamic"
  18. docker volume create "${PREFIX}-traefik-logs"
  19. docker volume create "${PREFIX}-traefik-static"
  20. docker volume create "${PREFIX}-webroot"
  21. docker volume create wp-cli-cache
  22. docker volume create composer-cache
  23. echo "Copying SSL certificates to traefik volume"
  24. if [ ! -f "${SSL_CRT_LOCATION}/${SSL_CRT_NAME}" ] || [ ! -f "${SSL_KEY_LOCATION}/${SSL_KEY_NAME}" ]; then
  25. echo "Missing SSL key or cert file"
  26. exit 1
  27. fi
  28. docker run \
  29. --rm \
  30. --volume "${PREFIX}-traefik-certs":/certs \
  31. --volume "${SSL_CRT_LOCATION}":/source \
  32. ubuntu \
  33. cp "/source/${SSL_CRT_NAME}" /certs
  34. docker run \
  35. --rm \
  36. --volume "${PREFIX}-traefik-certs":/certs \
  37. --volume "${SSL_KEY_LOCATION}":/source \
  38. ubuntu \
  39. cp "/source/${SSL_KEY_NAME}" /certs
  40. echo "Generating traefik configuration files (ssl.yml and middlewares.yml)"
  41. cat << EOF > /tmp/${PREFIX}/ssl.yml
  42. ---
  43. tls:
  44. stores:
  45. default:
  46. defaultCertificate:
  47. certFile: /certs/${SSL_CRT_NAME}
  48. keyFile: /certs/${SSL_KEY_NAME}
  49. EOF
  50. cat << EOF > /tmp/${PREFIX}/middlewares.yml
  51. ---
  52. http:
  53. middlewares:
  54. https-redirect:
  55. redirectscheme:
  56. scheme: https
  57. permanent: true
  58. EOF
  59. docker run \
  60. --rm \
  61. --volume "/tmp/${PREFIX}":/source \
  62. --volume "${PREFIX}-traefik-dynamic":/destination \
  63. ubuntu \
  64. cp /source/ssl.yml /source/middlewares.yml /destination
  65. echo "Generating traefik static configuration"
  66. cat << EOF > /tmp/${PREFIX}/static.yml
  67. ---
  68. api:
  69. dashboard: true
  70. entrypoints:
  71. http:
  72. address: :80
  73. https:
  74. address: :443
  75. log:
  76. filepath: /logs/traefik.log
  77. level: debug
  78. providers:
  79. docker:
  80. exposedbydefault: false
  81. file:
  82. directory: /etc/traefik/dynamic
  83. watch: true
  84. EOF
  85. docker run \
  86. --rm \
  87. --volume "/tmp/${PREFIX}":/source \
  88. --volume "${PREFIX}-traefik-static":/destination \
  89. ubuntu \
  90. cp /source/static.yml /destination/traefik.yml
  91. docker compose up -d app
  92. while ! docker ps -q -f name="${PREFIX}-app"; do
  93. echo "Waiting for the web container to be up and running..."
  94. sleep 1
  95. done
  96. docker compose up -d db
  97. while ! docker ps -q -f name="${PREFIX}-db"; do
  98. echo "Waiting for the db container to be up and running..."
  99. sleep 1
  100. done
  101. while ! docker exec "${PREFIX}-app" /bin/sh -c "mysqladmin ping -h ${PREFIX}-db -P 3306 --protocol=tcp -u user -puser --silent"; do
  102. echo "Waiting for the mysql server in the db container to be up and running and reachable from the app container..."
  103. sleep 1
  104. done
  105. if [ "${PROJECT_TYPE}" = "laravel" ]; then
  106. echo "Installing laravel"
  107. docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer create-project --prefer-dist laravel/laravel /var/www/html '${LAREVEL_VERSION}'"
  108. fi
  109. if [ "${PROJECT_TYPE}" = "livewire" ]; then
  110. echo "Installing livewire"
  111. docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer create-project --prefer-dist laravel/laravel /var/www/html '${LARAVEL_VERSION}'"
  112. docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer require livewire/livewire ${LIVEWIRE_VERSION}"
  113. fi
  114. if [ "${PROJECT_TYPE}" = "wintercms" ]; then
  115. echo "Installing laravel"
  116. docker exec --user www-data --workdir "/var/www/html" "${PREFIX}-app" /bin/sh -c "composer create-project wintercms/winter /var/www/html '${LAREVEL_VERSION}'"
  117. fi
  118. if [ "${PROJECT_TYPE}" = "wordpress" ]; then
  119. echo "Downloading WordPress core"
  120. docker exec --user www-data "${PREFIX}-app" /bin/sh -c "
  121. wp core download \
  122. --locale=${WP_LOCALE} \
  123. --path=/var/www/html \
  124. --version=${WP_VERSION}"
  125. echo "Creating WordPress config"
  126. docker exec --user www-data "${PREFIX}-app" /bin/sh -c '
  127. wp config create \
  128. --dbhost='"${PREFIX}-db"' \
  129. --dbname='"${DB_NAME}"' \
  130. --dbpass='"${DB_USER_PASSWORD}"' \
  131. --dbuser='"${DB_USER}"' \
  132. --force \
  133. --path=/var/www/html \
  134. --skip-check \
  135. --extra-php <<EXTRA-PHP
  136. if (isset(\$_SERVER["HTTP_X_FORWARDED_PROTO"]) && \$_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") \$_SERVER["HTTPS"]="on";
  137. EXTRA-PHP
  138. '
  139. echo "Installing WordPress core"
  140. docker exec --user www-data "${PREFIX}-app" /bin/sh -c "
  141. wp core install \
  142. --admin_email=no@mail.com \
  143. --admin_password=${WP_ADMIN_PASSWORD} \
  144. --admin_user=${WP_ADMIN_USERNAME} \
  145. --path=/var/www/html \
  146. --skip-email \
  147. --title=${PREFIX} \
  148. --url=${WP_DEFAULT_PROTOCOL}://${APP_URL}"
  149. echo "Installing WordPress "${WP_THEME}" theme"
  150. docker exec --user www-data "${PREFIX}-app" /bin/sh -c "
  151. wp theme install ${WP_THEME} \
  152. --activate \
  153. --path=/var/www/html"
  154. fi
  155. docker compose up -d adminer
  156. docker compose up -d app
  157. docker compose up -d traefik