Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 62 additions & 4 deletions docker-for-development/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: twhl-dev
services:
composer:
container_name: twhl-dev-composer
command: composer install
environment:
- COMPOSER_IGNORE_PLATFORM_REQS=1
image: composer:latest
volumes:
- ../:/var/twhl
working_dir: /var/twhl
db:
command:
--collation-server=utf8mb4_unicode_ci
Expand All @@ -8,27 +17,73 @@ services:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=twhl
- MYSQL_ROOT_PASSWORD=cs_canbunk2
healthcheck:
test: "/usr/bin/mysql --user=root --password=cs_canbunk2 --execute \"SELECT 1;\""
interval: 5s
timeout: 5s
retries: 10
image: mysql:8.0
# ports:
# - "3306:3306"
volumes:
- ./mysql-data:/var/lib/mysql
migration-runner:
build:
context: ./migration-runner
container_name: twhl-dev-migration-runner
depends_on:
composer:
condition: service_completed_successfully
db:
condition: service_healthy
env_file:
- path: ../.env.example
- path: ../.env
required: false
environment:
- APP_KEY=base64:PB2xpacpFD+vjAcrcj/tBEQ7RzAtvUyufGd4KznJ81k=
- DB_DATABASE=twhl
- DB_HOST=twhl-mysql-db
- DB_PASSWORD=cs_canbunk2
- DB_USERNAME=root
image: twhl-dev/migration-runner
links:
- "db:twhl-mysql-db"
volumes:
- ../:/var/twhl
node:
container_name: twhl-dev-node
build:
context: ./node
image: twhl-dev/node
command: npm install
image: node:24
secrets:
- source: npmrc
target: /root/.npmrc
volumes:
- ../:/var/twhl
working_dir: /var/twhl
php-apache:
build:
context: ./php-apache
container_name: twhl-dev-php-apache
depends_on:
composer:
condition: service_completed_successfully
db:
condition: service_healthy
migration-runner:
condition: service_completed_successfully
node:
condition: service_completed_successfully
env_file:
- path: ../.env.example
- path: ../.env
required: false
environment:
- APP_KEY=base64:PB2xpacpFD+vjAcrcj/tBEQ7RzAtvUyufGd4KznJ81k=
- DB_DATABASE=twhl
- DB_HOST=twhl-mysql-db
- DB_PASSWORD=cs_canbunk2
- DB_USER=root
- DB_USERNAME=root
image: twhl-dev/php-apache
links:
- "db:twhl-mysql-db"
Expand All @@ -37,3 +92,6 @@ services:
volumes:
- ../:/var/www/html/twhl
- ./php-apache/twhl-dev-php-conf.d:/usr/local/etc/php/conf.d
secrets:
npmrc:
file: ~/.npmrc
15 changes: 15 additions & 0 deletions docker-for-development/migration-runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM php:8.4

# Use the PHP development config
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# Install PHP extensions
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions pdo_mysql

WORKDIR /var/twhl/

# Migration script
COPY ./run-migrations.sh ../run-migrations.sh
RUN chmod +x ../run-migrations.sh
ENTRYPOINT ["../run-migrations.sh"]
11 changes: 11 additions & 0 deletions docker-for-development/migration-runner/run-migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

if php artisan migrate:status | grep -q "Migration table not found"
then
echo "Did not find a migration table in the database."
echo "Running 'php artisan migrate --seed'."
echo "If it fails, you may have to rerun it manually."
php artisan migrate --seed
fi
php artisan migrate
3 changes: 0 additions & 3 deletions docker-for-development/node/Dockerfile

This file was deleted.

23 changes: 2 additions & 21 deletions docker-for-development/php-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# Install PHP extensions
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd pdo_mysql @composer
RUN install-php-extensions gd pdo_mysql

# Set the document root
ENV APACHE_DOCUMENT_ROOT /var/www/html/twhl/public
ENV APACHE_DOCUMENT_ROOT=/var/www/html/twhl/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

Expand All @@ -21,24 +21,5 @@ EXPOSE 80/tcp
# If we wanted to store the PHP files etc. in a volume:
# VOLUME /var/www/html/twhl

# Environment variables
ENV DB_DATABASE=twhl
ENV DB_HOST=twhl-mysql-db
ENV DB_PASSWORD=cs_canbunk2
ENV DB_USER=root

# Script for waiting for the MySQL server to start
COPY ./wait-for-mysql-to-start.php /usr/local/bin/wait-for-mysql-to-start
RUN chmod +x /usr/local/bin/wait-for-mysql-to-start

# Script for creating a .env file and running Composer
COPY ./twhl-install.sh /usr/local/bin/twhl-install
RUN chmod +x /usr/local/bin/twhl-install

# This is where the good stuff goes, so make that the working directory
WORKDIR /var/www/html/twhl/

# Startup script
COPY ./entrypoint.sh ../entrypoint.sh
RUN chmod +x ../entrypoint.sh
ENTRYPOINT "../entrypoint.sh"
23 changes: 0 additions & 23 deletions docker-for-development/php-apache/entrypoint.sh

This file was deleted.

20 changes: 0 additions & 20 deletions docker-for-development/php-apache/twhl-install.sh

This file was deleted.

28 changes: 0 additions & 28 deletions docker-for-development/php-apache/wait-for-mysql-to-start.php

This file was deleted.

44 changes: 19 additions & 25 deletions docker-for-development/readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
Delete your `.env` file if you have one and run this in Bash or PowerShell to build the Docker images and start the containers:
```
docker compose up
```
The web server can then be reached at http://localhost:82 .
# Dockerized local development

To install the Composer dependencies and create the `.env` file (if it does not exist), run:
```
docker compose exec php-apache twhl-install
```
## Starting a local development instance of TWHL
1. Create a [GitHub Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) with the `read:packages` scope and add it to the file `~/.npmrc` like this:
```
//npm.pkg.github.com/:_authToken=ghp_1234example567
```
This step is necessary for the successful installation of the `@logicandtrick/twhl-wikicode-parser` NPM package.
2. Run `docker compose up` to build the Docker images and start the containers. Your local development instance of TWHL can now be reached at http://localhost:82 .
3. When making changes to `*.css`, `*.scss` and `*.js` files, you need to run `docker compose run --rm node npm run development` to bundle those changes into the compiled CSS and JS files. The easiest way to do this is to run `docker compose run --rm node npm run watch`, which will watch the files for changes and auto-build when needed.

To run `npm install` inside the Node container:
```
docker compose run node npm install
```
## Updating NPM dependencies
1. Make your changes to package.json
2. Run `docker compose run --rm node npm install`

To start a Bash instance inside the PHP & Apache container for executing commands, run this:
```
docker compose exec php-apache bash
```
## Updating Composer PHP dependencies
1. Make your changes to composer.json
2. Run `docker compose run --rm composer composer install`

To see the Apache log, run this:
```
docker compose logs php-apache
```
## Running Bash inside the PHP & Apache container for executing commands
Run `docker compose exec php-apache bash`

To rebuild the images:
```
docker compose build
```
## Inspecting the Apache logs
Run `docker compose logs php-apache`
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

TWHL is a mapping and modding resource website for Half-Life 1 and related games.

- [Visit twhl.info](http://twhl.info)
- [Visit twhl.info](https://twhl.info)

### Getting a dev environment set up

TWHL4 uses the [Laravel](http://laravel.com/) framework. Detailed instructions can be found
TWHL4 uses the [Laravel](https://laravel.com/) framework. Detailed instructions can be found
in the Laravel docs, but here's the basic steps:

1. If you know how to use Docker, see the [docker-for-development](docker-for-development/readme.md) folder and skip many of the following steps.
Expand Down