A: Create file `.gitpod.yml`
Be sure you update the file so that you replace “THEME_NAME” with your theme name. Then commit the file your repo.
Here’s a high-level overview of the file.
image: This is the gitpod docker image file that we’re using. You haven’t yet added it to your repo, we’ll do that below.
tasks: There are three tasks defined. They are set up this way for efficiency. The “Build Theme” task doesn’t have a dependency on the “Build Application” task so they can run in parallel. The last task, “Open Browser” waits until “Build Theme” and “Build Application” are done and ends with launching the preview browser and delivering a one-time login link.
vscode: This is a list of the VS Code extensions that we use. Modify as you see fit.
ports: Port 8080 is the most important port, that’s the one you’ll use to view the website running in Gitpod. Note that the “visibility” flag is set to “open”. This means that anybody in the world can visit that URL while your workspace is running and see what you’re working on. This is very handy for collaborating with colleagues.
image:
file: .gitpod/.gitpod.dockerfile
tasks:
- name: Build Application
before: |
ddev config global --instrumentation-opt-in=true --web-environment="TERMINUS_MACHINE_TOKEN=$TERMINUS_MACHINE_TOKEN"
init: |
ddev start -y
ddev composer install
ddev pull pantheon --skip-confirmation --skip-files
command: gp sync-done build_application
- name: Build Theme
init: |
cd web/themes/custom/THEME_NAME
nvm use
npm install
npm run build-storybook -- -o storybook
node -v
command: gp sync-done build_theme
- name: Open Browser
command: |
gp sync-await build_application
gp sync-await build_theme
ddev start -y
ddev drush cr
gp preview $(gp url 8080)
ddev drush uli
# VScode extensions
vscode:
extensions:
# Twig language support
- mblode.twig-language-2
# YAML language support
- redhat.vscode-yaml
# PHP documentation block support
- neilbrayfield.php-docblocker
# PHP code intelligence
- bmewburn.vscode-intelephense-client
# Gherkin support for Behat test writing
- alexkrechik.cucumberautocomplete
# Drupal API support
- andrewdavidblum.drupal-smart-snippets
# Git Extension Pack including Git Lens
- donjayamanne.git-extension-pack
ports:
# Used by ddev - local db clients
- port: 3306
onOpen: ignore
# Used by MailHog
- port: 8027
onOpen: ignore
# Used by phpMyAdmin
- port: 8036
onOpen: ignore
# Direct-connect ddev-webserver port that is the main port
- port: 8080
onOpen: ignore
visibility: public
# Ignore host https port
- port: 8443
onOpen: ignore
# xdebug port
- port: 9003
onOpen: ignore
B: Create file `.gitpod/.gitpod.dockerfile`
Using the Bitucket interface I create this file which will also create the `.gitpod` directory in the project root.
You’ll want to update the NODE_VERSION environment variable to be whichever you use for your website. Then commit the file to your repo.
Honestly, it would be great if this script consumed up the node version from the .nvmrc file in our theme, so if you know how to do that, let me know!
FROM ddev/ddev-gitpod-base:20240516
ARG NODE_VERSION
ENV NODE_VERSION=16.14
ENV PNPM_HOME=/home/gitpod/.pnpm
ENV PATH=/home/gitpod/.nvm/versions/node/v${NODE_VERSION}/bin:/home/gitpod/.yarn/bin:${PNPM_HOME}:$PATH
RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | PROFILE=/dev/null bash \
&& bash -c ". .nvm/nvm.sh \
&& nvm install v${NODE_VERSION} \
&& nvm alias default v${NODE_VERSION} \
&& sudo chown -R 33333:33333 "/home/gitpod/.npm" \
&& npm install -g typescript yarn pnpm node-gyp" \
&& echo ". ~/.nvm/nvm-lazy.sh" >> /home/gitpod/.bashrc.d/50-node
# above, we are adding the lazy nvm init to .bashrc, because one is executed on interactive shells, the other for non-interactive shells (e.g. plugin-host)
COPY --chown=gitpod:gitpod .gitpod/nvm-lazy.sh /home/gitpod/.nvm/nvm-lazy.sh
C: Create file `.gitpod/nvm-lazy.sh`
Here are the contents of that file, no updates are needed. Then commit the file to your repo.
#!/bin/bash
export NVM_DIR="$HOME/.nvm"
node_versions=("$NVM_DIR"/versions/node/*)
if (("${#node_versions[@]}" > 0)); then
PATH="$PATH:${node_versions[$((${#node_versions[@]} - 1))]}/bin"
fi
if [ -s "$NVM_DIR/nvm.sh" ]; then
# load the real nvm on first use
nvm() {
# shellcheck disable=SC1090,SC1091
source "$NVM_DIR"/nvm.sh
nvm "$@"
}
fi
if [ -s "$NVM_DIR/bash_completion" ]; then
# shellcheck disable=SC1090,SC1091
source "$NVM_DIR"/bash_completion
fi