diff --git a/.dockerignore b/.dockerignore index 3067f90..4577259 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,11 +1,34 @@ +# .dockerignore .git -.env +.gitattributes +.github .idea .vscode -node_modules -vendor -storage/logs -storage/framework/sessions -storage/framework/cache -storage/framework/views -docker +.devcontainer +.editorconfig +.env +.env.example +.styleci.yml +.phpunit.result.cache +/node_modules +/vendor +/storage/app +/storage/framework +/storage/logs +/public/storage +/tests +/docs +README.md +CHANGELOG.md +CONTRIBUTING.md +LICENSE +phpunit.xml +docker-compose.yml +compose.dev.yml +Dockerfile.dev +docker/development +docker/common +render.yaml +!docker/production +!docker/production/nginx/nginx.conf +!docker/production/start.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f97afe5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Dockerfile +# Builder stage +FROM public.ecr.aws/composer/composer:2 AS builder +WORKDIR /app +COPY . . +RUN composer install --no-dev --no-interaction --optimize-autoloader + +# Production stage +FROM public.ecr.aws/php/php:8.2-fpm-alpine +WORKDIR /var/www + +# Install dependencies +RUN apk add --no-cache nginx libpq + +# Copy nginx configuration +COPY docker/production/nginx/nginx.conf /etc/nginx/nginx.conf + +# Copy application files from builder stage +COPY --from=builder /app . + +# Copy start script +COPY docker/production/start.sh /usr/local/bin/start.sh +RUN chmod +x /usr/local/bin/start.sh + +# Set permissions +RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache + +# Expose port 80 +EXPOSE 80 + +# Start supervisord +CMD ["/usr/local/bin/start.sh"] diff --git a/docker/production/nginx/nginx.conf b/docker/production/nginx/nginx.conf new file mode 100644 index 0000000..b6caa36 --- /dev/null +++ b/docker/production/nginx/nginx.conf @@ -0,0 +1,52 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + gzip on; + + server { + listen 80; + server_name _; + + root /var/www/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } + } +} diff --git a/docker/production/start.sh b/docker/production/start.sh new file mode 100755 index 0000000..e124eb4 --- /dev/null +++ b/docker/production/start.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Start PHP-FPM +php-fpm & + +# Start Nginx +nginx -g "daemon off;" diff --git a/docs/RENDER.md b/docs/RENDER.md index 8e823bc..181149e 100644 --- a/docs/RENDER.md +++ b/docs/RENDER.md @@ -4,16 +4,17 @@ This project is configured for automatic deployment to the [Render](https://rend ## How It Works -This repository contains a `render.yaml` file that uses Render's "Blueprint" feature. This file tells Render everything it needs to know to deploy the application, including: +This repository contains a `render.yaml` file in the root directory that uses Render's "Blueprint" feature. This file tells Render everything it needs to know to deploy the application, including: -- A **web service** running the Laravel application. +- A **web service** running the Laravel application. This service is built using the `Dockerfile` in the root of the repository. - A **PostgreSQL database** for storing data. When you push changes to the `main` branch on GitHub, Render will automatically: 1. Detect the changes. -2. Build the application using the `buildCommand` defined in `render.yaml`. This includes installing dependencies and running database migrations. -3. Deploy the new version of the application. +2. Build the Docker image for the application. +3. Run the `buildCommand` defined in `render.yaml` to execute database migrations (`php artisan migrate --force`). +4. Deploy the new version of the application. ## Initial Setup on Render diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..677fd75 --- /dev/null +++ b/render.yaml @@ -0,0 +1,49 @@ +services: + - type: web + name: ote + env: docker + repo: https://github.com/attogram/ote + region: oregon + plan: free + healthCheckPath: / + buildCommand: 'php artisan migrate --force' + envVars: + - key: DB_CONNECTION + value: pgsql + - key: DB_HOST + fromService: + type: psql + name: ote-db + property: host + - key: DB_PORT + fromService: + type: psql + name: ote-db + property: port + - key: DB_DATABASE + fromService: + type: psql + name: ote-db + property: database + - key: DB_USERNAME + fromService: + type: psql + name: ote-db + property: user + - key: DB_PASSWORD + fromService: + type: psql + name: ote-db + property: password + - key: APP_KEY + generateValue: true + - key: APP_URL + fromService: + type: web + name: ote + property: url + - type: psql + name: ote-db + region: oregon + plan: free + version: "14"