Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build test and README #63

Merged
merged 4 commits into from
Apr 14, 2024
Merged
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
38 changes: 38 additions & 0 deletions .github/workflows/run-docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Docker Compose Production Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test-docker:
runs-on: ubuntu-latest
services:
docker:
image: docker:26.0.0
options: --privileged
steps:
- uses: actions/checkout@v2
- name: Modify Dockerfile to disable USER www (which is not supported by GitHub Actions, as it runs as root)
run: |
sed -i '/USER www/s/^/#/' ./Dockerfile
- name: Set up Docker Compose
run: |
# Build the images and start the services
docker compose -f docker-compose.prod.yml up -d
# Ensure the database is ready
docker compose exec -T ogame-db bash -c 'until mariadb -h "ogame-db" -u "root" -p"toor" -e "SELECT 1"; do sleep 1; done'
- name: Set Permissions
run: docker compose exec -T ogame-app chmod -R 777 /var/www
- name: Copy .env
run: docker compose exec -T ogame-app cp .env.example .env
- name: Run Laravel setup commands
run: |
docker compose exec -T ogame-app composer install --no-dev
docker compose exec -T ogame-app php artisan key:generate
- name: Run DB Migrations
run: docker compose exec -T ogame-app php artisan migrate
- name: Run configuration cache commands
run: docker compose exec -T ogame-app php artisan cache:clear && docker compose exec -T ogame-app php artisan config:cache && docker compose exec -T ogame-app php artisan route:cache && docker compose exec -T ogame-app php artisan view:cache
6 changes: 6 additions & 0 deletions .github/workflows/run-tests-docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Docker Compose Production Build and Test
# Note: This workflow will install ALL composer dependencies including dev packages in order to run tests.
# The separate workflow "Docker Compose Production Build" will install only production dependencies and will not run tests.

on:
push:
Expand All @@ -15,8 +17,12 @@ jobs:
options: --privileged
steps:
- uses: actions/checkout@v2
- name: Modify Dockerfile to disable USER www (which is not supported by GitHub Actions, as it runs as root)
run: |
sed -i '/USER www/s/^/#/' ./Dockerfile
- name: Set up Docker Compose
run: |
# Build the images and start the services
docker compose -f docker-compose.prod.yml up -d
# Ensure the database is ready
docker compose exec -T ogame-db bash -c 'until mariadb -h "ogame-db" -u "root" -p"toor" -e "SELECT 1"; do sleep 1; done'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/run-tests-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ jobs:
options: --privileged
steps:
- uses: actions/checkout@v2
- name: Modify Dockerfile to disable USER www (which is not supported by GitHub Actions, as it runs as root)
run: |
sed -i '/USER www/s/^/#/' ./Dockerfile
- name: Set up Docker Compose
run: |
# Build the images and start the services
docker compose -f docker-compose.yml up -d
# Ensure the database is ready
docker compose exec -T ogame-db bash -c 'until mariadb -h "ogame-db" -u "root" -p"toor" -e "SELECT 1"; do sleep 1; done'
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www (not compatible with GitHub Actions)
#USER www
# Change current user to www (disabled when running through GitHub Actions)
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ After completing the setup, visit http://localhost to access OGameX. You first n
For production there is a separate docker-compose file that is used to run the application. This file is called `docker-compose.prod.yml`. This configuration contains
several performance optimizations and security settings that are not present in the development configuration.

***Caution:*** the production configuration is not yet fully optimized and should be used with caution. As an example, the database root user uses a default password which should be changed to something unique.

1. Clone the repository.
2. Copy `.env.example` to `.env`.
3. Launch the project using Docker Compose:
Expand All @@ -115,7 +117,7 @@ several performance optimizations and security settings that are not present in

5. Run Laravel setup commands to download composer dependencies, generate an encryption key, cache configuration and prepare the database:
```
$ composer install
$ composer install --no-dev
$ php artisan key:generate
$ php artisan migrate --force
$ php artisan cache:clear && php artisan config:cache && php artisan route:cache && php artisan view:cache
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ services:
context: .
dockerfile: Dockerfile
args:
OPCACHE_ENABLE: "1" # Enable opcache for production
OPCACHE_ENABLE: "1" # Enable opcache in production
USE_USER: ${USE_USER_ARG:-yes} # Defaults to "yes". Set to "no" for GitHub Actions.
image: digitalocean.com/php
container_name: ogame-app
restart: unless-stopped
Expand All @@ -37,7 +38,7 @@ services:
networks:
- app-network

#MySQL Service
#MariaDB Service
ogame-db:
image: mariadb:11.3.2-jammy
container_name: ogame-db
Expand All @@ -46,8 +47,7 @@ services:
volumes:
- ogame-dbdata:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
ports:
- "3306:3306"
# MariaDB port is not exposed to the host machine in production.
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: toor
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
dockerfile: Dockerfile
args:
OPCACHE_ENABLE: "0" # Disable opcache for development
USE_USER: ${USE_USER_ARG:-yes} # Defaults to "yes". Set to "no" for GitHub Actions.
image: digitalocean.com/php
container_name: ogame-app
restart: unless-stopped
Expand All @@ -37,7 +38,7 @@ services:
networks:
- app-network

#MySQL Service
#MariaDB Service
ogame-db:
image: mariadb:11.3.2-jammy
container_name: ogame-db
Expand Down
Loading