From 9de940b25cf27c52ee4ede463eda1fe7d7e5613b Mon Sep 17 00:00:00 2001 From: Lucas Thurston Date: Mon, 31 May 2021 16:35:50 -0700 Subject: [PATCH] [F] Add scaffold for craft / next proj --- cmd/brew-dockerize-craft-next | 14 ++++ cmd/brew-scaffold.rb | 6 ++ scaffold/docker_craft_next/README.md | 55 +++++++++++++++ scaffold/docker_craft_next/api/.env | 46 +++++++++++++ scaffold/docker_craft_next/api/.env.example | 46 +++++++++++++ scaffold/docker_craft_next/api/Dockerfile | 28 ++++++++ scaffold/docker_craft_next/api/scripts/README | 1 + .../docker_craft_next/api/scripts/composer.sh | 4 ++ .../docker_craft_next/api/scripts/database.sh | 26 +++++++ .../docker_craft_next/api/scripts/helpers.sh | 3 + .../docker_craft_next/api/scripts/plugins.sh | 22 ++++++ scaffold/docker_craft_next/api/scripts/run.sh | 30 ++++++++ scaffold/docker_craft_next/client/.env.local | 13 ++++ .../client/.env.local.example | 13 ++++ scaffold/docker_craft_next/client/Dockerfile | 20 ++++++ scaffold/docker_craft_next/data/pg/.gitkeep | 0 scaffold/docker_craft_next/docker-compose.yml | 62 +++++++++++++++++ .../docker/craft/php-fpm.conf | 69 +++++++++++++++++++ .../docker_craft_next/docker/craft/php.ini | 11 +++ .../docker_craft_next/docker/nginx/nginx.conf | 53 ++++++++++++++ .../docker_craft_next/script/craft/backup | 14 ++++ scaffold/docker_craft_next/script/craft/cli | 3 + .../docker_craft_next/script/craft/restore | 38 ++++++++++ scaffold/docker_craft_next/script/down | 6 ++ scaffold/docker_craft_next/script/server | 3 + scaffold/docker_craft_next/script/setup | 13 ++++ scaffold/docker_craft_next/script/up | 3 + 27 files changed, 602 insertions(+) create mode 100644 cmd/brew-dockerize-craft-next create mode 100644 scaffold/docker_craft_next/README.md create mode 100644 scaffold/docker_craft_next/api/.env create mode 100644 scaffold/docker_craft_next/api/.env.example create mode 100644 scaffold/docker_craft_next/api/Dockerfile create mode 100644 scaffold/docker_craft_next/api/scripts/README create mode 100644 scaffold/docker_craft_next/api/scripts/composer.sh create mode 100644 scaffold/docker_craft_next/api/scripts/database.sh create mode 100644 scaffold/docker_craft_next/api/scripts/helpers.sh create mode 100644 scaffold/docker_craft_next/api/scripts/plugins.sh create mode 100644 scaffold/docker_craft_next/api/scripts/run.sh create mode 100644 scaffold/docker_craft_next/client/.env.local create mode 100644 scaffold/docker_craft_next/client/.env.local.example create mode 100644 scaffold/docker_craft_next/client/Dockerfile create mode 100644 scaffold/docker_craft_next/data/pg/.gitkeep create mode 100644 scaffold/docker_craft_next/docker-compose.yml create mode 100644 scaffold/docker_craft_next/docker/craft/php-fpm.conf create mode 100644 scaffold/docker_craft_next/docker/craft/php.ini create mode 100644 scaffold/docker_craft_next/docker/nginx/nginx.conf create mode 100644 scaffold/docker_craft_next/script/craft/backup create mode 100644 scaffold/docker_craft_next/script/craft/cli create mode 100644 scaffold/docker_craft_next/script/craft/restore create mode 100644 scaffold/docker_craft_next/script/down create mode 100644 scaffold/docker_craft_next/script/server create mode 100644 scaffold/docker_craft_next/script/setup create mode 100644 scaffold/docker_craft_next/script/up diff --git a/cmd/brew-dockerize-craft-next b/cmd/brew-dockerize-craft-next new file mode 100644 index 0000000..97f6cdd --- /dev/null +++ b/cmd/brew-dockerize-craft-next @@ -0,0 +1,14 @@ +#!/bin/bash + +#GIT_IGNORE_LINE='docker-compose/mysql/data' +#GIT_IGNORE_FILE='.gitignore' +#if [ -f "$GIT_IGNORE_FILE" ]; then +# grep -qF -- "$GIT_IGNORE_LINE" "$GIT_IGNORE_FILE" || echo "$GIT_IGNORE_LINE" >> "$GIT_IGNORE_FILE" +#fi + +brew scaffold docker_october + + +echo "" +echo "==> See the updated README for next steps!" +echo "" diff --git a/cmd/brew-scaffold.rb b/cmd/brew-scaffold.rb index 848e638..9540ecf 100755 --- a/cmd/brew-scaffold.rb +++ b/cmd/brew-scaffold.rb @@ -31,6 +31,12 @@ end end +if type == "docker_craft_next" + unless File.exists?("api/composer.json") && File.exists?("client/package.json") + abort "The current directory does not appear to be the root of a Craft/Next project" + end +end + source_dir = File.join(template_dir, type) source_root_path = Pathname.new(source_dir) diff --git a/scaffold/docker_craft_next/README.md b/scaffold/docker_craft_next/README.md new file mode 100644 index 0000000..ac5b616 --- /dev/null +++ b/scaffold/docker_craft_next/README.md @@ -0,0 +1,55 @@ +## Development Environment + +This project uses Docker and Docker Compose to setup a development environment. You'll need to install a current version of Docker, which you can get here: https://docs.docker.com/docker-for-mac/install/ + +To setup this project for the first time, begin by eyeballing the `Dockerfile`s in the repo. There is one in the `api/` directory for Craft, and another in the `client/` directory for Next.js. Does the Craft `Dockerfile` contain the correct PHP version on the base image? Are you using the correct version of Composer? Is the correct Node version referenced in the Next Dockerfile? + +If you've just used `brew scaffold` to put required files in place, note that you will need to merge updated files and commit those changes +to version control. You can also delete the `config/dev` directory, and `Brewfile.*`. + +Then, follow these steps: + +``` +# Start up the containers. This will take longer the first time because +# Docker will need to build the containers. Every time you run this command +# the postgres database will be dropped and recreated if it already exists. +script/setup + +# Once the containers are built, fire them up! The first time, a new +# user with credentials `username` / `password` will be created, and Craft +# will be installed. +script/up + +# Note: script/server does the same thing as script/up! +``` + +The Craft backend will be accessible here: http://localhost:8000/admin +The Next.js frontend will be accessible here: http://localhost:3000 + +#### Other useful commands: + +``` +# Shorthand for `docker compose down`. Shuts down and removes all containers. +script/down + +# Run an Craft CLI command +script/craft/cli [[COMMAND]] + +# Here's one you'll likely need to write project config from database structure +docker compose exec craft php craft project-config/write + +# Add a node module +docker compose exec nextjs yarn add [[MODULE]] + +# Update a node module +docker compose exec nextjs yarn upgrade [[MODULE]] + +# Force rebuild of all container images +docker compose up --build --force-recreate --no-deps + +# Sync a site from staging +bundle exec cap staging content:sync +``` + +If you need to SSH into any of the running containers, use the Docker dashboard, +locate the container, and click the terminal icon. diff --git a/scaffold/docker_craft_next/api/.env b/scaffold/docker_craft_next/api/.env new file mode 100644 index 0000000..948e86c --- /dev/null +++ b/scaffold/docker_craft_next/api/.env @@ -0,0 +1,46 @@ +# The environment Craft is currently running in ("dev", "staging", "production", etc.) +ENVIRONMENT="dev" + +# The application ID used to to uniquely store session and cache data, mutex locks, and more +APP_ID="" + +# The secure key Craft will use for hashing and encrypting data +SECURITY_KEY= + +# The database driver that will be used ("mysql" or "pgsql") +DB_DRIVER="pgsql" + +# The database server name or IP address +DB_SERVER="pg" + +# The port to connect to the database with +DB_PORT="5432" + +# The name of the database to select +DB_DATABASE="pg" + +# The database username to connect with +DB_USER="pg" + +# The database password to connect with +DB_PASSWORD="pg" + +# The database schema that will be used (PostgreSQL only) +DB_SCHEMA="public" + +# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database) +DB_TABLE_PREFIX="" + +# Use these env var to reduce repetition, see HEROES example below +BASE_PATH=/var/www/html/web +PRIMARY_SITE_URL="http://localhost:8000" +DEFAULT_SITE_URL="http://localhost:8000" + +# HEROES_BASE_URL=${PRIMARY_SITE_URL}/assets/heroes +# HEROES_PATH=${BASE_PATH}/assets/heroes + +# Used by the scripts/run script when site is first created +CRAFTCMS_SITENAME="EN" + +# For generating previews +ALIAS_PREVIEW_URL_FORMAT=${DEFAULT_SITE_URL}/api/preview?entryUid={sourceUid} diff --git a/scaffold/docker_craft_next/api/.env.example b/scaffold/docker_craft_next/api/.env.example new file mode 100644 index 0000000..948e86c --- /dev/null +++ b/scaffold/docker_craft_next/api/.env.example @@ -0,0 +1,46 @@ +# The environment Craft is currently running in ("dev", "staging", "production", etc.) +ENVIRONMENT="dev" + +# The application ID used to to uniquely store session and cache data, mutex locks, and more +APP_ID="" + +# The secure key Craft will use for hashing and encrypting data +SECURITY_KEY= + +# The database driver that will be used ("mysql" or "pgsql") +DB_DRIVER="pgsql" + +# The database server name or IP address +DB_SERVER="pg" + +# The port to connect to the database with +DB_PORT="5432" + +# The name of the database to select +DB_DATABASE="pg" + +# The database username to connect with +DB_USER="pg" + +# The database password to connect with +DB_PASSWORD="pg" + +# The database schema that will be used (PostgreSQL only) +DB_SCHEMA="public" + +# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database) +DB_TABLE_PREFIX="" + +# Use these env var to reduce repetition, see HEROES example below +BASE_PATH=/var/www/html/web +PRIMARY_SITE_URL="http://localhost:8000" +DEFAULT_SITE_URL="http://localhost:8000" + +# HEROES_BASE_URL=${PRIMARY_SITE_URL}/assets/heroes +# HEROES_PATH=${BASE_PATH}/assets/heroes + +# Used by the scripts/run script when site is first created +CRAFTCMS_SITENAME="EN" + +# For generating previews +ALIAS_PREVIEW_URL_FORMAT=${DEFAULT_SITE_URL}/api/preview?entryUid={sourceUid} diff --git a/scaffold/docker_craft_next/api/Dockerfile b/scaffold/docker_craft_next/api/Dockerfile new file mode 100644 index 0000000..3d989be --- /dev/null +++ b/scaffold/docker_craft_next/api/Dockerfile @@ -0,0 +1,28 @@ +FROM craftcms/php-fpm:7.4-dev + +USER root + +# These are used by our startup scripts +RUN apk add bash jq findutils php7-pecl-xdebug + +# Came from https://github.com/urbantrout/craftcms. TODO: determine if this is necessary +RUN apk add gnu-libiconv --update-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Copy our scripts into the container and make them +X +COPY scripts/ /scripts/ +RUN chown -R www-data:www-data /scripts && chmod -R +x /scripts + +WORKDIR /var/www/html +RUN chown -R www-data:www-data . +USER www-data + +# Install Craft CMS and save original dependencies in file +RUN composer create-project craftcms/craft . \ + && cp composer.json composer.base + +ENTRYPOINT [ "/scripts/run.sh" ] + +CMD [ "docker-php-entrypoint", "php-fpm"] diff --git a/scaffold/docker_craft_next/api/scripts/README b/scaffold/docker_craft_next/api/scripts/README new file mode 100644 index 0000000..c1b1c20 --- /dev/null +++ b/scaffold/docker_craft_next/api/scripts/README @@ -0,0 +1 @@ +These scripts came from https://github.com/urbantrout/craftcms. diff --git a/scaffold/docker_craft_next/api/scripts/composer.sh b/scaffold/docker_craft_next/api/scripts/composer.sh new file mode 100644 index 0000000..692426b --- /dev/null +++ b/scaffold/docker_craft_next/api/scripts/composer.sh @@ -0,0 +1,4 @@ +install_composer_dependencies() { + cd /var/www/html + composer install +} diff --git a/scaffold/docker_craft_next/api/scripts/database.sh b/scaffold/docker_craft_next/api/scripts/database.sh new file mode 100644 index 0000000..7cc5d74 --- /dev/null +++ b/scaffold/docker_craft_next/api/scripts/database.sh @@ -0,0 +1,26 @@ +setup_database() { + declare zip_file + declare sql_file + + # Save DB credentials + echo $DB_SERVER:$DB_PORT:$DB_DATABASE:$DB_USER:$DB_PASSWORD >~/.pgpass + chmod 600 ~/.pgpass + + h2 "Setup Craft CMS (if necessary)" + + while ! pg_isready -h $DB_SERVER; do + h2 "Waiting for PostreSQL server" + sleep 1 + done + + cd /var/www/html && + ./craft setup/security-key && + ./craft install \ + --interactive=0 \ + --email="${CRAFTCMS_EMAIL:-office@castironcoding.com}" \ + --username="${CRAFTCMS_USERNAME:-admin}" \ + --password="${CRAFTCMS_PASSWORD:-password}" \ + --siteUrl="${CRAFTCMS_SITEURL:-@web}" \ + --language="${CRAFTCMS_LANGUAGE:-en-US}" + +} diff --git a/scaffold/docker_craft_next/api/scripts/helpers.sh b/scaffold/docker_craft_next/api/scripts/helpers.sh new file mode 100644 index 0000000..f347d10 --- /dev/null +++ b/scaffold/docker_craft_next/api/scripts/helpers.sh @@ -0,0 +1,3 @@ +h2() { + printf '\e[1;33m==>\e[37;1m %s\e[0m\n' "$*" +} diff --git a/scaffold/docker_craft_next/api/scripts/plugins.sh b/scaffold/docker_craft_next/api/scripts/plugins.sh new file mode 100644 index 0000000..50a884c --- /dev/null +++ b/scaffold/docker_craft_next/api/scripts/plugins.sh @@ -0,0 +1,22 @@ +activate_plugins() { + h2 'Activating Plugins.' + + cd /var/www/html + + dependencies=$(cat composer.json | + jq '.require' | + jq --compact-output 'keys' | + tr -d '[]"' | tr ',' '\n') + + for package in ${dependencies}; do + + vendor=$(awk -F '[\/:]+' '{print $1}' <<<$package) + packageName=$(awk -F '[\/:]+' '{print $2}' <<<$package) + isCraftPlugin=$(cat vendor/$vendor/$packageName/composer.json | jq '.type == "craft-plugin"') + + if [ "$isCraftPlugin" = true ]; then + handle=$(cat vendor/$vendor/$packageName/composer.json | jq -r '.extra.handle') + ./craft plugin/install $handle + fi + done +} diff --git a/scaffold/docker_craft_next/api/scripts/run.sh b/scaffold/docker_craft_next/api/scripts/run.sh new file mode 100644 index 0000000..7729ff9 --- /dev/null +++ b/scaffold/docker_craft_next/api/scripts/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +source /scripts/helpers.sh +source /scripts/database.sh +source /scripts/composer.sh +source /scripts/plugins.sh + +# This should only run the first time a project is set up and dependencies aren't in place yet. In all other cases +# the developer will be managing dependencies. +[ ! -d "/var/www/html/vendor" ] && install_composer_dependencies + +setup_database & +SETUP_PID=$! +DEPENDENDIES_PID=$! + +wait $SETUP_PID +wait $DEPENDENCIES_PID +activate_plugins + +wait + +h2 "✅ Visit http://localhost:8000 to start using Craft CMS." + +# Make sure PHP FPM has a log dir +[ ! -d "/var/www/html/log" ] && mkdir -p /var/www/html/log + +# Start php-fpm +exec "$@" diff --git a/scaffold/docker_craft_next/client/.env.local b/scaffold/docker_craft_next/client/.env.local new file mode 100644 index 0000000..46bd49b --- /dev/null +++ b/scaffold/docker_craft_next/client/.env.local @@ -0,0 +1,13 @@ +# Prepend "NEXT_PUBLIC_" to Next.js env vars to expose them as process.env.NEXT_PUBLIC_ANALYTICS_ID, for example +#NEXT_PUBLIC_ANALYTICS_ID= + +# API requests coming from server vs browser means different request domains. +# Make sure your code respects both. +NEXT_PUBLIC_PRIVATE_BASE_URL="http://nginx" +NEXT_PUBLIC_BASE_URL="http://localhost:8000" +NEXT_PUBLIC_API_URL_PREPEND="api/" + +NEXT_PUBLIC_SHARETHIS_PROPERTY= + +# This should not be present in Production, but it's OK for dev. +NODE_TLS_REJECT_UNAUTHORIZED=0 diff --git a/scaffold/docker_craft_next/client/.env.local.example b/scaffold/docker_craft_next/client/.env.local.example new file mode 100644 index 0000000..46bd49b --- /dev/null +++ b/scaffold/docker_craft_next/client/.env.local.example @@ -0,0 +1,13 @@ +# Prepend "NEXT_PUBLIC_" to Next.js env vars to expose them as process.env.NEXT_PUBLIC_ANALYTICS_ID, for example +#NEXT_PUBLIC_ANALYTICS_ID= + +# API requests coming from server vs browser means different request domains. +# Make sure your code respects both. +NEXT_PUBLIC_PRIVATE_BASE_URL="http://nginx" +NEXT_PUBLIC_BASE_URL="http://localhost:8000" +NEXT_PUBLIC_API_URL_PREPEND="api/" + +NEXT_PUBLIC_SHARETHIS_PROPERTY= + +# This should not be present in Production, but it's OK for dev. +NODE_TLS_REJECT_UNAUTHORIZED=0 diff --git a/scaffold/docker_craft_next/client/Dockerfile b/scaffold/docker_craft_next/client/Dockerfile new file mode 100644 index 0000000..ee5d2b5 --- /dev/null +++ b/scaffold/docker_craft_next/client/Dockerfile @@ -0,0 +1,20 @@ +FROM node:15.5.1-alpine3.10 + +ENV PORT 3000 +ENV PATH /usr/src/node_modules/.bin:$PATH + +# Create app directory +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +# Installing dependencies +COPY package*.json yarn.lock /usr/src/ +RUN yarn + +# Copying source files +COPY . /usr/src/app + +EXPOSE 3000 + +# Running the app +CMD ["yarn", "dev"] diff --git a/scaffold/docker_craft_next/data/pg/.gitkeep b/scaffold/docker_craft_next/data/pg/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scaffold/docker_craft_next/docker-compose.yml b/scaffold/docker_craft_next/docker-compose.yml new file mode 100644 index 0000000..02396f6 --- /dev/null +++ b/scaffold/docker_craft_next/docker-compose.yml @@ -0,0 +1,62 @@ +services: + craft: + build: + context: ./api + dockerfile: ./Dockerfile + restart: unless-stopped + working_dir: /var/www/html + depends_on: + - pg + environment: + DB_SERVER: pg + DB_PORT: 5432 + DB_DATABASE: pg + DB_USER: pg + DB_PASSWORD: pg + volumes: + - ./api:/var/www/html + - ./docker/craft/php.ini:/usr/local/etc/php/conf.d/custom.ini + - ./docker/craft/php-fpm.conf:/usr/local/etc/php-fpm.conf + nextjs: + build: + context: ./client + dockerfile: Dockerfile + depends_on: + - craft + ports: + - "3000:3000" + - "6006:6006" + volumes: + - ./client:/usr/src/app:delegated + - ./client/package.json:/usr/src/package.json + - ./client/yarn.lock:/usr/src/yarn.lock + - /usr/src/app/node_modules + - /usr/src/app/.next + environment: + - NEXT_PUBLIC_API_PRIVATE_URL + - NEXT_PUBLIC_API_URL + restart: unless-stopped + pg: + image: postgres:13.3-alpine + restart: unless-stopped + environment: + POSTGRES_PASSWORD: pg + POSTGRES_USER: pg + POSTGRES_DB: pg + volumes: + - ./data/pg:/srv/data + nginx: + image: nginx:alpine + restart: unless-stopped + depends_on: + - craft + ports: + - "8000:80" + volumes: + - ./docker/nginx:/etc/nginx/conf.d + - ./api/web:/var/www/html/web + - ./api/assets:/var/www/html/assets + +volumes: + pg-data: + driver: local diff --git a/scaffold/docker_craft_next/docker/craft/php-fpm.conf b/scaffold/docker_craft_next/docker/craft/php-fpm.conf new file mode 100644 index 0000000..6a9c5d5 --- /dev/null +++ b/scaffold/docker_craft_next/docker/craft/php-fpm.conf @@ -0,0 +1,69 @@ +;;;;;;;;;;;;;;;;;;;;; +; FPM Configuration ; +;;;;;;;;;;;;;;;;;;;;; + +; All relative paths in this configuration file are relative to PHP's install +; prefix (/usr). This prefix can be dynamicaly changed by using the +; '-p' argument from the command line. + +[global] +; Pid file +; Note: the default prefix is /var +; Default Value: none +pid = /tmp/php.pid + +; Error log file +; Note: the default prefix is /var +; Default Value: log/php-fpm.log +error_log = /var/www/html/log/php-fpm.log + +; Log level +; Possible Values: alert, error, warning, notice, debug +; Default Value: notice +;log_level = notice + +; If this number of child processes exit with SIGSEGV or SIGBUS within the time +; interval set by emergency_restart_interval then FPM will restart. A value +; of '0' means 'Off'. +; Default Value: 0 +;emergency_restart_threshold = 0 + +; Interval of time used by emergency_restart_interval to determine when +; a graceful restart will be initiated. This can be useful to work around +; accidental corruptions in an accelerator's shared memory. +; Available Units: s(econds), m(inutes), h(ours), or d(ays) +; Default Unit: seconds +; Default Value: 0 +;emergency_restart_interval = 0 + +; Time limit for child processes to wait for a reaction on signals from master. +; Available units: s(econds), m(inutes), h(ours), or d(ays) +; Default Unit: seconds +; Default Value: 0 +;process_control_timeout = 0 + +; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. +; Default Value: yes +daemonize = no + +;;;;;;;;;;;;;;;;;;;; +; Pool Definitions ; +;;;;;;;;;;;;;;;;;;;; + +; Multiple pools of child processes may be started with different listening +; ports and different management options. The name of the pool will be +; used in logs and stats. There is no limitation on the number of pools which +; FPM can handle. Your system will tell you anyway :) + +; To configure the pools it is recommended to have one .conf file per +; pool in the following directory: +[project] +listen = 9000 +listen.mode = 0666 +pm = dynamic +pm.start_servers = 1 +pm.min_spare_servers = 1 +pm.max_spare_servers = 1 +pm.max_children = 10 + +clear_env = no diff --git a/scaffold/docker_craft_next/docker/craft/php.ini b/scaffold/docker_craft_next/docker/craft/php.ini new file mode 100644 index 0000000..9919f9c --- /dev/null +++ b/scaffold/docker_craft_next/docker/craft/php.ini @@ -0,0 +1,11 @@ +[PHP] + +upload_max_filesize = 256M +post_max_size = 256M +memory_limit = 256M +max_execution_time = 120 + +[xdebug] + +xdebug.max_nesting_level = 2048 +xdebug.remote_enable = 1 diff --git a/scaffold/docker_craft_next/docker/nginx/nginx.conf b/scaffold/docker_craft_next/docker/nginx/nginx.conf new file mode 100644 index 0000000..4749b5e --- /dev/null +++ b/scaffold/docker_craft_next/docker/nginx/nginx.conf @@ -0,0 +1,53 @@ +server { + access_log /var/log/nginx.api.access.log combined; + listen 80 default_server; + root /var/www/html/web; + + client_max_body_size 100M; + client_body_timeout 600s; + proxy_send_timeout 600s; + proxy_read_timeout 600s; + fastcgi_no_cache 1; + error_page 500 502 503 504 /50x.html; + + location ~ \.php$ { + fastcgi_pass craft:9000; + fastcgi_param QUERY_STRING $query_string; + fastcgi_param REQUEST_METHOD $request_method; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_param CONTENT_LENGTH $content_length; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_param SCRIPT_FILENAME /var/www/html/web$fastcgi_script_name; + fastcgi_param SERVER_NAME $host; + fastcgi_param HTTPS $https; + + fastcgi_param REQUEST_URI $request_uri; + fastcgi_param DOCUMENT_URI $document_uri; + fastcgi_param DOCUMENT_ROOT $document_root; + fastcgi_param SERVER_PROTOCOL $server_protocol; + + fastcgi_param GATEWAY_INTERFACE CGI/1.1; + fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + + fastcgi_param REMOTE_ADDR $remote_addr; + fastcgi_param REMOTE_PORT $remote_port; + fastcgi_param SERVER_ADDR $server_addr; + fastcgi_param SERVER_PORT $server_port; + fastcgi_param SERVER_NAME $server_name; + + fastcgi_param REDIRECT_STATUS 200; + + fastcgi_index index.php; + fastcgi_read_timeout 3600s; + client_body_timeout 3600s; + send_timeout 3600s; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + } + + location / { + index index.html index.htm index.php; + try_files $uri /index.php$is_args$args; + } +} + diff --git a/scaffold/docker_craft_next/script/craft/backup b/scaffold/docker_craft_next/script/craft/backup new file mode 100644 index 0000000..a454465 --- /dev/null +++ b/scaffold/docker_craft_next/script/craft/backup @@ -0,0 +1,14 @@ +#!/bin/bash + +cd "$(dirname "$0")/.." + +BACKUP_FILE=backup-`date +"%m-%d-%y-%s"`.tar +SQL_FILE=dump.sql + +DB_DATABASE=$(grep DB_DATABASE api/.env | xargs) +DB_DATABASE=${DB_DATABASE#*=} + +pg_dump $DB_DATABASE -O -x --clean > $SQL_FILE +tar -cf $BACKUP_FILE $SQL_FILE api/assets +rm $SQL_FILE +echo $BACKUP_FILE diff --git a/scaffold/docker_craft_next/script/craft/cli b/scaffold/docker_craft_next/script/craft/cli new file mode 100644 index 0000000..015f971 --- /dev/null +++ b/scaffold/docker_craft_next/script/craft/cli @@ -0,0 +1,3 @@ +#!/bin/bash + +docker compose exec craft php craft $@ diff --git a/scaffold/docker_craft_next/script/craft/restore b/scaffold/docker_craft_next/script/craft/restore new file mode 100644 index 0000000..0d2fb5d --- /dev/null +++ b/scaffold/docker_craft_next/script/craft/restore @@ -0,0 +1,38 @@ +#!/bin/bash + +cd "$(dirname "$0")/.." + +RESTORE_ARCHIVE_PATH=$1 +RESTORE_ARCHIVE_FILE=$(basename $RESTORE_ARCHIVE_PATH) + +mkdir -p tmp-restore +cp $RESTORE_ARCHIVE_PATH tmp-restore/ +cd tmp-restore +tar -xf $RESTORE_ARCHIVE_FILE +cd .. + +if [ -f tmp-restore/dump.sql ] +then + mv tmp-restore/dump.sql data/pg/dump.sql + docker-compose exec -T pg dropdb -U pg pg + docker-compose exec -T pg createdb -U pg pg + docker-compose exec -T pg psql -U pg --file /srv/data/dump.sql pg + rm data/pg/dump.sql +fi + +if [ -d tmp-restore/api/assets ] +then + rm -rf api/assets + mv tmp-restore/api/assets api/ +fi + +rm -rf tmp-restore + +if [ -z `docker ps -q --no-trunc | grep $(docker compose ps -q craft)` ]; then + echo "Craft container is not running, so project config was not updated." + echo "Once the container is running, execute this command:" + echo "docker-compose exec craft php craft project-config/write" +else + echo "Updating Craft project config" + docker-compose exec -T craft php craft project-config/write +fi diff --git a/scaffold/docker_craft_next/script/down b/scaffold/docker_craft_next/script/down new file mode 100644 index 0000000..d084aa2 --- /dev/null +++ b/scaffold/docker_craft_next/script/down @@ -0,0 +1,6 @@ +#!/bin/bash + +docker compose down --remove-orphans --rmi local --volumes + +# The --volumes flag is not working as it should, so putting this here to make sure +docker volume rm ofb_pg-data diff --git a/scaffold/docker_craft_next/script/server b/scaffold/docker_craft_next/script/server new file mode 100644 index 0000000..5b74415 --- /dev/null +++ b/scaffold/docker_craft_next/script/server @@ -0,0 +1,3 @@ +#!/bin/bash + +docker compose up diff --git a/scaffold/docker_craft_next/script/setup b/scaffold/docker_craft_next/script/setup new file mode 100644 index 0000000..d2e7485 --- /dev/null +++ b/scaffold/docker_craft_next/script/setup @@ -0,0 +1,13 @@ +#!/bin/sh + +echo "==> Ensuring Ruby is installed (for capistrano)\n" +rbenv install -s + +echo "==> Creating .env files if they aren't present\n" +[ ! -f api/.env ] && cp api/.env{.example,} +[ ! -f client/.env.local ] && cp client/.env.local{.example,} + +echo "==> Rebuilding docker containers\n" +docker compose build + +echo "==> We're done here! Run script/up to start the project. The frontend will be at http://localhost:3000, the backend at http://localhost:8000/admin. See README.md for more info." diff --git a/scaffold/docker_craft_next/script/up b/scaffold/docker_craft_next/script/up new file mode 100644 index 0000000..5b74415 --- /dev/null +++ b/scaffold/docker_craft_next/script/up @@ -0,0 +1,3 @@ +#!/bin/bash + +docker compose up