first commit
This commit is contained in:
18
.editorconfig
Normal file
18
.editorconfig
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Editor
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Container file
|
||||||
|
/docker/postgres/data/*
|
||||||
|
!/docker/postgres/data/.gitkeep
|
||||||
|
|
||||||
|
# Working directory
|
||||||
|
src/*
|
||||||
70
Dockerfile
Normal file
70
Dockerfile
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# PHP-FPM is a FastCGI implementation for PHP.
|
||||||
|
# Read more here: https://hub.docker.com/_/php
|
||||||
|
FROM php:8.2-fpm
|
||||||
|
|
||||||
|
|
||||||
|
RUN apt-get update
|
||||||
|
|
||||||
|
# Install useful tools
|
||||||
|
RUN apt-get -y install apt-utils nano wget dialog vim
|
||||||
|
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apt-get -y install --fix-missing \
|
||||||
|
apt-utils \
|
||||||
|
build-essential \
|
||||||
|
git \
|
||||||
|
curl \
|
||||||
|
libcurl4 \
|
||||||
|
libcurl4-openssl-dev \
|
||||||
|
zlib1g-dev \
|
||||||
|
libzip-dev \
|
||||||
|
zip \
|
||||||
|
libbz2-dev \
|
||||||
|
locales \
|
||||||
|
libmcrypt-dev \
|
||||||
|
libicu-dev \
|
||||||
|
libonig-dev \
|
||||||
|
libxml2-dev
|
||||||
|
|
||||||
|
RUN docker-php-ext-install \
|
||||||
|
exif \
|
||||||
|
pcntl \
|
||||||
|
bcmath \
|
||||||
|
ctype \
|
||||||
|
curl \
|
||||||
|
pcntl \
|
||||||
|
zip
|
||||||
|
|
||||||
|
# Install Postgre PDO
|
||||||
|
RUN apt-get install -y libpq-dev \
|
||||||
|
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
|
||||||
|
&& docker-php-ext-install pdo pdo_pgsql pgsql
|
||||||
|
|
||||||
|
# Install NPM
|
||||||
|
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
|
||||||
|
RUN apt-get install -y nodejs
|
||||||
|
|
||||||
|
# Clear cache
|
||||||
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install Composer
|
||||||
|
COPY --from=composer:2.3 /usr/bin/composer /usr/bin/composer
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
# Add user for laravel application
|
||||||
|
RUN groupadd -g 1000 www
|
||||||
|
RUN useradd -u 1000 -ms /bin/bash -g www www
|
||||||
|
|
||||||
|
# Copy existing application directory contents
|
||||||
|
COPY ./src /var/www/html
|
||||||
|
|
||||||
|
# Copy existing application directory permissions
|
||||||
|
COPY --chown=www:www ./src /var/www/html
|
||||||
|
|
||||||
|
# Change current user to www
|
||||||
|
USER www
|
||||||
|
|
||||||
|
# Set port for application
|
||||||
|
EXPOSE 8000
|
||||||
95
Makefile
Normal file
95
Makefile
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
up:
|
||||||
|
docker compose up -d
|
||||||
|
build:
|
||||||
|
docker compose build
|
||||||
|
laravel-install:
|
||||||
|
docker compose exec app composer create-project --prefer-dist laravel/laravel .
|
||||||
|
create-project:
|
||||||
|
mkdir -p src
|
||||||
|
@make build
|
||||||
|
@make up
|
||||||
|
@make laravel-install
|
||||||
|
docker compose exec app php artisan key:generate
|
||||||
|
docker compose exec app php artisan storage:link
|
||||||
|
docker compose exec app chmod -R 777 storage bootstrap/cache
|
||||||
|
docker compose exec app npm install
|
||||||
|
init:
|
||||||
|
docker compose up -d --build
|
||||||
|
docker compose exec app composer install
|
||||||
|
docker compose exec app cp .env.example .env
|
||||||
|
docker compose exec app php artisan key:generate
|
||||||
|
docker compose exec app php artisan storage:link
|
||||||
|
docker compose exec app chmod -R 777 storage bootstrap/cache
|
||||||
|
docker compose exec app npm install
|
||||||
|
@make fresh
|
||||||
|
remake:
|
||||||
|
@make destroy
|
||||||
|
@make init
|
||||||
|
stop:
|
||||||
|
docker compose stop
|
||||||
|
down:
|
||||||
|
docker compose down --remove-orphans
|
||||||
|
down-v:
|
||||||
|
docker compose down --remove-orphans --volumes
|
||||||
|
restart:
|
||||||
|
@make down
|
||||||
|
@make up
|
||||||
|
destroy:
|
||||||
|
docker compose down --rmi all --volumes --remove-orphans
|
||||||
|
ps:
|
||||||
|
docker compose ps
|
||||||
|
logs:
|
||||||
|
docker compose logs
|
||||||
|
logs-watch:
|
||||||
|
docker compose logs --follow
|
||||||
|
log-web:
|
||||||
|
docker compose logs web
|
||||||
|
log-web-watch:
|
||||||
|
docker compose logs --follow web
|
||||||
|
log-app:
|
||||||
|
docker compose logs app
|
||||||
|
log-app-watch:
|
||||||
|
docker compose logs --follow app
|
||||||
|
log-db:
|
||||||
|
docker compose logs postgres
|
||||||
|
log-db-watch:
|
||||||
|
docker compose logs --follow postgres
|
||||||
|
web:
|
||||||
|
docker compose exec web bash
|
||||||
|
app:
|
||||||
|
docker compose exec app bash
|
||||||
|
migrate:
|
||||||
|
docker compose exec app php artisan migrate
|
||||||
|
fresh:
|
||||||
|
docker compose exec app php artisan migrate:fresh --seed
|
||||||
|
seed:
|
||||||
|
docker compose exec app php artisan db:seed
|
||||||
|
dacapo:
|
||||||
|
docker compose exec app php artisan dacapo
|
||||||
|
rollback-test:
|
||||||
|
docker compose exec app php artisan migrate:fresh
|
||||||
|
docker compose exec app php artisan migrate:refresh
|
||||||
|
tinker:
|
||||||
|
docker compose exec app php artisan tinker
|
||||||
|
test:
|
||||||
|
docker compose exec app php artisan test
|
||||||
|
optimize:
|
||||||
|
docker compose exec app php artisan optimize
|
||||||
|
optimize-clear:
|
||||||
|
docker compose exec app php artisan optimize:clear
|
||||||
|
cache:
|
||||||
|
docker compose exec app composer dump-autoload -o
|
||||||
|
@make optimize
|
||||||
|
docker compose exec app php artisan event:cache
|
||||||
|
docker compose exec app php artisan view:cache
|
||||||
|
cache-clear:
|
||||||
|
docker compose exec app composer clear-cache
|
||||||
|
@make optimize-clear
|
||||||
|
docker compose exec app php artisan event:clear
|
||||||
|
dump-autoload:
|
||||||
|
docker compose exec app composer dump-autoload
|
||||||
|
ide-helper:
|
||||||
|
docker compose exec app php artisan clear-compiled
|
||||||
|
docker compose exec app php artisan ide-helper:generate
|
||||||
|
docker compose exec app php artisan ide-helper:meta
|
||||||
|
docker compose exec app php artisan ide-helper:models --nowrite
|
||||||
85
README.md
Normal file
85
README.md
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# Laravel using PostgreSQL in Docker
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./docker/images/laravel+docker.png" alt="docker+laravel">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
Build a simple laravel application development environment with docker compose.
|
||||||
|
|
||||||
|
|
||||||
|
## Requirement
|
||||||
|
|
||||||
|
- Docker ^19.*
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Git clone & move to working directory
|
||||||
|
2. Settings your credentials docker compose using [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/)
|
||||||
|
|
||||||
|
- Create credentials for DB Name
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo "<your_db_name>" | docker secret create app_db_name -
|
||||||
|
```
|
||||||
|
- Create credentials for DB User
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo "<your_db_user>" | docker secret create app_db_user -
|
||||||
|
```
|
||||||
|
- Create credentials for DB Password
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo "<your_db_password>" | docker secret create app_db_password -
|
||||||
|
```
|
||||||
|
### *Optional credentials*
|
||||||
|
If you want to use pgAdmin management add this credentials:
|
||||||
|
|
||||||
|
- Create credentials for pgAdmin Password
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo "<your_pgadmin_password>" | docker secret create app_pgadmin_password -
|
||||||
|
```
|
||||||
|
|
||||||
|
**Uncomment** in top level secret for pgAdmin in file docker-compose.yml to:
|
||||||
|
```bash
|
||||||
|
app_pgadmin_password:
|
||||||
|
external: true
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Execute the following command for create application
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make create-project
|
||||||
|
```
|
||||||
|
|
||||||
|
4. set src/.env variable :
|
||||||
|
```
|
||||||
|
DB_CONNECTION=pgsql
|
||||||
|
DB_HOST=postgres
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_DATABASE=<your_database>
|
||||||
|
DB_USERNAME=<your_username>
|
||||||
|
DB_PASSWORD=<your_password>
|
||||||
|
```
|
||||||
|
|
||||||
|
5. show application in [http://localhost:85](http://localhost:85)
|
||||||
|
6. show adminer in [http://localhost:8080](http://localhost:8080)
|
||||||
|
7. list execute command in [Makefile](Makefile).
|
||||||
|
|
||||||
|
## Container details :
|
||||||
|
- ``app`` use image:
|
||||||
|
- [php](https://hub.docker.com/_/php):8.2-fpm
|
||||||
|
- [composer](https://hub.docker.com/_/composer):2.3
|
||||||
|
- [npm](https://deb.nodesource.com/setup_lts.x):latest
|
||||||
|
- ``web`` use image:
|
||||||
|
- [nginx](https://hub.docker.com/_/nginx):stable-alpine
|
||||||
|
- ``db`` use image:
|
||||||
|
- [postgres](https://hub.docker.com/_/postgres):15
|
||||||
|
- ``adminer`` use image:
|
||||||
|
- [adminer](https://hub.docker.com/_/adminer):latest
|
||||||
|
*Optional*
|
||||||
|
- ``pgadmin`` use image:
|
||||||
|
- [pgadmin](https://hub.docker.com/_/pgadmin):latest
|
||||||
88
docker-compose.yml
Normal file
88
docker-compose.yml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
aselole:
|
||||||
|
name: aselole
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
container_name: aselole-app
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
networks:
|
||||||
|
- aselole
|
||||||
|
|
||||||
|
postgres:
|
||||||
|
container_name: aselole-db
|
||||||
|
image: postgres:15
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./docker/postgres/data:/var/lib/postgres/data
|
||||||
|
environment:
|
||||||
|
- POSTGRES_DB_FILE=/run/secrets/app_db_name
|
||||||
|
- POSTGRES_USER_FILE=/run/secrets/app_db_user
|
||||||
|
- POSTGRES_PASSWORD_FILE=/run/secrets/app_db_password
|
||||||
|
secrets:
|
||||||
|
- app_db_name
|
||||||
|
- app_db_user
|
||||||
|
- app_db_password
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
networks:
|
||||||
|
- aselole
|
||||||
|
|
||||||
|
web:
|
||||||
|
container_name: aselole-web
|
||||||
|
image: nginx:stable-alpine
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "81:80"
|
||||||
|
- "5173:80"
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html
|
||||||
|
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
|
||||||
|
networks:
|
||||||
|
- aselole
|
||||||
|
|
||||||
|
# Database management with pgAdmin
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4
|
||||||
|
container_name: aselole-pgAdmin
|
||||||
|
environment:
|
||||||
|
- PGADMIN_DEFAULT_EMAIL=agung@gmail.com
|
||||||
|
- PGADMIN_DEFAULT_PASSWORD_FILE=/run/secrets/app_pgadmin_password
|
||||||
|
secrets:
|
||||||
|
- app_pgadmin_password
|
||||||
|
ports:
|
||||||
|
- "5050:80"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
networks:
|
||||||
|
- aselole
|
||||||
|
|
||||||
|
# Database management with Adminer
|
||||||
|
adminer:
|
||||||
|
container_name: aselole-adminer
|
||||||
|
image: adminer
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
networks:
|
||||||
|
- aselole
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
app_db_name:
|
||||||
|
external: true
|
||||||
|
app_db_user:
|
||||||
|
external: true
|
||||||
|
app_db_password:
|
||||||
|
external: true
|
||||||
|
app_pgadmin_password:
|
||||||
|
external: true
|
||||||
BIN
docker/image/laravel+docker.png
Normal file
BIN
docker/image/laravel+docker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
35
docker/nginx/default.conf
Normal file
35
docker/nginx/default.conf
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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/html/public;
|
||||||
|
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN";
|
||||||
|
add_header X-XSS-Protection "1; mode=block";
|
||||||
|
add_header X-Content-Type-Options "nosniff";
|
||||||
|
|
||||||
|
charset utf-8;
|
||||||
|
|
||||||
|
location = /favicon.ico { access_log off; log_not_found off; }
|
||||||
|
location = /robots.txt { access_log off; log_not_found off; }
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /\.(?!well-known).* {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
docker/postgres/.gitkeep
Normal file
0
docker/postgres/.gitkeep
Normal file
23
secret.sh
Executable file
23
secret.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Create Docker secrets for the database configuration
|
||||||
|
echo "Creating Docker secrets for the database configuration..."
|
||||||
|
|
||||||
|
# Create the secret for the database name
|
||||||
|
echo "aselole_db" | docker secret create app_db_name -
|
||||||
|
echo "Secret for database name (aselole_db) created."
|
||||||
|
|
||||||
|
# Create the secret for the database user
|
||||||
|
echo "aselole" | docker secret create app_db_user -
|
||||||
|
echo "Secret for database user (aselole) created."
|
||||||
|
|
||||||
|
# Create the secret for the database password
|
||||||
|
echo "password!" | docker secret create app_db_password -
|
||||||
|
echo "Secret for database password created."
|
||||||
|
|
||||||
|
# Create the secret for the database password
|
||||||
|
echo "password!" | docker secret create app_pgadmin_password -
|
||||||
|
echo "Secret for pgAdmin password created."
|
||||||
|
|
||||||
|
# Finished creating Docker secrets
|
||||||
|
echo "Docker secrets for the database configuration have been set up."
|
||||||
Reference in New Issue
Block a user