Skip to content

Commit

Permalink
Merge branch 'main' into charles/2fa
Browse files Browse the repository at this point in the history
  • Loading branch information
notAreYouScared committed Jan 17, 2025
2 parents 4ec9171 + cbacc18 commit a8f31b5
Show file tree
Hide file tree
Showing 59 changed files with 664 additions and 1,359 deletions.
75 changes: 0 additions & 75 deletions .github/docker/default.conf

This file was deleted.

70 changes: 0 additions & 70 deletions .github/docker/default_ssl.conf

This file was deleted.

16 changes: 0 additions & 16 deletions .github/docker/www.conf

This file was deleted.

24 changes: 13 additions & 11 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Docker


on:
push:
branches:
Expand All @@ -15,17 +14,23 @@ env:

jobs:
build-and-push:
name: Build and Push
runs-on: ubuntu-latest
name: Build and Push ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write

strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, ubuntu-24.04-arm]
# Always run against a tag, even if the commit into the tag has [docker skip] within the commit message.
if: "!contains(github.ref, 'main') || (!contains(github.event.head_commit.message, 'skip docker') && !contains(github.event.head_commit.message, 'docker skip'))"

steps:
- name: Code checkout
uses: actions/checkout@v4

- name: Docker metadata
id: docker_meta
uses: docker/metadata-action@v5
Expand All @@ -38,9 +43,6 @@ jobs:
type=ref,event=tag
type=ref,event=branch
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -58,26 +60,26 @@ jobs:
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and Push (tag)
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
if: "github.event_name == 'release' && github.event.action == 'published'"
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
platforms: ${{ matrix.os == 'ubuntu-24.04' && 'linux/amd64' || 'linux/arm64' }}
build-args: |
VERSION=${{ steps.build_info.outputs.version_tag }}
labels: ${{ steps.docker_meta.outputs.labels }}
tags: ${{ steps.docker_meta.outputs.tags }}

- name: Build and Push (main)
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
if: "github.event_name == 'push' && contains(github.ref, 'main')"
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
platforms: ${{ matrix.os == 'ubuntu-24.04' && 'linux/amd64' || 'linux/arm64' }}
build-args: |
VERSION=dev-${{ steps.build_info.outputs.short_sha }}
labels: ${{ steps.docker_meta.outputs.labels }}
Expand Down
61 changes: 39 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,67 @@
# Pelican Production Dockerfile

FROM node:20-alpine AS yarn
#FROM --platform=$TARGETOS/$TARGETARCH node:20-alpine AS yarn
# ================================
# Stage 1: Build PHP Dependencies
# ================================
FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine AS composer

WORKDIR /build

COPY . ./
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Install required libraries and PHP extensions
RUN apk update && apk add --no-cache \
libpng-dev libjpeg-turbo-dev freetype-dev libzip-dev icu-dev \
zip unzip curl \
&& docker-php-ext-install bcmath gd intl zip opcache pcntl posix pdo_mysql

RUN composer install --no-dev --optimize-autoloader

# ================================
# Stage 2: Build Frontend Assets
# ================================
FROM --platform=$TARGETOS/$TARGETARCH node:20-alpine AS yarn

WORKDIR /build

COPY --from=composer /build .

RUN yarn config set network-timeout 300000 \
&& yarn install --frozen-lockfile \
&& yarn run build:production
&& yarn run build

FROM php:8.3-fpm-alpine
# FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# ================================
# Stage 3: Build Final Application Image
# ================================
FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine

WORKDIR /var/www/html

# Install dependencies
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Install additional required libraries
RUN apk update && apk add --no-cache \
libpng-dev libjpeg-turbo-dev freetype-dev libzip-dev icu-dev \
zip unzip curl \
caddy ca-certificates supervisor \
&& docker-php-ext-install bcmath gd intl zip opcache pcntl posix pdo_mysql
zip unzip curl caddy ca-certificates supervisor

# Copy the Caddyfile to the container
COPY Caddyfile /etc/caddy/Caddyfile

# Copy the application code to the container
COPY . .
# Copy PHP extensions and configuration from Composer stage
COPY --from=composer /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=composer /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/

COPY --from=yarn /build/public/assets ./public/assets
COPY Caddyfile /etc/caddy/Caddyfile
COPY --from=yarn /build .

RUN touch .env

RUN composer install --no-dev --optimize-autoloader

# Set file permissions
# Set permissions for Laravel directories
RUN chmod -R 755 storage bootstrap/cache \
&& chown -R www-data:www-data ./

# Add scheduler to cron
# Add Laravel scheduler to crontab
RUN echo "* * * * * php /var/www/html/artisan schedule:run >> /dev/null 2>&1" | crontab -u www-data -

## supervisord config and log dir
# Configure Supervisor
RUN cp .github/docker/supervisord.conf /etc/supervisord.conf && \
mkdir /var/log/supervisord/

Expand Down
14 changes: 6 additions & 8 deletions app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
use App\Models\Schedule;
use Illuminate\Database\Eloquent\Builder;
use App\Services\Schedules\ProcessScheduleService;
use Throwable;

class ProcessRunnableCommand extends Command
{
protected $signature = 'p:schedule:process';

protected $description = 'Process schedules in the database and determine which are ready to run.';

/**
* Handle command execution.
*/
public function handle(): int
public function handle(ProcessScheduleService $processScheduleService): int
{
$schedules = Schedule::query()
->with('tasks')
Expand All @@ -35,7 +33,7 @@ public function handle(): int
$bar = $this->output->createProgressBar(count($schedules));
foreach ($schedules as $schedule) {
$bar->clear();
$this->processSchedule($schedule);
$this->processSchedule($processScheduleService, $schedule);
$bar->advance();
$bar->display();
}
Expand All @@ -50,20 +48,20 @@ public function handle(): int
* never throw an exception out, otherwise you'll end up killing the entire run group causing
* any other schedules to not process correctly.
*/
protected function processSchedule(Schedule $schedule): void
protected function processSchedule(ProcessScheduleService $processScheduleService, Schedule $schedule): void
{
if ($schedule->tasks->isEmpty()) {
return;
}

try {
$this->getLaravel()->make(ProcessScheduleService::class)->handle($schedule);
$processScheduleService->handle($schedule);

$this->line(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
'id' => $schedule->id,
]));
} catch (\Throwable|\Exception $exception) {
} catch (Throwable $exception) {
logger()->error($exception, ['schedule_id' => $schedule->id]);

$this->error(__('commands.schedule.process.no_tasks') . " #$schedule->id: " . $exception->getMessage());
Expand Down
Loading

0 comments on commit a8f31b5

Please sign in to comment.