From c29805d857d6316b3972f25b7915359f9dd0ed8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Sch=C3=B6ldstr=C3=B6m?= Date: Sun, 21 May 2023 12:32:55 -0300 Subject: [PATCH] Add devcontainer --- .devcontainer/devcontainer.json | 32 ++++++++++++++++++++++++++++++++ .devcontainer/setup_project.sh | 22 ++++++++++++++++++++++ README.md | 25 +++++++++++++++++++++++-- config/application.php | 7 +++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/setup_project.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..bb1dd9c7 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,32 @@ +{ + "image": "mcr.microsoft.com/devcontainers/universal:2", + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:1": {}, + "ghcr.io/ddev/ddev/install-ddev:latest": {} + }, + "portsAttributes": { + "3306": { + "label": "database" + }, + "8027": { + "label": "mailhog" + }, + "8036": { + "label": "phpmyadmin" + }, + "8080": { + "label": "web http" + }, + "8443": { + "label": "web https" + } + }, + "extensions": [ + "EditorConfig.EditorConfig", + "xdebug.php-debug", + "bmewburn.vscode-intelephense-client", + "cjhowe7.laravel-blade", + "github.vscode-github-actions" + ], + "postCreateCommand": "bash .devcontainer/setup_project.sh" +} diff --git a/.devcontainer/setup_project.sh b/.devcontainer/setup_project.sh new file mode 100644 index 00000000..c19f9401 --- /dev/null +++ b/.devcontainer/setup_project.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -eu -o pipefail +set -x + +export DDEV_NONINTERACTIVE=true + +ddev config global --omit-containers=ddev-router +ddev debug download-images + +ddev stop -a +ddev start -y + +npm config set "//npm.fontawesome.com/:_authToken" $NPM_FONTAWESOME_AUTH_TOKEN +composer config --global http-basic.satispress.generodigital.com $SATISPRESS_API_KEY $SATISPRESS_PASSWORD +composer config --global github-oauth.github.com $GITHUB_TOKEN + +cp .env.example .env +sed -i "s/WP_HOME=.*/WP_HOME='https:\/\/$CODESPACE_NAME-8080.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN'/" .env + +mkdir -p ~/.ssh +chmod 700 ~/.ssh diff --git a/README.md b/README.md index 9683d74d..2c496496 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,6 @@ You will need an authentication token, we have a shared one added to LastPass/1P _If you are on Windows you should read the latest DDEV documentation and recommendations for getting things running. You'll need to run all composer, npm, robo and dep commands from within the DDEV container. Remember to send your SSH keys to container using `ddev auth ssh`_ -### Setup and run project - # Clone the repository and install the development dependencies. git clone --recursive git@github.com:generoi/bedrock.git gdsbedrock cd gdsbedrock @@ -82,6 +80,29 @@ Additional useful tasks ./vendor/bin/dep ./vendor/bin/wp +## Remote project development with GitHub codespaces + + # Create a codespace and install development tools when the setup tasks are done + composer install:development + cd web/app/themes/gds && npm run build + + # Option 1: Retrieve database by SSH into codespace with your keys + # ---------------------------------------------------------------- + gh codespace ssh -- -o ForwardAgent=yes + + # Option 2: Retrieve database through a personal codespace secret + # --------------------------------------------------------------- + echo -e "$PERSONAL_KINSTA_DEPLOY_KEY" >| ~/.ssh/private-key + chmod 600 ~/.ssh/private-key + eval `ssh-agent` + ssh-add + + # Pull the database + ./vendor/bin/robo db:pull @production + ./vendor/bin/robo db:search-replace @ddev 'gdsbedrock.ddev.site' "$CODESPACE_NAME-8080.$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" + +## Deploy + ### Deploying with GitHub actions Go to [GitHub Actions deploy_production.yml](https://github.com/generoi/gdsbedrock/actions/workflows/deploy_production.yml) workflow and trigger a deploy. diff --git a/config/application.php b/config/application.php index 2fc1d8ec..dc91ee8c 100644 --- a/config/application.php +++ b/config/application.php @@ -152,6 +152,13 @@ $_SERVER['HTTPS'] = 'on'; } +/** + * Support reverse proxy on codespaces/ddev + */ +if (env('IS_DDEV_PROJECT') && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; +} + $env_config = __DIR__ . '/environments/' . WP_ENV . '.php'; if (file_exists($env_config)) {