Skip to content

Commit

Permalink
Dockerize project
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpakzad committed Feb 5, 2023
1 parent a203617 commit bc992f2
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.env.backup
.env.production
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
auth.json
Expand All @@ -16,3 +17,4 @@ yarn-error.log
/.fleet
/.idea
/.vscode
.DS_Store
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM php:8.2-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libzip-dev

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

COPY . .

USER $user
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.8"
services:

app:
build:
args:
user: RS
uid: 1000
context: ./
dockerfile: Dockerfile
image: repository-switcher
container_name: repository-switcher-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- repository-switcher

db:
image: mysql:latest
container_name: repository-switcher-db
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: repository-switcher-mysql
volumes:
- ./docker/mysql:/docker-entrypoint-initdb.d
networks:
- repository-switcher

webserver:
image: nginx:alpine
container_name: repository-switcher-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker/nginx:/etc/nginx/conf.d/
networks:
- repository-switcher

networks:
repository-switcher:
driver: bridge
20 changes: 20 additions & 0 deletions docker/nginx/rs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}

0 comments on commit bc992f2

Please sign in to comment.