Skip to content

Commit

Permalink
Merge pull request #62 from fykosak/dev-docker
Browse files Browse the repository at this point in the history
docker base
  • Loading branch information
Headary authored Dec 20, 2023
2 parents 5037a83 + ac9bc6f commit fb01e2b
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 43 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: Create and publish a Docker image
on: push

on:
push:
branchers:
- master
- dev-docker
paths:
- 'docker/**'
- '.github/workflows/deploy-image.yml'

env:
REGISTRY: ghcr.io
Expand All @@ -14,21 +22,25 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
uses: docker/build-push-action@v5
with:
context: .
context: docker
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/nbproject/
app/config/config.*.local.neon
app/config/local/*
www/*/adminer/.htaccess
vendor/*
log/*
temp/*
!vendor/others
www/*/images/reports
www/*/images/reports/
www/*/documents
www/*/assets
node_modules
Expand Down
6 changes: 1 addition & 5 deletions app/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ private static function boot(string $site): Configurator
->register();

$configurator->addConfig(__DIR__ . '/config/config.' . $site . '.neon');
if (getenv('NETTE_EXTERNAL_LOCAL_CONFIG') === '1') {
$configurator->addConfig(__DIR__ . '/config/local/config.' . $site . '.local.neon');
} else {
$configurator->addConfig(__DIR__ . '/config/config.' . $site . '.local.neon');
}
$configurator->addConfig(__DIR__ . '/config/local/' . $site . '.neon');

return $configurator;
}
Expand Down
6 changes: 3 additions & 3 deletions app/Modules/Fol/ArchiveModule/templates/Reports/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div n:class="panel, $counter ? color-light : color-dark">
<section class="inner-container row">
<div class="col-md-4" id="{$report_id}-container" n:if="count($report->images)">
<img id="{$report_id}" src="{$basePath . '/images/reports/' . $report->images[0]->filename}" class="img-fluid">
<img id="{$report_id}" src="{$basePath . '/photos/' . $report->images[0]->filename}" class="img-fluid">
<div class="row gallery-thumbnails" id="{$report_id}-row">
{varType bool $solo} {* true when there's only one picture *}
{do $solo = true}
Expand All @@ -46,9 +46,9 @@
{/if}
{do $noImage = false}
{varType string $source}
{do $source = $basePath . '/images/reports/' . $reportImage->filename}
{do $source = $basePath . '/photos/' . $reportImage->filename}
<div class="col-4">
<img src="{$basePath}/images/reports/{$reportImage->filename}" alt="{$reportImage->caption}" onclick="gallery({$source}, {$report_id});" class="img-fluid">
<img src="{$basePath}/photos/{$reportImage->filename}" alt="{$reportImage->caption}" onclick="gallery({$source}, {$report_id});" class="img-fluid">
</div>
{/foreach}
<script n:if="$solo">
Expand Down
9 changes: 3 additions & 6 deletions app/Modules/Fykos/DefaultModule/ResultsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use App\Models\Downloader\FKSDBDownloader\FKSDBDownloader;
use Fykosak\FKSDBDownloaderCore\Requests\SeriesResultsRequest;


class ResultsPresenter extends BasePresenter
{

private FKSDBDownloader $downloader;

private int $FYKOSYear = 36; // TODO: get from URL

public function injectDownloader(FKSDBDownloader $downloader): void
{
$this->downloader = $downloader;
Expand All @@ -24,8 +23,7 @@ public function actionDefault(int $year = null): void
{
if ($year !== null) {
$this->FYKOSYear = $year;
}
else {
} else {
$this->FYKOSYear = $this->currentFYKOSYear;
}
}
Expand All @@ -37,8 +35,7 @@ public function renderDefault(): void
{
$this->template->FYKOSYear = $this->FYKOSYear;
$this->template->currentFYKOSYear = $this->currentFYKOSYear;

$this->template->results = json_decode($this->downloader->download(new SeriesResultsRequest(1, $this->FYKOSYear, 1)), true);

}
}
11 changes: 1 addition & 10 deletions app/Modules/Fykos/EventsModule/CampsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

declare(strict_types=1);



namespace App\Modules\Fykos\EventsModule;

use DOMDocument;


class CampsPresenter extends BasePresenter
{


public function renderDefault()
{

// Fetch the webpage
$html = file_get_contents('https://fykos.cz/akce/soustredeni/start');


// Create a new DOM document
$doc = new DOMDocument;
$doc = new DOMDocument();

// Suppress errors due to ill-formed HTML
libxml_use_internal_errors(true);
Expand All @@ -39,7 +32,5 @@ public function renderDefault()
$htmlContent = $doc->saveHTML($content);

$this->template->oldContent = $htmlContent;


}
}
2 changes: 0 additions & 2 deletions app/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ private static function useTranslateFilter(?array $domainList, array $routerMapp
}

// Either set the language in the domain, or in lang parameter

if (isset($domainList) && count($domainList)) {
$params['domain'] = array_search($params['lang'], $domainList);
if ($params['domain'] === false) {
Expand Down Expand Up @@ -213,7 +212,6 @@ public static function createFykosRouter(?array $domainList, array $routerMappin
null => self::useTranslateFilter($domainList, $routerMapping['default']),
]);


return $router;
}

Expand Down
14 changes: 10 additions & 4 deletions app/config/config.local.neon.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
parameters:
# FKSDB API endpoint
fksdbDownloader:
login:
password:
url:
gameApiURL:
login: ''
password: ''
url: 'https://db.fykos.cz/api/'

# game API endpoint, used for FOL/FOF live results
#gameApi:
# login: ''
# password: ''
# url: ''
9 changes: 5 additions & 4 deletions app/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ services:
- Fykosak\NetteFKSDBDownloader\ORM\Services\ServiceEventDetail('10 minutes')
- Fykosak\NetteFKSDBDownloader\ORM\Services\ServiceEventList('10 minutes')
- App\Models\GamePhaseCalculator(%eventTypeId%)
- App\Models\Game\Connector(%gameApiURL%, %gameApiUser%, %gameApiPass%)
- App\Models\Game\Connector(%gameApi.url%, %gameApi.login%, %gameApi.password%)
- App\Models\Downloader\FKSDBDownloader\FKSDBDownloader(%fksdbDownloader.url%,%fksdbDownloader.login%,%fksdbDownloader.password%,'10 minutes')

extensions:
asset: SixtyEightPublishers\Asset\Bridge\Nette\DI\AssetExtension

parameters:
gameApiURL: /dev/null
i18n:
locales:
cs: cs_CZ.utf-8
Expand All @@ -30,5 +29,7 @@ parameters:
domains:
# domain: lang
eventTypeId: 0
gameApiUser:
gameApiPass:
gameApi:
login:
password:
url: ''
3 changes: 3 additions & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
log
temp
config
38 changes: 38 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM php:8.1-apache

# install needed packages
RUN apt update && apt install -y \
gettext \
libfreetype-dev \
libjpeg62-turbo-dev \
libpng-dev \
libxml2-dev \
locales \
npm \
unzip

# install locales for i18n
RUN echo 'cs_CZ.UTF-8 UTF-8' >> /etc/locale.gen && \
echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && \
locale-gen

# install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# install apache EXTENSIONS
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN EXTENSIONS="gettext soap opcache gd" \
&& docker-php-ext-install $EXTENSIONS \
&& docker-php-ext-enable $EXTENSIONS
RUN a2enmod rewrite proxy proxy_http

# install recommended config
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY ./entrypoint.sh /
CMD /entrypoint.sh

EXPOSE 80

ENV MODE=prod
ENV NETTE_DEVEL=0
44 changes: 44 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Docker
`Dockerfile` a `docker-compose` pro jednoduché spuštění webů.

## Vývoj webů
- nutnost: nainstalovaný `docker` a `docker-compose-plugin`
- vytvoření aktuální image: `docker compose build` (potřeba spustit před prvním spuštěním)
- spuštění: `docker compose up`
- doplnění přihlašovacích údajů do FKSDB do `local/*.neon` (nutno případné promazání cache v `temp` )
- přístup: `localhost` na portech `8080-8084`
- spouštění příkazů uvnitř dockeru (`composer install`, `npm build` atd.): `docker exec -it webs <příkaz>`
- nainstalování composer balíčků: `docker exec -it webs composer install`
- nainstalování npm balíčků: `docker exec -it webs npm install`
- build CSS a JS:
- jednorázově: `docker exec -it webs npm run build`
- kontinuálně: `docker exec -it webs npm run dev`
- dostání se do konzole přímo uvnitř kontejneru: `docker exec -it webs /bin/bash`

## Produkce
### Setup
- vytvoření hlavní složky pro vše, například `data`
- clone repozitáře `webs` do této složky `data`, ve výsledku tedy `data/webs`
- zkopírování souboru `docker-compose.prod.yml` do `data/docker-compose.yml`
```
cp webs/config/docker-compose.prod.yml docker-compose.yml
```
- vytvoření všech potřebných složek
```
mkdir -p config/local temp log photos/dsef photos/fof photos/fol photos/fykos photos/vyfuk
```
- zkopírování Apache konfigurace
```
cp webs/config/apache.conf config/
```
- vytvoření složky `config/local` pro lokální konfigurace všech webů a její naplnění
```
cp webs/app/config/config.local.neon.example config/local/dsef.neon
cp webs/app/config/config.local.neon.example config/local/fol.neon
cp webs/app/config/config.local.neon.example config/local/fof.neon
cp webs/app/config/config.local.neon.example config/local/fykos.neon
cp webs/app/config/config.local.neon.example config/local/vyfuk.neon
```
- změna potřebné konfigurace ve všech souborech a zapnutí `docker compose`
- nainstalování composer a npm balíčků
- build npm
Loading

0 comments on commit fb01e2b

Please sign in to comment.