Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit ffa0498

Browse files
authored
Run app via docker compose (#594)
1 parent 648f3fa commit ffa0498

File tree

9 files changed

+153
-104
lines changed

9 files changed

+153
-104
lines changed

.env.ci

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
APP_NAME=Laravel
1+
APP_NAME=Secretic
22
APP_ENV=local
33
APP_KEY=base64:g3cPbmSz3AC3CoGXtbK81jFgYJnobc4iT27AwRs+FQc=
44
APP_DEBUG=true

.env.local

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
APP_NAME=Laravel
1+
APP_NAME=Secretic
22
APP_ENV=local
33
APP_KEY=base64:g3cPbmSz3AC3CoGXtbK81jFgYJnobc4iT27AwRs+FQc=
44
APP_DEBUG=true
5-
APP_URL=http://localhost
5+
APP_URL=http://localhost:8000
66

77
LOG_CHANNEL=stack
88
LOG_DEPRECATIONS_CHANNEL=null
99
LOG_LEVEL=debug
1010

1111
DB_CONNECTION=mysql
12-
DB_HOST=mysql
12+
DB_HOST=db
1313
DB_PORT=3306
1414
DB_DATABASE=secretic
15-
DB_USERNAME=root
15+
DB_USERNAME=secretic_user
1616
DB_PASSWORD=password
1717

1818
BROADCAST_DRIVER=log

.htaccess

-6
This file was deleted.

Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM php:8.2-fpm
2+
3+
# Arguments defined in docker-compose.yml
4+
ARG user
5+
ARG uid
6+
7+
# Install system dependencies
8+
RUN apt-get update && apt-get install -y \
9+
git \
10+
curl \
11+
libpng-dev \
12+
libonig-dev \
13+
libxml2-dev \
14+
zip \
15+
unzip
16+
17+
# Clear cache
18+
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
19+
20+
# Install PHP extensions
21+
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
22+
23+
# Get latest Composer
24+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
25+
26+
# Create system user to run Composer and Artisan Commands
27+
RUN useradd -G www-data,root -u $uid -d /home/$user $user
28+
RUN mkdir -p /home/$user/.composer && \
29+
chown -R $user:$user /home/$user
30+
31+
# Set working directory
32+
WORKDIR /var/www
33+
34+
USER $user

README.md

+34-8
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,50 @@ The following features will be implemented soon:
2323
- QR code for paste URLs, to easily transfer them over to mobile devices https://github.com/gomzyakov/secretic/issues/489
2424
- API for integration with third parties https://github.com/gomzyakov/secretic/issues/405
2525

26+
2627
## Requesting features
2728

2829
Open a [new issue](https://github.com/gomzyakov/secretic/issues/new) to request a feature (or if you find a bug).
2930

3031

31-
## Run the app with Docker
32+
## How to run Secretic locally?
33+
34+
I believe you already have Docker installed. If not, just do it on [Mac](https://docs.docker.com/desktop/install/mac-install/), [Windows](https://docs.docker.com/desktop/install/windows-install/) or [Linux](https://docs.docker.com/desktop/install/linux-install/).
35+
36+
37+
Build the `app` image with the following command:
38+
39+
```shell
40+
docker compose build --no-cache
41+
```
42+
43+
>This command might take a few minutes to complete.
44+
45+
When the build is finished, you can run the environment in background mode with:
46+
47+
```shell
48+
docker compose up -d
49+
```
50+
51+
We’ll now run `composer install` to install the application dependencies:
52+
53+
```shell
54+
docker compose exec app composer install
55+
```
3256

33-
Before running the Secretic locally:
57+
Copy the environment settings:
3458

35-
- Instead of repeatedly typing `vendor/bin/sail` to execute Sail commands, you may wish to configure a Bash alias ```alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'```
36-
- Copy the environment settings ```cp .env.local .env```
59+
```shell
60+
docker compose exec app cp .env.local .env
61+
```
3762

38-
After that just run the command:
63+
Migrate DB & seed fake data with the `artisan` Laravel command-line tool:
3964

40-
- ```sail up -d``` to run the Secretic ([What if I don't have PHP and Composer on my computer?](https://github.com/gomzyakov/secretic/issues/570))
41-
- ```sail artisan migrate:fresh --seed``` to migrate DB & seed fake data
65+
```shell
66+
docker compose exec app ./artisan migrate:fresh --seed
67+
```
4268

43-
And open http://127.0.0.1 in your favorite browser. Happy using Secretic!
69+
And open http://127.0.0.1:8000 in your favorite browser. Happy using Secretic!
4470

4571

4672
## Can I trust a instance of Secretic not hosted by me?

app/Providers/AppServiceProvider.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Providers;
44

5-
use Illuminate\Support\Facades\URL;
65
use Illuminate\Support\ServiceProvider;
76

87
class AppServiceProvider extends ServiceProvider
@@ -24,6 +23,6 @@ public function register()
2423
*/
2524
public function boot()
2625
{
27-
URL::forceScheme('https');
26+
//
2827
}
2928
}

docker-compose.yml

+37-83
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,50 @@
1-
# For more information: https://laravel.com/docs/sail
2-
version: '3'
1+
version: "3.7"
2+
33
services:
4-
laravel.test:
4+
app:
55
build:
6-
context: ./vendor/laravel/sail/runtimes/8.1
7-
dockerfile: Dockerfile
86
args:
9-
WWWGROUP: '${WWWGROUP}'
10-
image: sail-8.1/app
11-
extra_hosts:
12-
- 'host.docker.internal:host-gateway'
13-
ports:
14-
- '${APP_PORT:-80}:80'
15-
environment:
16-
WWWUSER: '${WWWUSER}'
17-
LARAVEL_SAIL: 1
18-
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
19-
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
7+
user: sammy
8+
uid: 1000
9+
context: ./
10+
dockerfile: Dockerfile
11+
image: secretic
12+
container_name: secretic-app
13+
restart: unless-stopped
14+
working_dir: /var/www/
2015
volumes:
21-
- '.:/var/www/html'
16+
- ./:/var/www
2217
networks:
23-
- sail
24-
depends_on:
25-
- mysql
26-
- redis
27-
- meilisearch
28-
- selenium
29-
mysql:
30-
image: 'mysql/mysql-server:8.0'
31-
ports:
32-
- '${FORWARD_DB_PORT:-3306}:3306'
18+
- secretic
19+
20+
db:
21+
image: mysql:8.0
22+
container_name: secretic-db
23+
restart: unless-stopped
3324
environment:
34-
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
35-
MYSQL_ROOT_HOST: "%"
36-
MYSQL_DATABASE: '${DB_DATABASE}'
37-
MYSQL_USER: '${DB_USERNAME}'
38-
MYSQL_PASSWORD: '${DB_PASSWORD}'
39-
MYSQL_ALLOW_EMPTY_PASSWORD: 1
40-
volumes:
41-
- 'sail-mysql:/var/lib/mysql'
42-
networks:
43-
- sail
44-
healthcheck:
45-
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
46-
retries: 3
47-
timeout: 5s
48-
redis:
49-
image: 'redis:alpine'
50-
ports:
51-
- '${FORWARD_REDIS_PORT:-6379}:6379'
52-
volumes:
53-
- 'sail-redis:/data'
54-
networks:
55-
- sail
56-
healthcheck:
57-
test: ["CMD", "redis-cli", "ping"]
58-
retries: 3
59-
timeout: 5s
60-
meilisearch:
61-
image: 'getmeili/meilisearch:latest'
62-
ports:
63-
- '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
25+
MYSQL_DATABASE: ${DB_DATABASE}
26+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
27+
MYSQL_PASSWORD: ${DB_PASSWORD}
28+
MYSQL_USER: ${DB_USERNAME}
29+
SERVICE_TAGS: dev
30+
SERVICE_NAME: mysql
6431
volumes:
65-
- 'sail-meilisearch:/data.ms'
32+
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
6633
networks:
67-
- sail
68-
healthcheck:
69-
test: ["CMD", "wget", "--no-verbose", "--spider", "http://localhost:7700/health"]
70-
retries: 3
71-
timeout: 5s
72-
mailhog:
73-
image: 'mailhog/mailhog:latest'
74-
platform: linux/amd64
34+
- secretic
35+
36+
nginx:
37+
image: nginx:1.17-alpine
38+
container_name: secretic-nginx
39+
restart: unless-stopped
7540
ports:
76-
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
77-
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
78-
networks:
79-
- sail
80-
selenium:
81-
image: 'selenium/standalone-chrome'
82-
platform: linux/amd64
41+
- 8000:80
8342
volumes:
84-
- '/dev/shm:/dev/shm'
43+
- ./:/var/www
44+
- ./docker-compose/nginx:/etc/nginx/conf.d
8545
networks:
86-
- sail
46+
- secretic
47+
8748
networks:
88-
sail:
49+
secretic:
8950
driver: bridge
90-
volumes:
91-
sail-mysql:
92-
driver: local
93-
sail-redis:
94-
driver: local
95-
sail-meilisearch:
96-
driver: local

docker-compose/nginx/secretic.conf

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
server {
3+
listen 80;
4+
index index.php index.html;
5+
error_log /var/log/nginx/error.log;
6+
access_log /var/log/nginx/access.log;
7+
root /var/www/public;
8+
location ~ \.php$ {
9+
try_files $uri =404;
10+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
11+
fastcgi_pass app:9000;
12+
fastcgi_index index.php;
13+
include fastcgi_params;
14+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
15+
fastcgi_param PATH_INFO $fastcgi_path_info;
16+
}
17+
location / {
18+
try_files $uri $uri/ /index.php?$query_string;
19+
gzip_static on;
20+
}
21+
}

server.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* Laravel - A PHP Framework For Web Artisans
5+
*
6+
* @package Laravel
7+
* @author Taylor Otwell <[email protected]>
8+
*/
9+
10+
$uri = urldecode(
11+
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
12+
);
13+
14+
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
15+
// built-in PHP web server. This provides a convenient way to test a Laravel
16+
// application without having installed a "real" web server software here.
17+
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
18+
return false;
19+
}
20+
21+
require_once __DIR__.'/public/index.php';

0 commit comments

Comments
 (0)