Skip to content

Commit 305043c

Browse files
committed
Merge branch 'dev' into accessibility-exchangeGH-2562
2 parents 73cacd7 + bd39ce8 commit 305043c

File tree

9 files changed

+514
-320
lines changed

9 files changed

+514
-320
lines changed

.kube/app/Dockerfile

+18-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ENV APP_DIR /app
99
ENV KUBE_DIR .kube/app
1010

1111
ARG CIPHERSWEET_KEY
12+
ARG USER_ID
13+
# If argument passed then swap out numerical id for www-data user to allow for mirroring volumes from local to host set via .env file variable WWWUSER and is auto-generate when starting nix-shell for the first time
14+
RUN [ -z "$USER_ID" ] || usermod -u $USER_ID www-data
1215

1316
RUN apt-get update
1417

@@ -49,7 +52,8 @@ RUN apt-get install -y \
4952

5053
RUN mkdir -p /tmp/imagick
5154
WORKDIR /tmp/imagick
52-
RUN curl -L -o /tmp/imagick.tar.gz https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz # upgrade version when bumping PHP version
55+
# upgrade version when bumping PHP version
56+
RUN curl -L -o /tmp/imagick.tar.gz https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz
5357
RUN tar --strip-components=1 -xf /tmp/imagick.tar.gz
5458
RUN phpize
5559
RUN ./configure
@@ -82,17 +86,23 @@ RUN . "$NVM_DIR/nvm.sh" && nvm install $NODE_VERSION
8286
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
8387

8488
COPY $KUBE_DIR/php.ini /etc/php/$PHP_VERSION/cli/conf.d/99-sail.ini
89+
# explicitly setup production PHP settings
90+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
8591
COPY $KUBE_DIR/nginx.conf /etc/nginx/nginx.conf
8692
COPY $KUBE_DIR/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
8793

88-
RUN mkdir $APP_DIR
8994
WORKDIR $APP_DIR
90-
COPY . $APP_DIR
91-
95+
# Change ownership as the files are copied rather than having to change after
96+
COPY --chown=www-data:www-data . $APP_DIR
97+
# Prevents error on npm ci when directory doesn not yet exist
98+
RUN mkdir -p $APP_DIR/node_modules
99+
# Set proper ownership to prevent errors when installed with php-fpm user
100+
RUN chown www-data:www-data $NVM_DIR/nvm.sh $APP_DIR/node_modules /var/www
101+
102+
# run installers as the user that PHP runs under to keep ownership aligned
103+
USER www-data
92104
RUN composer install
93-
94105
RUN . "$NVM_DIR/nvm.sh" && nvm use $NODE_VERSION && npm ci
106+
USER root
95107

96-
RUN chown -R www-data:root $APP_DIR/public/ $NVM_DIR
97-
98-
ENTRYPOINT $APP_DIR/$KUBE_DIR/entrypoint.sh
108+
ENTRYPOINT $APP_DIR/$KUBE_DIR/entrypoint.sh

.kube/app/entrypoint.sh

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
set -e
44

5-
# TODO permanent remove cache lines once testing on per/pod caching is tested
6-
75
mkdir -p $FILES_PATH
8-
# mkdir -p $CACHE_PATH removed per https://github.com/accessibility-exchange/platform/issues/1596
96

10-
## fix permissions before syncing to existing storage and cache https://github.com/accessibility-exchange/platform/issues/1226
11-
chown -R www-data:root /app/storage /app/bootstrap/cache $FILES_PATH $VIEW_COMPILED_PATH # $CACHE_PATH removed per https://github.com/accessibility-exchange/platform/issues/1596
7+
# Removing in favor of changing ownership in the syncing stream
8+
# chown -R www-data:www-data /app/storage /app/bootstrap/cache $FILES_PATH $VIEW_COMPILED_PATH
129

1310
## sync files from container storage to permanent storage then remove container storage
14-
rsync -a /app/storage/ $FILES_PATH
11+
rsync -a --chown=www-data:www-data /app/storage/ $FILES_PATH
1512
rm -rf /app/storage
1613

17-
## sync files from container cache to permanent storage then remove container cache
18-
## removed syncing to shared/permenant storage https://github.com/accessibility-exchange/platform/issues/1596
19-
# rsync -a /app/bootstrap/cache/ $CACHE_PATH
20-
# rm -rf /app/bootstrap/cache
21-
2214
## create symlinks from permanent storage & cache to application directory folders
2315
ln -s $FILES_PATH /app/storage
24-
## removed linked to shared/permenant storage https://github.com/accessibility-exchange/platform/issues/1596
25-
# ln -s $CACHE_PATH /app/bootstrap/cache
2616

2717
php artisan deploy:local
2818

2919
flock -n -E 0 /opt/data -c "php artisan deploy:global" # run exclusively on a single instance at once
3020

31-
## fix permissions after syncing to existing storage and cache https://github.com/accessibility-exchange/platform/issues/1236
32-
chown -R www-data:root /app/bootstrap/cache $FILES_PATH # $CACHE_PATH removed per and added path to cache in the pod https://github.com/accessibility-exchange/platform/issues/1596
33-
3421
# Generate the robots.txt and sitemap.xml files
3522
php artisan seo:generate
3623

24+
# Add in symlink to ownership update, add in public folder where assets are compiled
25+
chown -R www-data:www-data /app/storage /app/bootstrap/cache /app/public/build /app/public/*.{xml,txt} $FILES_PATH
26+
3727
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

.local-deploy/accessibility-app/Dockerfile

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
INCLUDE+ ./.kube/app/Dockerfile
44

5-
ARG USER_ID
5+
# for development add in command for showing running processes
6+
RUN apt install -y procps
67

7-
RUN usermod -u $USER_ID www-data
8-
RUN chown -R www-data:root /app $NVM_DIR
9-
RUN chown www-data:root /var/www
10-
11-
COPY .local-deploy/accessibility-app/php.ini-development /usr/local/etc/php/conf.d/php.ini
8+
COPY .local-deploy/accessibility-app/php.ini-development "$PHP_INI_DIR/conf.d/99-sail.ini"
9+
# explicitly setup development php settings
10+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
1211
COPY .local-deploy/accessibility-app/etc /etc

.local-deploy/accessibility-app/etc/nginx/nginx.conf

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ http {
3131
listen 8080;
3232
server_name _;
3333

34-
location /nginx_status {
34+
# change to match production path
35+
location /status/nginx {
3536
stub_status on;
36-
# don't need ip restrictions for local testing
37-
# allow 127.0.0.1;
38-
# allow 10.0.0.0/8;
39-
# allow 172.0.0.0/8;
40-
# deny all;
4137
}
4238

4339
include /etc/nginx/includes/laravel.conf;

README.md

+151-52
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ Herd supports debuging via XDebug. The article "[Activating XDebug on Visual Stu
182182
### Local development using Docker and Nix
183183
184184
#### Setup Instructions
185+
185186
1. Install [Nix](https://nixos.org/download/) for your system.
186187
2. Run `nix-shell`.
187188
3. If you are wanting to run Docker, follow the steps for your platform:
@@ -193,60 +194,157 @@ Herd supports debuging via XDebug. The article "[Activating XDebug on Visual Stu
193194
```
194195
- **Other Systems**: You will need to have Docker installed and running.
195196
196-
#### Docker Compose Aliases
197-
These aliases simplify working with `docker-compose` using the `docker-compose.yml` file:
198-
199-
- `dc` → Shortcut for `docker-compose -f docker-compose.yml`
200-
- `dcbp` → Build the `platform.test` service: `docker-compose -f docker-compose.yml build platform.test`
201-
- `dcup` → Start services in detached mode: `docker-compose -f docker-compose.yml up -d`
202-
- `dcd` → Stop and remove containers: `docker-compose -f docker-compose.yml down`
203-
- `dil` → List Docker images: `docker image ls`
204-
- `dirm` → Remove Docker images: `docker image rm`
205-
- `dvl` → List Docker volumes: `docker volume ls`
206-
- `dvrm` → Remove Docker volumes: `docker volume rm`
207-
208-
#### Kubernetes Aliases
209-
These aliases simplify working with `kubectl` in different namespaces:
210-
211-
- `kcd` → Shortcut for `kubectl -n iris-accessibility-development`
212-
- `kcs` → Shortcut for `kubectl -n iris-accessibility-staging`
213-
- `kcp` → Shortcut for `kubectl -n iris-accessibility-production`
214-
215-
#### Pod Flushing Functions
216-
217-
##### `kflush` Function
218-
The `kflush` function executes Laravel deployment commands (`php artisan deploy:local` and `php artisan deploy:global`) inside running `app-` pods for a given namespace.
219-
220-
###### Usage:
221-
```sh
222-
kflush <namespace>
223-
```
224-
Example:
225-
```sh
226-
kflush development
227-
```
228-
This will:
229-
1. Find all running pods with the `app-` prefix in the `iris-accessibility-<namespace>` namespace.
230-
2. Execute `php artisan deploy:local` in each pod.
231-
3. Execute `php artisan deploy:global` in the first matching pod.
232-
233-
##### `kflushall` Function
234-
Flushes all `app-` pods in all environments (`development`, `staging`, `production`).
235-
236-
###### Usage:
237-
```sh
238-
kflushall
239-
```
240-
This iterates through all environments and runs `kflush` for each.
241-
242-
##### Namespace-Specific Flush Aliases
243-
For convenience, predefined aliases allow flushing without specifying the namespace:
244-
245-
- `kdflush` → Runs `kflush development`
246-
- `ksflush` → Runs `kflush staging`
247-
- `kpflush` → Runs `kflush production`
197+
#### Entering Development Environment
198+
199+
Each time you want to have your terminal environment setup you will want to run `nix-shell` to make sure you have your aliases and packages setup.
200+
201+
#### Aliases
202+
203+
> :heavy_check_mark: All commands assume they're run from the project root directory where `docker-compose.yml` exists and the user has entered the nix shell by first running `nix-shell`.
204+
205+
##### :toolbox: 1. Docker Compose (`dc`, `dexit`, etc.)
206+
207+
| Command | Description |
208+
|--------|-------------|
209+
| `dc <command>` | Runs any `docker-compose` command (e.g., `dc ps`, `dc exec...`) |
210+
| `dcbp` | Builds the `platform.test` service |
211+
| `dcupd` | Starts containers in detached mode |
212+
| `dcdn` | Stops and removes containers |
213+
| `dexit [options] <service> <cmd>` | Executes an interactive command in a running container |
214+
| `dexp` | Opens a Bash shell in `platform.test` as user `www-data` |
215+
216+
---
217+
218+
##### :camera: 2. Docker Images (`img`, `imgrm`, etc.)
219+
220+
| Command | Description |
221+
|--------|-------------|
222+
| `img <command>` | Runs any `docker image` command |
223+
| `imgls` | Lists all Docker images |
224+
| `imglsp` | Lists only platform-related images (`platform*`) with their name:tag |
225+
| `imgrmp` | Prompts for confirmation before removing platform-related images |
226+
| `imgrm` | Removes specified Docker images manually |
227+
| `imgprune` | Removes all unused images (no confirmation) |
228+
229+
---
230+
231+
##### :page_facing_up: 3. Docker Logs (`log`, `logf`, `logt`, etc.)
232+
233+
| Command | Description |
234+
|--------|-------------|
235+
| `log <container>` | Shows logs for a specific container |
236+
| `logf <container>` | Follows (tails) logs for a specific container |
237+
| `logt` | Tails logs for `platform.test` with last 100 lines |
238+
| `logp` | Tails logs for `platform.proxy` with last 100 lines |
239+
| `logsql` | Tails logs for `platform.mysql` with last 100 lines |
240+
| `tailt`, `tailp`, `tailsql` | Show static last 100 lines (not tailing) for respective containers |
241+
242+
---
243+
244+
##### :floppy_disk: 4. Docker Volumes (`vol`, `volrmp`, etc.)
245+
246+
| Command | Description |
247+
|--------|-------------|
248+
| `vol <command>` | Runs any `docker volume` command |
249+
| `vols` | Lists all volumes |
250+
| `volsp` | Lists only platform-specific volumes (e.g., `platform.mysql`, `platform.redis`) |
251+
| `volrmp` | Prompts for confirmation before removing matched platform volumes |
252+
| `volrm` | Removes specified volume manually |
253+
| `volprune` | Removes all unused volumes (no confirmation) |
254+
255+
---
256+
257+
##### :star: 5. Laravel Artisan (`artisan`, `tinker`, etc.)
258+
259+
| Command | Description |
260+
|--------|-------------|
261+
| `artisan <command>` | Runs any Laravel Artisan command inside `platform.test` container |
262+
| `tinker` | Shortcut for `artisan tinker` |
263+
| `test` | Shortcut for `artisan test` |
264+
265+
Example:
266+
```bash
267+
artisan make:model User -mf
268+
```
269+
is equivalent to:
270+
```bash
271+
docker-compose exec -it --user www-data platform.test php artisan make:model User -mf
272+
```
273+
274+
---
275+
276+
##### :atom_symbol: 6. Kubernetes (`kflush`, `kflushall`, etc.)
277+
278+
These are custom deployment helpers that trigger Laravel `deploy:local` and `deploy:global` commands across Laravel pods in Kubernetes clusters.
279+
280+
| Command | Description |
281+
|--------|-------------|
282+
| `kflush development` | Flushes all pods in `iris-accessibility-development` namespace |
283+
| `kflush staging` | Flushes all pods in `iris-accessibility-staging` namespace |
284+
| `kflush production` | Flushes all pods in `iris-accessibility-production` namespace |
285+
| `kflushall` | Flushes pods in all three environments (dev → stag → prod) |
286+
| `kflushd`, `kflushs`, `kflushp` | Shortcuts for flushing dev/stag/prod respectively |
287+
288+
###### Internals of `kflush <env>`
289+
- Finds all `app-*` pods in the correct namespace
290+
- Runs `php artisan deploy:local` on each pod
291+
- Runs `php artisan deploy:global` only once (on the first pod)
292+
293+
---
294+
295+
##### :test_tube: Example Usage Overview
296+
297+
###### Docker Compose
298+
```bash
299+
dc ps # Show running services
300+
dcupd # Start environment
301+
dexp # Open shell in app
302+
```
303+
304+
###### Docker Images
305+
```bash
306+
imglsp # List platform images
307+
imgrmp # Remove platform images after confirming
308+
```
309+
310+
###### Docker Logs
311+
```bash
312+
logt # View recent logs for app
313+
logf platform.test # Tail logs for app
314+
```
315+
316+
###### Docker Volumes
317+
```bash
318+
volsp # List platform volumes
319+
volrmp # Remove them safely
320+
```
321+
322+
###### Laravel
323+
```bash
324+
artisan migrate # Run migrations
325+
artisan make:controller # Generate controller
326+
tinker # Start Laravel Tinker
327+
```
328+
329+
###### Kubernetes
330+
```bash
331+
kflushd # Run kflush in dev environment
332+
kflushall # Run kflush dev, staging, and prod environments
333+
```
334+
335+
---
336+
337+
##### :memo: Legend
338+
339+
| Symbol | Meaning |
340+
|-------|----------|
341+
| `$@` | Passes all arguments received by a function |
342+
| `-r` | Prevents execution if no input is given to `xargs` |
343+
| `-p` | Prompts for confirmation before executing |
344+
| `| grep ...` | Filters output based on pattern matching |
248345

249346
#### Environment Setup
347+
250348
If the `.env` file does not exist, the script automatically generates it using `.env.local.template` and random secrets:
251349
- `CIPHERSWEET_KEY` (32-byte hex string)
252350
- `DB_PASSWORD` (16-byte hex string)
@@ -258,6 +356,7 @@ If the `.env` file does not exist, the script automatically generates it using `
258356
Ensure `.env.local.template` is available before running the script.
259357

260358
#### Rootless Docker Support
359+
261360
For users running `dockerd-rootless`, the script provides:
262361
- Aliases:
263362
```sh

0 commit comments

Comments
 (0)