Skip to content

Commit 635514c

Browse files
committed
add devcontainer scripts
1 parent 50acc36 commit 635514c

7 files changed

Lines changed: 134 additions & 0 deletions

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ RUN chmod +x /usr/local/bin/drush
3434
# Install terminus
3535
RUN curl -L https://github.com/pantheon-systems/terminus/releases/latest/download/terminus.phar --output /usr/local/bin/terminus
3636
RUN chmod +x /usr/local/bin/terminus
37+
38+
# Copy devcontainer scripts
39+
COPY uceap-drupal-dev-* /usr/local/bin/
40+
RUN mkdir -p /usr/local/etc/uceap-dev
41+
COPY example.drush.yml /usr/local/etc/uceap-dev
42+
COPY vscode-launch.json /usr/local/etc/uceap-dev

example.drush.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
options:
2+
uri: 'http://{{HTTP_ADDRESS}}'

uceap-drupal-dev-on-create

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# Change default umask and add user to web group so we can share write permission on web files
5+
sed -i 's/^#umask\s*022/umask 002/' ~/.profile
6+
echo "umask 002" >> ~/.zshrc
7+
echo "umask 002" >> ~/.bashrc
8+
9+
sudo sh -c "cat >> /etc/apache2/sites-available/000-default.conf" <<EOF
10+
<Directory /var/www/html>
11+
AllowOverride All
12+
</Directory>
13+
EOF
14+
15+
# This is how the example codespace changes the docroot. If it's good enough for them, it's good enough for me.
16+
sudo chmod a+x "$(pwd)" && sudo rm -rf /var/www/html && sudo ln -s "$(pwd)/web" /var/www/html
17+
18+
# Setup database
19+
sudo service mariadb start
20+
sudo mysql -u$MYSQL_USER -e "SET PASSWORD=PASSWORD('$MYSQL_PASSWORD')"
21+
cat <<EOF > ~/.my.cnf
22+
[client]
23+
user="$MYSQL_USER"
24+
password="$MYSQL_PASSWORD"
25+
EOF
26+
mysqladmin create $MYSQL_DATABASE
27+
28+
# and cache
29+
sudo service redis-server start
30+
31+
# translate mysql env vars to our template vars
32+
export DB_HOST="$MYSQL_HOST" DB_PORT="$MYSQL_TCP_PORT" DB_USER="$MYSQL_USER" DB_PASSWORD="$MYSQL_PASSWORD" DB_NAME="$MYSQL_DATABASE"
33+
34+
# Setup our Drupal app
35+
composer dev-initialize-local
36+
cat >> web/sites/default/settings.local.php <<EOF
37+
\$settings['trusted_host_patterns'] = [];
38+
39+
# make drupal play nice with codespace proxy
40+
\$settings['reverse_proxy'] = TRUE;
41+
\$settings['reverse_proxy_addresses'] = array(\$_SERVER['REMOTE_ADDR']);
42+
EOF
43+
44+
composer install
45+
composer compile-theme
46+
47+
# Set file permissions so both httpd and user can write to files
48+
chgrp www-data web/sites/default/files
49+
chmod g+s web/sites/default/files
50+
51+
# Setup VS Code
52+
mkdir -p .vscode
53+
cp /usr/local/etc/uceap-dev/vscode-launch.json .vscode/launch.json

uceap-drupal-dev-post-create

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Authenticate to Pantheon iff the user set a token env var
4+
if [[ -n "$TERMINUS_TOKEN" ]]; then
5+
terminus -n auth:login --machine-token="$TERMINUS_TOKEN"
6+
fi
7+
8+
# set global ServerName so that apachectl isn't chatty
9+
if [[ -n "$CODESPACE_NAME" ]]; then
10+
SERVER_NAME="$CODESPACE_NAME-8080.app.github.dev"
11+
HTTP_ADDRESS="$SERVER_NAME"
12+
else
13+
SERVER_NAME="localhost"
14+
HTTP_ADDRESS="$SERVER_NAME:8080"
15+
fi
16+
echo "ServerName $SERVER_NAME" | sudo tee /etc/apache2/conf-available/global-servername.conf
17+
sudo a2enconf global-servername
18+
19+
# Setup drush
20+
mkdir -p drush
21+
export HTTP_ADDRESS
22+
build/templater.sh /usr/local/etc/uceap-dev/example.drush.yml > drush/drush.yml

uceap-drupal-dev-post-start

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# make sure db and cache are running, just in case of restarts
4+
sudo service mariadb start
5+
sudo service redis-server start
6+
7+
# this seems to more reliably get the private proxy working
8+
sudo apache2ctl stop
9+
sudo apache2ctl start

uceap-drupal-dev-update-content

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# we need to preserve gitconfig if it already exists
5+
if [ -f ~/.gitconfig ]; then
6+
gitconfig_existed=true
7+
fi
8+
# ownership of the workspace directory won't match when using bindfs
9+
git config --global --add safe.directory "$(pwd)"
10+
# gh runs git, so we need to set the safe.directory in order for it to work
11+
gh release download --clobber --pattern '*.gz'
12+
# but later on vscode will try setting global git config (credential helper, etc) ONLY if gitconfig doesn't exist
13+
if [ ! $gitconfig_existed ]; then
14+
rm ~/.gitconfig
15+
fi
16+
# FWIW vscode will also fix the safe.directory setting
17+
18+
tar zx --no-same-permissions --strip-components 1 -C web/sites/default/files -f files.tar.gz
19+
rm files.tar.gz
20+
21+
# no-same-permissions doesn't seem to work so we fix it here
22+
sudo find web/sites/default/files -type d -exec chmod g+ws {} +
23+
sudo find web/sites/default/files -type f -exec chmod g+w {} +
24+
25+
# the first time we run this script the default umask is still in effect,
26+
# which messes up permissions on the profiler directory that gets created when the caches are rebuilt by db-rebuild.sh
27+
umask 002
28+
29+
sudo service mariadb start
30+
build/db-rebuild.sh database.sql.gz
31+
rm database.sql.gz

vscode-launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Listen for Xdebug",
6+
"type": "php",
7+
"request": "launch",
8+
"port": 9000
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)