Skip to content

Commit 1e68ea0

Browse files
authored
Merge pull request #11 from uklibraries/ci-publish
Ci and publish
2 parents bb01a98 + 96bcce2 commit 1e68ea0

24 files changed

+2319
-247
lines changed

.github/workflows/ci.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches: [ "dev" ]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
env:
10+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.override.yml
11+
COMPOSE_PROJECT_NAME: ci-${{ github.job }}-${{ github.run_id }}
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Build services
16+
run: docker compose build
17+
18+
- name: Show service logs if failed
19+
if: failure()
20+
run: docker compose logs
21+
22+
- name: Container runs
23+
run: docker compose run --rm --no-deps -T findingaid php -v
24+
25+
- name: Teardown
26+
if: always()
27+
run: docker compose down -v --remove-orphans
28+
29+
lint:
30+
needs: build
31+
runs-on: ubuntu-latest
32+
# TODO: Fix the linting errors
33+
# Report the failure, but don't stop the job
34+
continue-on-error: true
35+
env:
36+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.override.yml
37+
COMPOSE_PROJECT_NAME: ci-${{ github.job }}-${{ github.run_id }}
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Build services
42+
run: docker compose build
43+
44+
- name: Show service logs if failed
45+
if: failure()
46+
run: docker compose logs
47+
48+
- name: Run linting inside app container
49+
run: docker compose run --rm -T findingaid /vendor/bin/phpcs -w --exclude=Generic.Files.LineLength --standard=PSR12 /tests /app
50+
51+
- name: Teardown
52+
if: always()
53+
run: docker compose down -v --remove-orphans
54+
55+
unit-test:
56+
needs: build
57+
runs-on: ubuntu-latest
58+
env:
59+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.override.yml
60+
COMPOSE_PROJECT_NAME: ci-${{ github.job }}-${{ github.run_id }}
61+
steps:
62+
- uses: actions/checkout@v4
63+
64+
- name: Build services
65+
run: docker compose build
66+
67+
- name: Start services
68+
run: docker compose up -d findingaid
69+
70+
- name: Show service logs if failed
71+
if: failure()
72+
run: docker compose logs
73+
74+
- name: Run tests inside app container
75+
run: docker compose run --rm -T findingaid /vendor/bin/phpunit -c /phpunit.xml /tests
76+
77+
- name: Teardown
78+
if: always()
79+
run: docker compose down -v --remove-orphans

.github/workflows/publish.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish release
2+
on:
3+
push: [dev]
4+
5+
permissions:
6+
contents: read
7+
packages: write
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
ref: ${{ github.sha }}
16+
17+
- uses: docker/setup-buildx-action@v3
18+
19+
- name: Login to GitHub Container Registry (ghcr)
20+
uses: docker/login-action@v3
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Build and push
27+
uses: docker/build-push-action@v6
28+
with:
29+
context: .
30+
push: true
31+
tags: |
32+
ghcr.io/${{ github.repository_owner }}/findingaid:${{ github.sha }}
33+
labels: |
34+
org.opencontainers.image.revision=${{ github.sha }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ misc/
88
public/minimal*
99
public/cache
1010
is_prod
11+
.phpunit.result.cache

dockerfile renamed to Dockerfile

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN git clone https://github.com/douglascrockford/JSMin /tmp/jsmin && \
99
gcc /tmp/jsmin/jsmin.c -o /usr/bin/jsmin && \
1010
rm -rf /tmp/jsmin
1111

12-
FROM php:8.0-fpm-alpine AS development
12+
FROM php:8.3-fpm-alpine AS development
1313

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

38-
FROM php:8.0-fpm-alpine AS prod-builder
38+
FROM php:8.3-fpm-alpine AS prod-builder
3939

4040
RUN apk add --no-cache bash
4141

4242
COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer
4343
COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin
4444

45+
WORKDIR /app
46+
COPY ./composer.json .
47+
COPY ./composer.lock .
48+
49+
RUN composer install --no-interaction --no-dev
50+
51+
COPY ./app .
52+
53+
FROM php:8.3-fpm-alpine as CI
54+
55+
RUN apk add --no-cache \
56+
libzip-dev \
57+
bash
58+
4559
WORKDIR /app
4660

47-
COPY . .
61+
COPY --from=jsmin /usr/bin/jsmin /usr/bin/jsmin
62+
COPY --from=prod-builder /app .
63+
COPY --from=development /vendor /vendor
64+
COPY ./phpunit.xml /phpunit.xml
65+
66+
COPY exe/build.sh /exe/build.sh
67+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
68+
RUN chmod +x /usr/local/bin/entrypoint.sh
69+
70+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
71+
EXPOSE 9000
72+
CMD ["php-fpm", "-F"]
4873

49-
FROM php:8.0-fpm-alpine AS production
74+
FROM php:8.3-fpm-alpine AS production
5075

5176
WORKDIR /app
5277

5378
COPY --from=prod-builder /app .
79+
COPY --from=prod-builder /vendor /vendor
5480

5581
COPY exe/build.sh /exe/build.sh
5682
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

app/config/config.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?php
22
class Config
33
{
4-
private $config = array();
5-
private $repo = array();
4+
private $config = [];
5+
private $repo = [];
66
private $nonuk = null;
77

88
public function __construct()
99
{
10-
$config_file = implode(DIRECTORY_SEPARATOR, array(
10+
$config_file = implode(DIRECTORY_SEPARATOR, [
1111
APP,
1212
'config',
1313
'config.json',
14-
));
14+
]);
1515
if (file_exists($config_file)) {
1616
$this->config = json_decode(file_get_contents($config_file), true);
1717
}
18-
$repo_file = implode(DIRECTORY_SEPARATOR, array(
18+
$repo_file = implode(DIRECTORY_SEPARATOR, [
1919
APP,
2020
'config',
2121
'repo.json',
22-
));
22+
]);
2323
if (file_exists($repo_file)) {
2424
$this->repo = json_decode(file_get_contents($repo_file), true);
2525
}
@@ -48,11 +48,11 @@ public function get_repo($key)
4848
public function get_nonuk($key)
4949
{
5050
if (!isset($this->nonuk)) {
51-
$nonuk_config_file = implode(DIRECTORY_SEPARATOR, array(
51+
$nonuk_config_file = implode(DIRECTORY_SEPARATOR, [
5252
APP,
5353
'config',
5454
'nonuk-metadata.json',
55-
));
55+
]);
5656
if (file_exists($nonuk_config_file)) {
5757
$this->nonuk = json_decode(file_get_contents($nonuk_config_file), true);
5858
}

app/controllers/component.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
class Component extends Controller
33
{
4-
public function __construct($params = array())
4+
public function __construct($params = [])
55
{
66
parent::__construct($params);
77
}
@@ -14,45 +14,45 @@ public function show()
1414

1515
public function render()
1616
{
17-
$m = new Mustache_Engine(array(
17+
$m = new Mustache_Engine([
1818
'partials_loader' => new Mustache_Loader_FilesystemLoader(
1919
implode(
2020
DIRECTORY_SEPARATOR,
21-
array(
21+
[
2222
APP,
2323
'views',
2424
'findingaid',
25-
)
25+
]
2626
)
2727
),
28-
));
28+
]);
2929

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

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

38-
$container_lists = array();
38+
$container_lists = [];
3939
foreach ($model->container_lists() as $container_list) {
4040
$container_list_content = $m->render(
4141
$container_list_template,
4242
$container_list
4343
);
44-
$container_lists[] = array(
44+
$container_lists[] = [
4545
'container_list' => $container_list_content,
46-
);
46+
];
4747
}
4848

4949
$subcomponents = $model->subcomponents();
50-
$subcomponent_content = array();
50+
$subcomponent_content = [];
5151
foreach ($model->subcomponents() as $subcomponent) {
52-
$subcomponent_content[] = array(
52+
$subcomponent_content[] = [
5353
'subcomponent' => $m->render(
5454
$component_template,
55-
array(
55+
[
5656
'label' => fa_brevity($subcomponent->title()),
5757
'collapsible' => true,
5858
'bioghist_head' => $model->bioghistHead(),
@@ -61,14 +61,14 @@ public function render()
6161
'scopecontent' => $subcomponent->scopecontent(),
6262
'processinfo_head' => $model->processinfoHead(),
6363
'processinfo' => $subcomponent->processinfo(),
64-
)
64+
]
6565
),
66-
);
66+
];
6767
}
6868

6969
$component_content = $m->render(
7070
$component_template,
71-
array(
71+
[
7272
'label' => fa_brevity($model->title()),
7373
'collapsible' => true,
7474
'container_lists' => $container_lists,
@@ -79,18 +79,18 @@ public function render()
7979
'processinfo_head' => $model->processinfoHead(),
8080
'processinfo' => $model->processinfo(),
8181
'subcomponents' => $subcomponent_content,
82-
)
82+
]
8383
);
8484

85-
return array(
85+
return [
8686
$component_content,
87-
array(
87+
[
8888
'level' => (string)$model->level(),
89-
'metadata' => array(
89+
'metadata' => [
9090
'label' => fa_brevity($model->title()),
9191
'id' => 'demo_id',
92-
),
93-
),
94-
);
92+
],
93+
],
94+
];
9595
}
9696
}

0 commit comments

Comments
 (0)