Skip to content

Commit f9bb8b0

Browse files
authored
Merge pull request #20 from UCEAP/reorg-scripts
Consolidate command line scripts
2 parents fd79ac2 + f531b86 commit f9bb8b0

34 files changed

Lines changed: 608 additions & 193 deletions

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.insertSpaces": false
3+
}

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ FROM mcr.microsoft.com/devcontainers/php:8.3
44
RUN sed -i 's/^UMASK\s*022/UMASK 002/' /etc/login.defs
55
RUN usermod -aG www-data vscode
66

7+
# Add glow for formatting command usage output (and because it's just nice)
8+
RUN mkdir -p /etc/apt/keyrings \
9+
&& curl -fsSL https://repo.charm.sh/apt/gpg.key | gpg --dearmor -o /etc/apt/keyrings/charm.gpg \
10+
&& echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | tee /etc/apt/sources.list.d/charm.list
11+
712
# Install MariaDB and Redis and PHP (incl Apache) and Cypress dependencies
813
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
914
&& apt-get install -y libpng-dev libzip-dev libicu-dev \
@@ -14,7 +19,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
1419
&& docker-php-ext-enable redis zip \
1520
&& apt-get install -y mariadb-client redis-tools \
1621
&& apt-get install -y npm libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb \
17-
&& apt-get install -y dnsutils pv \
22+
&& apt-get install -y dnsutils glow pv \
1823
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
1924

2025
# Configure PHP, make memory_limit and upload_max_filesize match Pantheon
@@ -34,12 +39,6 @@ RUN sed -i 's/Listen\s*80$/# Listen 80/' /etc/apache2/ports.conf
3439
RUN curl -L https://github.com/pantheon-systems/terminus/releases/latest/download/terminus.phar --output /usr/local/bin/terminus
3540
RUN chmod +x /usr/local/bin/terminus
3641

37-
# Copy devcontainer scripts
38-
COPY uceap-drupal-dev-* /usr/local/bin/
39-
RUN mkdir -p /usr/local/etc/uceap-dev
40-
COPY example.drush.yml /usr/local/etc/uceap-dev
41-
COPY vscode-*.json /usr/local/etc/uceap-dev
42-
4342
# Install atuin
4443
#
4544
# # The recommended way to install atuin is to use cargo, but that takes *forever*:
@@ -52,3 +51,6 @@ RUN curl -sL $(curl -s https://api.github.com/repos/atuinsh/atuin/releases/lates
5251

5352
# Our base image has an ancient version of gh cli in apt, so we download the latest version instead
5453
RUN curl -sL $(curl -s https://api.github.com/repos/cli/cli/releases/latest | jq -r '.assets[] | select(.name | endswith("_linux_'`uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`'.tar.gz")) | .browser_download_url') | tar zx --no-same-owner --wildcards --absolute-names --transform 's,[^/]*,/usr/local,' '*/gh'
54+
55+
# Copy our scripts and template files
56+
COPY local /usr/local/

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@ A docker image supporting [GitHub Codespaces](https://github.com/features/codesp
22

33
Refer to the UCEAP Software Engineering Playbook for more information on how to [setup your development environment](https://itse-playbook.uceap.work/fundamentals/setup-your-development-environment/).
44

5-
## Personalization
6-
7-
Devcontainers support dotfiles!
8-
9-
See the [GitHub documentation](https://docs.github.com/en/codespaces/setting-your-user-preferences/personalizing-github-codespaces-for-your-account#dotfiles) for more info, and check out [Brandt's personal dotfiles](https://github.com/kurowski/dotfiles) for an example.
10-
11-
Visual Studio Code users should also look into the settings available in the Dev Containers extension, such as [Default Extensions](vscode://settings/dev.containers.defaultExtensions) to automatically install your favorite extensions in devcontainers.
125

13-
## Quality of life
6+
## Helper script
147

15-
This image includes several scripts that integrate with the devcontainer lifecycle, but these can also be used independently:
8+
This image includes a helper script that provides several commands to support features offered by this container. There are three main types of commands:
169

17-
* `/usr/local/bin/uceap-drupal-dev-on-create`
18-
* `/usr/local/bin/uceap-drupal-dev-post-create`
19-
* `/usr/local/bin/uceap-drupal-dev-post-start`
20-
* `/usr/local/bin/uceap-drupal-dev-update-content`
10+
- __deploy-*__: perform deployments to various environments
11+
- __devcontainer-*__: implementations of devcontainer lifecycle hooks
12+
- _all others_: functionality to support the local developer experience
2113

22-
It also includes one that doesn't fit into the devcontainer lifecycle, but performs similar tasks:
14+
To see a list of available commands, run `uceap` in the terminal. You can also run `uceap help <command>` to see more information about a specific command.
2315

24-
* `/usr/local/bin/uceap-drupal-dev-refresh-content`
16+
## Tips and tricks
2517

26-
I frequently invoke `uceap-drupal-dev-refresh-content` to reset my local environment after switching branches. It runs `composer install` and invokes `db-rebuild.sh` with a fresh copy of the latest snapshot of the dev environment database and files. With zsh completions installed, it's as easy as `dev-re<TAB>`.
18+
I frequently invoke `uceap refresh-content` to reset my local environment after switching branches. It runs `composer install` and invokes `db-rebuild.sh` with a fresh copy of the latest snapshot of the dev environment database and files. With shell completions installed, it's as easy as `uce<TAB>r<TAB>`.
2719

2820
> 👉 When working on a PR that adds update hooks or makes config changes, it's generally a good idea to make sure it applies cleanly to a database matching the QA environment. To do this, switch to the `qa` branch, run refresh-content, switch back to your branch, and run the deploy command (e.g. `drush md` for the portal):
2921
> ``` zsh
3022
> git checkout qa
31-
> uceap-drupal-dev-refresh-content
23+
> uceap refresh-content
3224
> git checkout -
3325
> composer install
3426
> drush $DRUSH_TASK
3527
> ```
3628
37-
Sometimes a process can die or port forwarding can fail. `uceap-drupal-dev-post-start` runs a few commands that should get things working again. (Again, zsh shell completion makes this `post-s<TAB>`).
29+
Sometimes a process can die or port forwarding can fail. `uceap devcontainer-post-start` runs a few commands that should get things working again. (Again, shell completion makes this `uce<TAB>sta<TAB>`).
30+
31+
Using devcontainers facilitates treating local environments as ephemeral: they're quick and easy to set up. Treat them as safe to destroy because you can always create a new one (or multiple new ones, to suit your needs). One thing you might miss is your shell history. Check out [Atuin](https://atuin.sh/) to sync your shell history across environments. `Control-R` has never looked so good 😎
3832
39-
Using devcontainers faciliates treating local environments as ephemeral: they're quick and easy to setup. Treat them as safe to destroy because you can always create a new one (or multiple new ones, to suit your needs). One thing you might miss is your shell history. Check out [Atuin](https://atuin.sh/) to sync your shell history across environments. `Control-R` has never looked so good 😎
33+
## Personalization
34+
35+
Devcontainers support dotfiles!
36+
37+
See the [GitHub documentation](https://docs.github.com/en/codespaces/setting-your-user-preferences/personalizing-github-codespaces-for-your-account#dotfiles) for more info, and check out [Brandt's personal dotfiles](https://github.com/kurowski/dotfiles) for an example.
38+
39+
Visual Studio Code users should also look into the settings available in the Dev Containers extension, such as [Default Extensions](vscode://settings/dev.containers.defaultExtensions) to automatically install your favorite extensions in devcontainers.

local/bin/uceap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# we often use this script in CI pipelines, so we treat every error as fatal
4+
set -eo pipefail
5+
6+
parent_dir=$(dirname "$0}")/..
7+
. $parent_dir/etc/uceap.sh
8+
9+
uceap "$@"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
uceap devcontainer-on-create
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
uceap devcontainer-post-create
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
uceap devcontainer-post-start
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
uceap devcontainer-refresh-content
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
uceap devcontainer-update-content
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function _assert_terminus_vars() {
2+
if [ -z "$TERMINUS_ENV" ]; then
3+
echo "TERMINUS_ENV environment variable is not set."
4+
exit 1
5+
fi
6+
7+
if [ -z "$TERMINUS_SITE" ]; then
8+
echo "TERMINUS_SITE environment variable is not set."
9+
exit 1
10+
fi
11+
12+
if [ -z "$DRUSH_TASK" ]; then
13+
echo "DRUSH_TASK environment variable is not set."
14+
exit 1
15+
fi
16+
}

0 commit comments

Comments
 (0)