Skip to content

Commit add739b

Browse files
Fix Docker setup for Render deployment
This commit introduces a complete Docker setup for deploying the OTE application on Render.com. It addresses the issue of a missing Dockerfile in the root directory, which caused deployment failures. The main changes include: - A new multi-stage `Dockerfile` in the root directory that builds a production-ready image with PHP-FPM and Nginx. - A `render.yaml` file to define the deployment blueprint for Render, including a web service and a PostgreSQL database. - Nginx configuration and a start script for the production environment. - An updated `.dockerignore` file to optimize the Docker build context. - Updated documentation in `docs/RENDER.md` to reflect the new deployment process.
1 parent 82eafbf commit add739b

6 files changed

Lines changed: 176 additions & 12 deletions

File tree

.dockerignore

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
# .dockerignore
12
.git
2-
.env
3+
.gitattributes
4+
.github
35
.idea
46
.vscode
5-
node_modules
6-
vendor
7-
storage/logs
8-
storage/framework/sessions
9-
storage/framework/cache
10-
storage/framework/views
11-
docker
7+
.devcontainer
8+
.editorconfig
9+
.env
10+
.env.example
11+
.styleci.yml
12+
.phpunit.result.cache
13+
/node_modules
14+
/vendor
15+
/storage/app
16+
/storage/framework
17+
/storage/logs
18+
/public/storage
19+
/tests
20+
/docs
21+
README.md
22+
CHANGELOG.md
23+
CONTRIBUTING.md
24+
LICENSE
25+
phpunit.xml
26+
docker-compose.yml
27+
compose.dev.yml
28+
Dockerfile.dev
29+
docker/development
30+
docker/common
31+
render.yaml
32+
!docker/production
33+
!docker/production/nginx/nginx.conf
34+
!docker/production/start.sh

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Dockerfile
2+
# Builder stage
3+
FROM public.ecr.aws/composer/composer:2 AS builder
4+
WORKDIR /app
5+
COPY . .
6+
RUN composer install --no-dev --no-interaction --optimize-autoloader
7+
8+
# Production stage
9+
FROM public.ecr.aws/php/php:8.2-fpm-alpine
10+
WORKDIR /var/www
11+
12+
# Install dependencies
13+
RUN apk add --no-cache nginx libpq
14+
15+
# Copy nginx configuration
16+
COPY docker/production/nginx/nginx.conf /etc/nginx/nginx.conf
17+
18+
# Copy application files from builder stage
19+
COPY --from=builder /app .
20+
21+
# Copy start script
22+
COPY docker/production/start.sh /usr/local/bin/start.sh
23+
RUN chmod +x /usr/local/bin/start.sh
24+
25+
# Set permissions
26+
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache
27+
28+
# Expose port 80
29+
EXPOSE 80
30+
31+
# Start supervisord
32+
CMD ["/usr/local/bin/start.sh"]

docker/production/nginx/nginx.conf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
user www-data;
2+
worker_processes auto;
3+
pid /run/nginx.pid;
4+
include /etc/nginx/modules-enabled/*.conf;
5+
6+
events {
7+
worker_connections 768;
8+
}
9+
10+
http {
11+
sendfile on;
12+
tcp_nopush on;
13+
tcp_nodelay on;
14+
keepalive_timeout 65;
15+
types_hash_max_size 2048;
16+
17+
include /etc/nginx/mime.types;
18+
default_type application/octet-stream;
19+
20+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
21+
ssl_prefer_server_ciphers on;
22+
23+
access_log /var/log/nginx/access.log;
24+
error_log /var/log/nginx/error.log;
25+
26+
gzip on;
27+
28+
server {
29+
listen 80;
30+
server_name _;
31+
32+
root /var/www/public;
33+
index index.php index.html index.htm;
34+
35+
location / {
36+
try_files $uri $uri/ /index.php?$query_string;
37+
}
38+
39+
location ~ \.php$ {
40+
try_files $uri =404;
41+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
42+
fastcgi_pass 127.0.0.1:9000;
43+
fastcgi_index index.php;
44+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
45+
include fastcgi_params;
46+
}
47+
48+
location ~ /\.ht {
49+
deny all;
50+
}
51+
}
52+
}

docker/production/start.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Start PHP-FPM
4+
php-fpm &
5+
6+
# Start Nginx
7+
nginx -g "daemon off;"

docs/RENDER.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ This project is configured for automatic deployment to the [Render](https://rend
44

55
## How It Works
66

7-
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:
7+
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:
88

9-
- A **web service** running the Laravel application.
9+
- A **web service** running the Laravel application. This service is built using the `Dockerfile` in the root of the repository.
1010
- A **PostgreSQL database** for storing data.
1111

1212
When you push changes to the `main` branch on GitHub, Render will automatically:
1313

1414
1. Detect the changes.
15-
2. Build the application using the `buildCommand` defined in `render.yaml`. This includes installing dependencies and running database migrations.
16-
3. Deploy the new version of the application.
15+
2. Build the Docker image for the application.
16+
3. Run the `buildCommand` defined in `render.yaml` to execute database migrations (`php artisan migrate --force`).
17+
4. Deploy the new version of the application.
1718

1819
## Initial Setup on Render
1920

render.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
services:
2+
- type: web
3+
name: ote
4+
env: docker
5+
repo: https://github.com/attogram/ote
6+
region: oregon
7+
plan: free
8+
healthCheckPath: /
9+
buildCommand: 'php artisan migrate --force'
10+
envVars:
11+
- key: DB_CONNECTION
12+
value: pgsql
13+
- key: DB_HOST
14+
fromService:
15+
type: psql
16+
name: ote-db
17+
property: host
18+
- key: DB_PORT
19+
fromService:
20+
type: psql
21+
name: ote-db
22+
property: port
23+
- key: DB_DATABASE
24+
fromService:
25+
type: psql
26+
name: ote-db
27+
property: database
28+
- key: DB_USERNAME
29+
fromService:
30+
type: psql
31+
name: ote-db
32+
property: user
33+
- key: DB_PASSWORD
34+
fromService:
35+
type: psql
36+
name: ote-db
37+
property: password
38+
- key: APP_KEY
39+
generateValue: true
40+
- key: APP_URL
41+
fromService:
42+
type: web
43+
name: ote
44+
property: url
45+
- type: psql
46+
name: ote-db
47+
region: oregon
48+
plan: free
49+
version: "14"

0 commit comments

Comments
 (0)