Skip to content

Commit 1d10629

Browse files
committed
Add Docker ignore file, migration for test_entries table, and update job handling
1 parent c5dfaf5 commit 1d10629

File tree

10 files changed

+190
-41
lines changed

10 files changed

+190
-41
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/.phpunit.cache
2+
/bootstrap/ssr
3+
/node_modules
4+
/public/build
5+
/public/hot
6+
/public/storage
7+
/storage/*.key
8+
/storage/pail
9+
/vendor
10+
.env
11+
.env.backup
12+
.env.production
13+
.phpactor.json
14+
.phpunit.result.cache
15+
Homestead.json
16+
Homestead.yaml
17+
npm-debug.log
18+
yarn-error.log
19+
/auth.json
20+
/.fleet
21+
/.idea
22+
/.nova
23+
/.vscode
24+
/.zed
25+
*.log

.github/workflows/docker-build.yml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ jobs:
2424
steps:
2525
- name: Checkout code
2626
uses: actions/checkout@v3
27-
27+
2828
- name: Docker meta
2929
id: meta
3030
uses: docker/metadata-action@v5
3131
with:
3232
images: |
33-
herrlevin/laravel-docker-text
33+
herrlevin/laravel-docker-test
3434
tags: |
3535
type=ref,event=branch
3636
type=semver,pattern={{version}}
@@ -50,24 +50,15 @@ jobs:
5050
push: ${{ github.event_name != 'pull_request' }}
5151
tags: ${{ steps.meta.outputs.tags }}
5252
labels: ${{ steps.meta.outputs.labels }}
53-
53+
5454
- name: Deploy via SSH
5555
uses: appleboy/[email protected]
5656
with:
5757
host: ${{ secrets.SSH_HOST }}
5858
username: ${{ secrets.SSH_USER }}
59-
key: <span class="math-inline">\{\{ secrets\.SSH\_KEY \}\}
59+
port: ${{ secrets.SSH_PORT || 22 }}
60+
key: ${{ secrets.SSH_KEY }}
6061
script: |
61-
docker pull {IMAGE_REPOSITORY}/{IMAGE_NAME}\:</span>{{ github.event.inputs.tag || github.ref_name }}
62-
63-
docker stop {IMAGE_NAME} || true
64-
docker rm {IMAGE_NAME} || true
65-
66-
docker run -d --name {IMAGE_NAME} \
67-
-v /var/www/html/{FOLDER_NAME}/.env:/var/www/html/.env \
68-
-v /var/www/html/{FOLDER_NAME}/database/database.sqlite:/var/www/html/database/database.sqlite \
69-
-v /var/www/html/{FOLDER_NAME}/storage/logs:/var/www/html/storage/logs \
70-
-p 80:80 \
71-
--env-file /var/www/html/{FOLDER_NAME}/.env \
72-
{IMAGE_REPOSITORY}/{IMAGE_NAME}:${{ github.event.inputs.tag || github.ref_name }}
73-
62+
cd ${{ secrets.PATH_TO_LARAVEL_PROJECT }}
63+
docker compose -f docker-compose.production.yml pull
64+
docker compose -f docker-compose.production.yml up -d

Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,28 @@ ARG RUNTIME_GID=33
1212

1313
# Install required system dependencies
1414
RUN apk add --no-cache \
15-
nginx \
16-
supervisor \
15+
bash \
1716
icu-dev \
17+
libpq-dev \
1818
libzip-dev \
19-
zlib-dev \
19+
nginx \
20+
nodejs \
21+
npm \
2022
oniguruma-dev \
2123
shadow \
22-
bash \
2324
sqlite-dev \
24-
nodejs \
25-
npm
25+
supervisor \
26+
zlib-dev
2627

2728
# Install required PHP extensions
2829
RUN docker-php-ext-install \
2930
bcmath \
31+
intl \
32+
opcache \
3033
pdo_mysql \
34+
pdo_pgsql \
3135
pdo_sqlite \
32-
zip \
33-
intl \
34-
opcache
36+
zip
3537

3638
RUN groupmod --gid ${RUNTIME_GID} www-data \
3739
&& usermod --uid ${RUNTIME_UID} --gid ${RUNTIME_GID} www-data

app/Jobs/TestJob.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Jobs;
44

5+
use App\Models\TestEntry;
56
use Illuminate\Contracts\Queue\ShouldQueue;
67
use Illuminate\Foundation\Queue\Queueable;
78
use Illuminate\Support\Facades\Log;
@@ -14,7 +15,10 @@ public function handle(): void
1415
{
1516
Log::info("TestJob started");
1617
// Simulate some work
17-
sleep(10); // Simulating a delay of 5 seconds
18+
sleep(10); // Simulating a delay of 10 seconds
19+
TestEntry::create([
20+
'created_by' => 'TestJob',
21+
]);
1822
Log::info("TestJob completed");
1923
}
2024
}

app/Models/TestEntry.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Concerns\HasUuids;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class TestEntry extends Model
9+
{
10+
use HasUuids;
11+
12+
protected $fillable = [
13+
'created_by',
14+
];
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('test_entries', function (Blueprint $table) {
12+
$table->uuid('id')->primary();
13+
$table->string('created_by')->nullable();
14+
$table->timestamps();
15+
});
16+
}
17+
18+
public function down(): void
19+
{
20+
Schema::dropIfExists('test_entries');
21+
}
22+
};

docker/entrypoint.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ if [ ! -f /var/www/html/database/database.sqlite ]; then
1212
fi
1313

1414
if [ ! -f /var/www/html/.env ]; then
15-
echo "Environment file not found. Copying example..."
16-
cp /var/www/html/.env.example.prod /var/www/html/.env
17-
php artisan key:generate
15+
echo "Environment file not found. Creating a new one..."
16+
touch /var/www/html/.env
17+
echo "APP_ENV=production" >> /var/www/html/.env
18+
echo "APP_DEBUG=false" >> /var/www/html/.env
19+
echo "APP_KEY=base64:$(openssl rand -base64 32)" > /var/www/html/.env
1820
fi
1921

2022
# Set correct permissions

docker/supervisor/supervisord.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ autostart=true
1717
autorestart=true
1818
stdout_logfile=/var/log/nginx/access.log
1919
stderr_logfile=/var/log/nginx/error.log
20+
21+
[program:laravel-worker]
22+
process_name=%(program_name)s_%(process_num)02d
23+
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3 --max-time=3600
24+
autostart=true
25+
autorestart=true
26+
stopasgroup=true
27+
killasgroup=true
28+
user=www-data
29+
numprocs=8
30+
redirect_stderr=true
31+
stdout_logfile=/var/www/html/storage/logs/worker.log
32+
stopwaitsecs=3600

resources/js/pages/Welcome.vue

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { Head, Link } from '@inertiajs/vue3';
77
<link rel="preconnect" href="https://rsms.me/" />
88
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" />
99
</Head>
10-
<div class="flex min-h-screen flex-col items-center bg-[#FDFDFC] p-6 text-[#1b1b18] lg:justify-center lg:p-8 dark:bg-[#0a0a0a]">
10+
<div
11+
class="flex min-h-screen flex-col items-center bg-[#FDFDFC] p-6 text-[#1b1b18] lg:justify-center lg:p-8 dark:bg-[#0a0a0a]">
1112
<header class="mb-6 w-full max-w-[335px] text-sm not-has-[nav]:hidden lg:max-w-4xl">
1213
<nav class="flex items-center justify-end gap-4">
1314
<Link
@@ -33,16 +34,67 @@ import { Head, Link } from '@inertiajs/vue3';
3334
</template>
3435
</nav>
3536
</header>
36-
<div class="flex w-full items-center justify-center opacity-100 transition-opacity duration-750 lg:grow starting:opacity-0">
37-
<main class="flex w-full max-w-[335px] flex-col-reverse overflow-hidden rounded-lg lg:max-w-4xl lg:flex-row">
37+
<div
38+
class="flex w-full items-center justify-center opacity-100 transition-opacity duration-750 lg:grow starting:opacity-0">
39+
<main
40+
class="flex w-full max-w-[335px] flex-col-reverse overflow-hidden rounded-lg lg:max-w-4xl lg:flex-row">
3841
<div
3942
class="flex-1 rounded-br-lg rounded-bl-lg bg-white p-6 pb-12 text-[13px] leading-[20px] shadow-[inset_0px_0px_0px_1px_rgba(26,26,0,0.16)] lg:rounded-tl-lg lg:rounded-br-none lg:p-20 dark:bg-[#161615] dark:text-[#EDEDEC] dark:shadow-[inset_0px_0px_0px_1px_#fffaed2d]"
4043
>
4144
<h1 class="mb-1 font-medium">Let's get started</h1>
4245
<p class="mb-2 text-[#706f6c] dark:text-[#A1A09A]">
43-
Laravel has an incredibly rich ecosystem. <br />We suggest starting with the following.
46+
This is a demo project to showcase a containerized Laravel application using Inertia.js and Vue
47+
3. <br />
48+
This example project is built with redis and postgres in mind.
49+
50+
More information at: <a href="https://github.com/HerrLevin/laravel-docker-test"
51+
target="_blank"
52+
class="ml-1 inline-flex items-center space-x-1 font-medium text-[#f53003] underline underline-offset-4 dark:text-[#FF4433]"
53+
>https://github.com/HerrLevin/laravel-docker-test</a>
4454
</p>
4555
<ul class="mb-4 flex flex-col lg:mb-6">
56+
<li
57+
class="relative flex items-center gap-4 py-2 before:absolute before:top-1/2 before:bottom-0 before:left-[0.4rem] before:border-l before:border-[#e3e3e0] dark:before:border-[#3E3E3A]"
58+
>
59+
<span class="relative bg-white py-1 dark:bg-[#161615]">
60+
<span
61+
class="flex h-3.5 w-3.5 items-center justify-center rounded-full border border-[#e3e3e0] bg-[#FDFDFC] shadow-[0px_0px_1px_0px_rgba(0,0,0,0.03),0px_1px_2px_0px_rgba(0,0,0,0.06)] dark:border-[#3E3E3A] dark:bg-[#161615]"
62+
>
63+
<span class="h-1.5 w-1.5 rounded-full bg-[#dbdbd7] dark:bg-[#3E3E3A]" />
64+
</span>
65+
</span>
66+
<span>
67+
Queue a job
68+
<a
69+
href="/test-job"
70+
target="_blank"
71+
class="ml-1 inline-flex items-center space-x-1 font-medium text-[#f53003] underline underline-offset-4 dark:text-[#FF4433]"
72+
>
73+
<span>Here</span>
74+
</a>
75+
</span>
76+
</li>
77+
<li
78+
class="relative flex items-center gap-4 py-2 before:absolute before:top-1/2 before:bottom-0 before:left-[0.4rem] before:border-l before:border-[#e3e3e0] dark:before:border-[#3E3E3A]"
79+
>
80+
<span class="relative bg-white py-1 dark:bg-[#161615]">
81+
<span
82+
class="flex h-3.5 w-3.5 items-center justify-center rounded-full border border-[#e3e3e0] bg-[#FDFDFC] shadow-[0px_0px_1px_0px_rgba(0,0,0,0.03),0px_1px_2px_0px_rgba(0,0,0,0.06)] dark:border-[#3E3E3A] dark:bg-[#161615]"
83+
>
84+
<span class="h-1.5 w-1.5 rounded-full bg-[#dbdbd7] dark:bg-[#3E3E3A]" />
85+
</span>
86+
</span>
87+
<span>
88+
Or look at the job-created sample data
89+
<a
90+
href="/test-entries"
91+
target="_blank"
92+
class="ml-1 inline-flex items-center space-x-1 font-medium text-[#f53003] underline underline-offset-4 dark:text-[#FF4433]"
93+
>
94+
<span>Here</span>
95+
</a>
96+
</span>
97+
</li>
4698
<li
4799
class="relative flex items-center gap-4 py-2 before:absolute before:top-1/2 before:bottom-0 before:left-[0.4rem] before:border-l before:border-[#e3e3e0] dark:before:border-[#3E3E3A]"
48100
>
@@ -60,7 +112,7 @@ import { Head, Link } from '@inertiajs/vue3';
60112
target="_blank"
61113
class="ml-1 inline-flex items-center space-x-1 font-medium text-[#f53003] underline underline-offset-4 dark:text-[#FF4433]"
62114
>
63-
<span>Documentation</span>
115+
<span>Laravel Documentation</span>
64116
<svg
65117
width="{10}"
66118
height="{11}"
@@ -69,7 +121,8 @@ import { Head, Link } from '@inertiajs/vue3';
69121
xmlns="http://www.w3.org/2000/svg"
70122
class="h-2.5 w-2.5"
71123
>
72-
<path d="M7.70833 6.95834V2.79167H3.54167M2.5 8L7.5 3.00001" stroke="currentColor" stroke-linecap="square" />
124+
<path d="M7.70833 6.95834V2.79167H3.54167M2.5 8L7.5 3.00001"
125+
stroke="currentColor" stroke-linecap="square" />
73126
</svg>
74127
</a>
75128
</span>
@@ -100,7 +153,8 @@ import { Head, Link } from '@inertiajs/vue3';
100153
xmlns="http://www.w3.org/2000/svg"
101154
class="h-2.5 w-2.5"
102155
>
103-
<path d="M7.70833 6.95834V2.79167H3.54167M2.5 8L7.5 3.00001" stroke="currentColor" stroke-linecap="square" />
156+
<path d="M7.70833 6.95834V2.79167H3.54167M2.5 8L7.5 3.00001"
157+
stroke="currentColor" stroke-linecap="square" />
104158
</svg>
105159
</a>
106160
</span>

routes/web.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Jobs\TestJob;
4+
use App\Models\TestEntry;
45
use Illuminate\Support\Facades\Route;
56
use Inertia\Inertia;
67

@@ -12,9 +13,29 @@
1213
return Inertia::render('Dashboard');
1314
})->middleware(['auth', 'verified'])->name('dashboard');
1415

15-
Route::get('test-tob', function () {
16+
Route::get('test-entries', function () {
17+
$entries = TestEntry::all();
18+
19+
return response()->json([
20+
'info' => 'This endpoint is used to test the persistence of the database and the job queue system. You can trigger a job at ' . route('test-job'),
21+
'count' => $entries->count(),
22+
'entries' => $entries->map(function ($entry) {
23+
return [
24+
'id' => $entry->id,
25+
'created_by' => $entry->created_by,
26+
'created_at' => $entry->created_at->toDateTimeString(),
27+
];
28+
}),
29+
]);
30+
})->name('test-entries');
31+
32+
Route::get('test-job', function () {
1633
TestJob::dispatch();
17-
});
1834

19-
require __DIR__.'/settings.php';
20-
require __DIR__.'/auth.php';
35+
return response()->json([
36+
'success' => 'The job should have been dispatched! To test the results & persistence of the database, check ' . route('test-entries') . ' after a few seconds.',
37+
]);
38+
})->name('test-job');
39+
40+
require __DIR__ . '/settings.php';
41+
require __DIR__ . '/auth.php';

0 commit comments

Comments
 (0)