Skip to content

Commit

Permalink
feat: docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Quadrubo committed Jul 13, 2023
1 parent 1762f1a commit 93f127e
Show file tree
Hide file tree
Showing 29 changed files with 368 additions and 67 deletions.
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/.git
/.github
/.idea
/.vscode
/docker/*
!/docker/deploy
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/logs
/storage/app/private
/storage/app/public/fonts
/data
/vendor
_ide_helper.php
.editorconfig
.phpstorm.meta.php
.phpunit.result.cache
auth.json
docker-compose.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
25 changes: 10 additions & 15 deletions .env.host → .env.prod.example
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
APP_NAME=WOL-Client
APP_ENV=local
APP_ENV=production
APP_KEY=
APP_DEBUG=true
APP_DEBUG=false
APP_URL=http://localhost
FORCE_HTTPS=false

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=wol_client
DB_USERNAME=sail
DB_PASSWORD=password
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=wol_client
# DB_USERNAME=sail
# DB_PASSWORD=password

BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
Expand All @@ -24,7 +25,7 @@ SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

Expand Down Expand Up @@ -61,11 +62,5 @@ SCOUT_DRIVER=meilisearch
MEILISEARCH_HOST=http://meilisearch:7700

APP_TIMEZONE="UTC"

SAIL_XDEBUG_MODE=develop,debug,coverage

DISCORD_WEBHOOK_URL=

WWWUSER=1000
WWWGROUP=sail

File renamed without changes.
56 changes: 56 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build and push Docker image to GHCR

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
workflow_dispatch:
release:
branches: ['main']
types: ['published']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PLATFORMS: linux/amd64, linux/arm64, linux/arm/v7

jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: ${{ env.PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/public/hot
/public/storage
/storage/*.key
/data
/vendor
.env
.env.backup
Expand Down
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM serversideup/php:8.2-fpm-nginx

ARG NODE_VERSION=18

# Add /config to allowed directory tree
ENV PHP_OPEN_BASEDIR=$WEBUSER_HOME:/config/:/dev/stdout:/tmp

# Enable mixed ssl mode so port 80 or 443 can be used
ENV SSL_MODE="mixed"

# Install additional packages and cron file
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
cron \
htop \
# Install cron file
&& echo "MAILTO=\"\"\n* * * * * webuser /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel \
# Install node & npm
&& curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm \
# Clean up package lists
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Copy package configs
COPY --chmod=755 docker/deploy/etc/s6-overlay/ /etc/s6-overlay/

WORKDIR /var/www/html

# Copy app
COPY --chown=webuser:webgroup . /var/www/html/

# Install composer dependencies
RUN composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev --no-cache \
&& mkdir -p storage/logs \
&& php artisan optimize:clear \
&& chown -R webuser:webgroup /var/www/html

# Install npm dependencies
RUN npm ci \
&& npm run build

VOLUME /config
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sail up
Copy the environment file.

```
cp .env.dev .env
cp .env.sail.example .env
```

Generate the app key.
Expand Down
48 changes: 48 additions & 0 deletions database/seeders/FirstAdminUserSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;

class FirstAdminUserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// exit if there are users in the system
if (User::count() !== 0) {
return;
}

$user = User::create([
'name' => 'admin',
'email' => '[email protected]',
'email_verified_at' => Carbon::now(),
'password' => Hash::make('password'),
]);

$roles = Role::all();

// give the user full permissions
foreach ($roles as $role) {
if (DB::table('model_has_roles')->where('role_id', $role->id)->where('model_id', $user->id)->count() == 0) {
DB::table('model_has_roles')->insert([
'role_id' => $role->id,
'model_type' => \App\Models\User::class,
'model_id' => $user->id,
]);
}
}

app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
}
}
51 changes: 0 additions & 51 deletions docker-compose-host.yml

This file was deleted.

22 changes: 22 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'
services:
wol-client:
build:
context: ./
dockerfile: Dockerfile
container_name: wol-client
ports:
- '8080:80'
- '8443:443'
- '6001:6001' # Websocket server
environment:
- PUID=1000
- PGID=1000
- APP_URL=http://localhost:8080
- TZ=Europe/Berlin
volumes:
- '/etc/localtime:/etc/localtime:ro'
- './data/config:/config' # Directory for sqlite database & .env
- './data/ssl/web:/etc/ssl/web' # Directory for ssl certificates
image: wol-client
restart: unless-stopped
Empty file.
2 changes: 2 additions & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/cron/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/command/with-contenv bash
s6-setuidgid root /usr/sbin/cron -f -l 8
1 change: 1 addition & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/cron/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
2 changes: 2 additions & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/default-queue/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/command/with-contenv bash
s6-setuidgid webuser php $WEBUSER_HOME/artisan queue:work --tries=3 --no-ansi -q
1 change: 1 addition & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/default-queue/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
runas-user
configure-ssl
Empty file.
2 changes: 2 additions & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/notifications-queue/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/command/with-contenv bash
s6-setuidgid webuser php $WEBUSER_HOME/artisan queue:work --queue notifications --tries=3 --no-ansi -q
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/websockets/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/command/with-contenv bash
s6-setuidgid webuser php $WEBUSER_HOME/artisan websockets:serve --no-ansi -q
1 change: 1 addition & 0 deletions docker/deploy/etc/s6-overlay/s6-rc.d/websockets/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Loading

0 comments on commit 93f127e

Please sign in to comment.