Skip to content

Commit

Permalink
Merge pull request #10 from mandrasch/feat-add-gitpod
Browse files Browse the repository at this point in the history
Feat add gitpod
  • Loading branch information
mandrasch authored May 25, 2024
2 parents 7fe5385 + 53d6bfa commit 2d1673b
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ database:
use_dns_when_possible: true
composer_version: "2"
web_environment:
- GITPOD_WORKSPACE_URL
- CODESPACES
- CODESPACE_NAME
- GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN
nodejs_version: "20"
nodejs_version: "20.13.1"
corepack_enable: false
web_extra_exposed_ports:
- name: craft-vite
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"label": "web https"
},
// our custom vite port for ddev + codespaces
"5174":{
"5173":{
"label": "vite"
}
},
Expand Down
43 changes: 13 additions & 30 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ wait_for_docker() {

wait_for_docker

# TODO: remove, might not be needed (auto-detected)
# https://github.com/ddev/ddev/pull/5290#issuecomment-1689024764
ddev config global --omit-containers=ddev-router

Expand All @@ -30,35 +31,17 @@ ddev debug download-images
# avoid errors on rebuilds
ddev poweroff

# Workaround for vite:
# We expose port 5174 for vite on codespaces, because ddev-router is not used on codespace instances.
# Routing is handled by codespaces itself. This will create an additional config file for DDEV
# which will expose port 5174. This port needs to be set to public + HTTPS manually in ports tab,
# otherwise CORS errors will occur. See config/vite.php and vite.config.js as well.

if [ ! -f ".ddev/docker-compose.codespaces-vite.yaml" ]; then
echo "Creating vite port workaround file for port exposing ..."
# create workaround file for port exposing (if it does not exist yet)
# info: this file should not be commited to git since it shouldn't be used on local DDEV
cat >.ddev/docker-compose.codespaces-vite.yaml <<EOL
services:
web:
ports:
- 5174:5174
EOL

fi

# start ddev project
ddev start -y

# DDEV will automatically set the codespaces preview URL in .env.
# If this is not working in future, you can use this snippet for replacement:
# ddev exec 'sed -i "/PRIMARY_SITE_URL=/c APP_URL=$DDEV_PRIMARY_URL" .env'
# Workaround for Vite:
# Normally expose port 5173 for Vite in .ddev/config.yaml, but ddev-router
# is not used on Gitpod / Codespaces, etc. The Routing is handled by Gitpod /
# Codespaces itself. Therefore we will create an additional config file for
# DDEV which will expose port 5173 without ddev-router.
cp .devcontainer/templates/docker-compose.vite-workaround.yaml .ddev/.

# Current workaround for https://github.com/ddev/ddev/issues/5256,
# can be removed later if PR is merged in next ddev version
ddev exec 'sed -i "s/preview.app.github.dev/app.github.dev/g" .env'
# Start the DDEV project
# (will automatically get URL from env, adds db connection to .env)
export DDEV_NONINTERACTIVE=true
ddev start -y

# normal project setup
ddev composer install
Expand All @@ -76,10 +59,10 @@ ddev craft install/craft \
[email protected] \
--site-name=Testsite

# You could also remove it here and run this in codespaces terminal, it will just prompt for your password:
# You could also remove it here and run this in terminal, it will just prompt for your password:
# ddev craft install/craft --username=admin [email protected] --site-name=Testsite

# If craft was also installed (e.g. when you do a codespaces rebuild/full rebuild), this command
# If craft was also installed (e.g. when you do a rebuild/full rebuild), this command
# will just state "craft already installed".

# install the vite plugin by nystudio107 after fresh install
Expand Down
7 changes: 7 additions & 0 deletions .devcontainer/templates/docker-compose.vite-workaround.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See postCreateCommand.sh for more information - expose the Vite port without using
# ddev router (disabled on Gitpod/Codespaces,etc.). This file should not be committed
# to git since it conflicts with local DDEV usage (with ddev router)
services:
web:
ports:
- 5173:5173
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
# vite builds
/web/dist/

# config file only used for exposing vite port on codespaces
/.ddev/docker-compose.codespaces-vite.yaml
# only needed for gitpod and codespaces
.ddev/docker-compose.vite-workaround.yaml
70 changes: 70 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ddev v1.23.1
# https://github.com/ddev/ddev-gitpod-launcher
# https://hub.docker.com/r/ddev/ddev-gitpod-base
image: ddev/ddev-gitpod-base:20240516

# Based on
# https://github.com/ddev/ddev-gitpod-launcher/blob/main/.gitpod.yml
# https://github.com/shaal/DrupalPod/blob/main/.gitpod.yml

# ddev and composer are running as part of the prebuild
# when starting a Gitpod workspace all docker images are ready
tasks:
- name: prepare
init: |
ddev debug download-images
command: |
chmod +x .gitpod/project-setup.sh
.gitpod/project-setup.sh
gp ports await 8080 && sleep 1 && gp preview $(gp url 8080)
echo "The system is ready, happy developing!"
code src/scss/app.scss
ddev npm run dev
vscode:
extensions:
# PHP extensions.
- felixfbecker.php-debug
- bmewburn.vscode-intelephense-client

# Prettier
- esbenp.prettier-vscode

# Twig
- mblode.twig-language-2
# - moetelo.twiggy
# or use https://github.com/zackad/prettier-plugin-twig-melody

# Bash extensions.
- timonwong.shellcheck
- rogalmic.bash-debug

ports:
# Vite port
- port: 5173
onOpen: ignore
visibility: public
# Used by ddev - local db clients
- port: 3306
onOpen: ignore
# Used by projector
- port: 6942
onOpen: ignore
# Used by Mailpit
- port: 8025
onOpen: ignore
# Mailpit web UI
- port: 8027
onOpen: ignore
# Direct-connect ddev-webserver port that is the main port
- port: 8080
onOpen: ignore
# Ignore host https port
- port: 8443
onOpen: ignore
# xdebug port
- port: 9003
onOpen: ignore
# projector port
- port: 9999
onOpen: open-browser
44 changes: 44 additions & 0 deletions .gitpod/project-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# Prepare vscode-xdebug setup
mkdir -p .vscode
cp .gitpod/templates/launch.json .vscode/.

# Workaround for Vite:
# Normally expose port 5173 for Vite in .ddev/config.yaml, but ddev-router
# is not used on Gitpod / Codespaces, etc. The Routing is handled by Gitpod /
# Codespaces itself. Therefore we will create an additional config file for
# DDEV which will expose port 5173 without ddev-router.
cp .gitpod/templates/docker-compose.vite-workaround.yaml .ddev/.

# Start the DDEV project
# (will automatically get URL from env, adds db connection to .env)
export DDEV_NONINTERACTIVE=true
ddev start -y

# Prepare Laravel website
ddev composer install
ddev npm install

ddev craft install/craft \
--interactive=0 \
--username=admin \
--password=newPassword \
[email protected] \
--site-name=Testsite

# You could also remove it here and run this in terminal, it will just prompt for your password:
# ddev craft install/craft --username=admin [email protected] --site-name=Testsite

# If craft was also installed (e.g. when you do a rebuild/full rebuild), this command
# will just state "craft already installed".

# install the vite plugin by nystudio107 after fresh install
ddev craft plugin/install vite

# Further steps - you could also import a database here:
# ddev import-db --file=dump.sql.gz
# if you import a dump, you might need:
# ddev craft setup/keys
# or use 'ddev pull' to get latest db / files from remote
# https://ddev.readthedocs.io/en/stable/users/providers/
7 changes: 7 additions & 0 deletions .gitpod/templates/docker-compose.vite-workaround.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See postCreateCommand.sh for more information - expose the Vite port without using
# ddev router (disabled on Gitpod/Codespaces,etc.). This file should not be committed
# to git since it conflicts with local DDEV usage (with ddev router)
services:
web:
ports:
- 5173:5173
42 changes: 42 additions & 0 deletions .gitpod/templates/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"label": "Auto-open css file",
"type": "shell",
"command": "code resources/css/app.css",
"runOptions": {
"runOn": "folderOpen"
},
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": false
}
},
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"hostname": "0.0.0.0",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceRoot}"
}
},
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (select script from list of sh files)",
"cwd": "${workspaceFolder}",
"program": "${command:SelectScriptName}",
"args": []
}
]
}
Loading

0 comments on commit 2d1673b

Please sign in to comment.