-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevcontainer_on_create.sh
More file actions
114 lines (89 loc) · 4.38 KB
/
devcontainer_on_create.sh
File metadata and controls
114 lines (89 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function devcontainer_on_create() {
# Change default umask and add user to web group so we can share write permission on web files
sed -i 's/^#umask\s*022/umask 002/' ~/.profile
echo "umask 002" | tee -a ~/.bashrc ~/.zshrc ~/.zshrc.local
# the first time we run this script the default umask is still in effect,
# which messes up permissions on the log file that gets created when we run drush deploy
umask 002
sudo sh -c "cat >> /etc/apache2/sites-available/000-default.conf" <<-EOF
<Directory /var/www/html>
AllowOverride All
</Directory>
EOF
# This is how the example codespace changes the docroot. If it's good enough for them, it's good enough for me.
sudo chmod a+x "$(pwd)" && sudo rm -rf /var/www/html && sudo ln -s "$(pwd)/web" /var/www/html
# Setup database if MYSQL_HOST = 127.0.0.1
cat >~/.my.cnf <<-EOF
[client]
host="$MYSQL_HOST"
user="$MYSQL_USER"
password="$MYSQL_PASSWORD"
skip-ssl
EOF
# translate mysql env vars to our template vars
export DB_HOST="$MYSQL_HOST" DB_PORT="$MYSQL_TCP_PORT" DB_USER="$MYSQL_USER" DB_PASSWORD="$MYSQL_PASSWORD" DB_NAME="$MYSQL_DATABASE"
# Setup our Drupal app
composer dev-initialize-local
cat >>web/sites/default/settings.local.php <<-EOF
\$settings['trusted_host_patterns'] = [];
# make drupal play nice with codespace proxy
\$settings['reverse_proxy'] = TRUE;
\$settings['reverse_proxy_addresses'] = array(\$_SERVER['REMOTE_ADDR']);
EOF
composer install
composer compile-theme
# Set file permissions so both httpd and user can write to files
chgrp www-data web/sites/default/files
chmod g+s web/sites/default/files
# Download files
_terminus_login
TERMINUS_ENV="dev" terminus backup:get --element=files --to=files.tar.gz
tar zx --no-same-permissions --strip-components 1 -C web/sites/default/files -f files.tar.gz
rm files.tar.gz
# no-same-permissions doesn't seem to work so we fix it here
sudo find web/sites/default/files -type d -exec chmod g+ws {} +
sudo find web/sites/default/files -type f -exec chmod g+w {} +
# The database image might be out of date so deploy any new changes from code
vendor/bin/drush deploy
# If the drush command generated a log file as the current user, make sure httpd can write to it
chmod -R g+w web/sites/default/files/private/logs
# Setup drush and other vendor binaries
echo "export PATH=\"$(pwd)/vendor/bin:\$PATH\"" | tee -a ~/.bashrc ~/.zshrc ~/.zshrc.local
# Setup VS Code
mkdir -p $WORKSPACE_FOLDER/.vscode
cp /usr/local/share/vscode/* $WORKSPACE_FOLDER/.vscode/
# Install Claude Code
curl -fsSL https://claude.ai/install.sh | bash
echo -e "export CLAUDE_CODE_USE_FOUNDRY=1\nexport ANTHROPIC_FOUNDRY_RESOURCE=uceap-claude-test-resource" | tee -a ~/.bashrc ~/.zshrc ~/.zshrc.local
claude plugin marketplace add UCEAP/claude
claude plugin install uceap
# Put neovim in the PATH for those who celebrate
ln -s /opt/nvim-linux-x86_64/bin/nvim ~/.local/bin
# Setup shell completion
uceap completion bash | sudo sh -c "cat > /etc/bash_completion.d/uceap"
gh completion --shell bash | sudo sh -c "cat > /etc/bash_completion.d/gh"
uceap completion zsh | sudo sh -c "cat > /usr/local/share/zsh/site-functions/_uceap"
gh completion --shell zsh | sudo sh -c "cat > /usr/local/share/zsh/site-functions/_gh"
# Force loading of the completion script because I can't get it to autoload
echo "autoload -Uz _uceap && compdef _uceap uceap" | tee -a ~/.zshrc ~/.zshrc.local
# Pantheon too
echo 'eval "$(/usr/local/bin/terminus completion zsh)"' | tee -a ~/.zshrc ~/.zshrc.local
# Run local devcontainer lifecycle scripts
if [ -x .devcontainer/onCreate.sh ]; then
.devcontainer/onCreate.sh
fi
}
_devcontainer_on_create_desc='runs when the devcontainer is created'
_devcontainer_on_create_help='
This command implements the `onCreateCommand` lifecycle event for dev containers.
# Usage
Add the following to your `devcontainer.json` file:
``` json
{
"onCreateCommand": "uceap devcontainer-on-create"
}
```
## Description
This command is the first of three (along with `updateContentCommand` and `postCreateCommand`) that finalizes container setup when a dev container is created. It and subsequent commands execute **inside** the container immediately after it has started for the first time.
Cloud services can use this command when caching or prebuilding a container. This means that it will not typically have access to user-scoped assets or secrets.
'