Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI
on:
pull_request:
branches: [ "dev" ]

jobs:
build:
runs-on: ubuntu-latest
env:
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.override.yml
COMPOSE_PROJECT_NAME: ci-${{ github.job }}-${{ github.run_id }}
steps:
- uses: actions/checkout@v4

- name: Build services
run: docker compose build

- name: Show service logs if failed
if: failure()
run: docker compose logs

- name: Container runs
run: docker compose run --rm --no-deps -T findingaid php -v

- name: Teardown
if: always()
run: docker compose down -v --remove-orphans

lint:
needs: build
runs-on: ubuntu-latest
# TODO: Fix the linting errors
# Report the failure, but don't stop the job
continue-on-error: true
env:
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.override.yml
COMPOSE_PROJECT_NAME: ci-${{ github.job }}-${{ github.run_id }}
steps:
- uses: actions/checkout@v4

- name: Build services
run: docker compose build

- name: Show service logs if failed
if: failure()
run: docker compose logs

- name: Run linting inside app container
run: docker compose run --rm -T findingaid /vendor/bin/phpcs -w --exclude=Generic.Files.LineLength --standard=PSR12 /tests /app

- name: Teardown
if: always()
run: docker compose down -v --remove-orphans

unit-test:
needs: build
runs-on: ubuntu-latest
env:
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.override.yml
COMPOSE_PROJECT_NAME: ci-${{ github.job }}-${{ github.run_id }}
steps:
- uses: actions/checkout@v4

- name: Build services
run: docker compose build

- name: Start services
run: docker compose up -d findingaid

- name: Show service logs if failed
if: failure()
run: docker compose logs

- name: Run tests inside app container
run: docker compose run --rm -T findingaid /vendor/bin/phpunit -c /phpunit.xml /tests

- name: Teardown
if: always()
run: docker compose down -v --remove-orphans
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish release
on:
push: [dev]

permissions:
contents: read
packages: write

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}

- uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry (ghcr)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/findingaid:${{ github.sha }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ misc/
public/minimal*
public/cache
is_prod
.phpunit.result.cache
34 changes: 30 additions & 4 deletions dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN git clone https://github.com/douglascrockford/JSMin /tmp/jsmin && \
gcc /tmp/jsmin/jsmin.c -o /usr/bin/jsmin && \
rm -rf /tmp/jsmin

FROM php:8.0-fpm-alpine AS development
FROM php:8.3-fpm-alpine AS development

# add other deps for dev here
RUN apk add --no-cache \
Expand All @@ -35,22 +35,48 @@ ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
EXPOSE 9000
CMD ["php-fpm", "-F"]

FROM php:8.0-fpm-alpine AS prod-builder
FROM php:8.3-fpm-alpine AS prod-builder

RUN apk add --no-cache bash

COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer
COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin

WORKDIR /app
COPY ./composer.json .
COPY ./composer.lock .

RUN composer install --no-interaction --no-dev

COPY ./app .

FROM php:8.3-fpm-alpine as CI

RUN apk add --no-cache \
libzip-dev \
bash

WORKDIR /app

COPY . .
COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin
COPY --from=prod-builder /app .
COPY --from=development /vendor /vendor
COPY ./phpunit.xml /phpunit.xml

COPY exe/build.sh /exe/build.sh
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
EXPOSE 9000
CMD ["php-fpm", "-F"]

FROM php:8.0-fpm-alpine AS production
FROM php:8.3-fpm-alpine AS production

WORKDIR /app

COPY --from=prod-builder /app .
COPY --from=prod-builder /vendor /vendor

COPY exe/build.sh /exe/build.sh
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
Expand Down
16 changes: 8 additions & 8 deletions app/config/config.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php
class Config
{
private $config = array();
private $repo = array();
private $config = [];
private $repo = [];
private $nonuk = null;

public function __construct()
{
$config_file = implode(DIRECTORY_SEPARATOR, array(
$config_file = implode(DIRECTORY_SEPARATOR, [
APP,
'config',
'config.json',
));
]);
if (file_exists($config_file)) {
$this->config = json_decode(file_get_contents($config_file), true);
}
$repo_file = implode(DIRECTORY_SEPARATOR, array(
$repo_file = implode(DIRECTORY_SEPARATOR, [
APP,
'config',
'repo.json',
));
]);
if (file_exists($repo_file)) {
$this->repo = json_decode(file_get_contents($repo_file), true);
}
Expand Down Expand Up @@ -48,11 +48,11 @@ public function get_repo($key)
public function get_nonuk($key)
{
if (!isset($this->nonuk)) {
$nonuk_config_file = implode(DIRECTORY_SEPARATOR, array(
$nonuk_config_file = implode(DIRECTORY_SEPARATOR, [
APP,
'config',
'nonuk-metadata.json',
));
]);
if (file_exists($nonuk_config_file)) {
$this->nonuk = json_decode(file_get_contents($nonuk_config_file), true);
}
Expand Down
44 changes: 22 additions & 22 deletions app/controllers/component.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class Component extends Controller
{
public function __construct($params = array())
public function __construct($params = [])
{
parent::__construct($params);
}
Expand All @@ -14,45 +14,45 @@ public function show()

public function render()
{
$m = new Mustache_Engine(array(
$m = new Mustache_Engine([
'partials_loader' => new Mustache_Loader_FilesystemLoader(
implode(
DIRECTORY_SEPARATOR,
array(
[
APP,
'views',
'findingaid',
)
]
)
),
));
]);

$pieces = explode('_', $this->params['id']);
$pieces = explode('_', (string) $this->params['id']);
$id = $pieces[0];
$component_id = $pieces[1];
$model = new ComponentModel($id, $component_id);

$container_list_template = load_template('findingaid/container_list');
$component_template = load_template('findingaid/component');

$container_lists = array();
$container_lists = [];
foreach ($model->container_lists() as $container_list) {
$container_list_content = $m->render(
$container_list_template,
$container_list
);
$container_lists[] = array(
$container_lists[] = [
'container_list' => $container_list_content,
);
];
}

$subcomponents = $model->subcomponents();
$subcomponent_content = array();
$subcomponent_content = [];
foreach ($model->subcomponents() as $subcomponent) {
$subcomponent_content[] = array(
$subcomponent_content[] = [
'subcomponent' => $m->render(
$component_template,
array(
[
'label' => fa_brevity($subcomponent->title()),
'collapsible' => true,
'bioghist_head' => $model->bioghistHead(),
Expand All @@ -61,14 +61,14 @@ public function render()
'scopecontent' => $subcomponent->scopecontent(),
'processinfo_head' => $model->processinfoHead(),
'processinfo' => $subcomponent->processinfo(),
)
]
),
);
];
}

$component_content = $m->render(
$component_template,
array(
[
'label' => fa_brevity($model->title()),
'collapsible' => true,
'container_lists' => $container_lists,
Expand All @@ -79,18 +79,18 @@ public function render()
'processinfo_head' => $model->processinfoHead(),
'processinfo' => $model->processinfo(),
'subcomponents' => $subcomponent_content,
)
]
);

return array(
return [
$component_content,
array(
[
'level' => (string)$model->level(),
'metadata' => array(
'metadata' => [
'label' => fa_brevity($model->title()),
'id' => 'demo_id',
),
),
);
],
],
];
}
}
Loading
Loading