Skip to content

Commit b7cbb42

Browse files
committed
docker-publisher action update
1 parent b82d5ee commit b7cbb42

13 files changed

Lines changed: 49 additions & 62 deletions

.docker/Dockerfile.prod

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ RUN apt-get update && apt-get install -y \
1313
git \
1414
npm
1515

16-
# install composer
17-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
18-
1916
# install PHP extensions
2017
RUN docker-php-ext-install pdo_mysql pdo intl
2118

@@ -30,14 +27,3 @@ COPY . /var/www/
3027
# setup environment config
3128
RUN sed -i 's/^\(APP_ENV=\)dev/\1prod/' .env
3229
RUN cp .env.dev .env.prod
33-
34-
# install app dependencies
35-
RUN composer install --no-interaction --no-progress
36-
RUN npm install --loglevel=error
37-
38-
# build frontend assets
39-
RUN npm run build
40-
41-
# set storage permissions
42-
RUN chmod -R 777 var/
43-
RUN chown -R www-data:www-data var/

.github/workflows/docker-publisher.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# action to build and push docker image on release
2-
name: Build and push Docker image on release
1+
# publisher for building and publishing docker image to github packages container registry
2+
name: Publish Docker Image
33

44
on:
55
release:
@@ -9,18 +9,37 @@ on:
99
jobs:
1010
build-and-publish:
1111
runs-on: ubuntu-latest
12+
1213
steps:
1314
- name: Checkout repository
1415
uses: actions/checkout@v3
1516

16-
# login to github container registry
17+
# login to container registry
1718
- name: Log in to GitHub Container Registry
1819
uses: docker/login-action@v2
1920
with:
2021
registry: ghcr.io
2122
username: ${{ github.actor }}
2223
password: ${{ secrets.GITHUB_TOKEN }}
2324

25+
# setup php interpreter for composer
26+
- name: Setup PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: 8.4
30+
31+
# install composer dependencies
32+
- name: Install backend dependencies
33+
run: composer install --ignore-platform-reqs --no-interaction --no-progress
34+
35+
# install frontend dependencies with npm
36+
- name: Install frontend dependencies
37+
run: npm install --loglevel=error
38+
39+
# build frontend assets
40+
- name: Build assets
41+
run: npm run build
42+
2443
# build and push docker image
2544
- name: Build and push docker image
2645
uses: docker/build-push-action@v4

src/Controller/PasteController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ public function save(Request $request): Response
6161
return $this->json([
6262
'code' => Response::HTTP_OK,
6363
'status' => 'success',
64-
'message' => 'Paste saved successfully',
64+
'message' => 'Paste saved successfully'
6565
], Response::HTTP_OK);
6666
} catch (Exception $e) {
6767
return $this->json([
6868
'code' => Response::HTTP_BAD_REQUEST,
6969
'status' => 'error',
70-
'message' => 'Error to save paste: ' . $e->getMessage(),
70+
'message' => 'Error to save paste: ' . $e->getMessage()
7171
], Response::HTTP_BAD_REQUEST);
7272
}
7373
}
@@ -90,7 +90,7 @@ public function view(Request $request): Response
9090

9191
// return paste view
9292
return $this->render('view.twig', [
93-
'paste' => $paste,
93+
'paste' => $paste
9494
]);
9595
}
9696

src/Repository/PasteRepository.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public function __construct(ManagerRegistry $registry)
3333
*/
3434
public function getPasteByToken(string $token): ?Paste
3535
{
36-
$query = $this->createQueryBuilder('u')
37-
->where('u.token = :token')
38-
->setParameter('token', $token)
39-
->getQuery();
36+
$query = $this->createQueryBuilder('u')->where('u.token = :token')->setParameter('token', $token)->getQuery();
4037

4138
/** @var Paste|null $result */
4239
$result = $query->getOneOrNullResult();

src/Util/AppUtil.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public function getAppRootDir(): string
6262
public function isSsl(): bool
6363
{
6464
// check if HTTPS header is set and its value is either 1 or 'on'
65-
return isset($_SERVER['HTTPS']) &&
66-
($_SERVER['HTTPS'] == 1 || strtolower($_SERVER['HTTPS']) === 'on');
65+
return isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 1 || strtolower($_SERVER['HTTPS']) === 'on');
6766
}
6867

6968
/**

tests/Command/ToggleMaintenanceCommandTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ public function testExecuteWithValidMode(): void
115115
public function testExecuteThrowsException(): void
116116
{
117117
// mock update env value
118-
$this->appUtil->method('updateEnvValue')
119-
->willThrowException(new Exception('Something went wrong'));
118+
$this->appUtil->method('updateEnvValue')->willThrowException(
119+
new Exception('Something went wrong')
120+
);
120121

121122
// execute command
122123
$exitCode = $this->commandTester->execute(['mode' => 'true']);

tests/Controller/PasteControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testSaveEmptyPaste(): void
4646
{
4747
$this->client->request('POST', '/save', [
4848
'paste-content' => '',
49-
'token' => ByteString::fromRandom(16),
49+
'token' => ByteString::fromRandom(16)
5050
]);
5151

5252
// assert response
@@ -62,7 +62,7 @@ public function testSaveNewPasteSuccess(): void
6262
{
6363
$this->client->request('POST', '/save', [
6464
'paste-content' => 'test content',
65-
'token' => ByteString::fromRandom(16),
65+
'token' => ByteString::fromRandom(16)
6666
]);
6767

6868
// assert response

tests/Manager/PasteManagerTest.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,12 @@ public function testSavePasteWithSuccessResponse(): void
7171
$this->appUtilMock->method('getHttpHost')->willReturn('localhost');
7272

7373
// expect entity manager to call persist and flush
74-
$this->entityManagerMock->expects($this->once())
75-
->method('persist')
74+
$this->entityManagerMock->expects($this->once())->method('persist')
7675
->with($this->isInstanceOf(Paste::class));
77-
$this->entityManagerMock->expects($this->once())
78-
->method('flush');
76+
$this->entityManagerMock->expects($this->once())->method('flush');
7977

8078
// expect log manager to be called upon successful save
81-
$this->logManagerMock->expects($this->once())
82-
->method('externalLog');
79+
$this->logManagerMock->expects($this->once())->method('externalLog');
8380

8481
// call tested method
8582
$this->pasteManager->savePaste('sample-token', 'This is a test paste.');
@@ -98,8 +95,7 @@ public function testSavePasteWithEmptyContent(): void
9895
$this->appUtilMock->method('isEncryptionMode')->willReturn(false);
9996

10097
// expect error manager call
101-
$this->errorManagerMock->expects($this->once())
102-
->method('handleError')
98+
$this->errorManagerMock->expects($this->once())->method('handleError')
10399
->with('paste content is empty', Response::HTTP_BAD_REQUEST);
104100

105101
// call tested method
@@ -119,8 +115,7 @@ public function testSavePasteWithLongContent(): void
119115
$this->appUtilMock->method('isEncryptionMode')->willReturn(false);
120116

121117
// expect error manager call
122-
$this->errorManagerMock->expects($this->once())
123-
->method('handleError')
118+
$this->errorManagerMock->expects($this->once())->method('handleError')
124119
->with('paste content is too long', Response::HTTP_BAD_REQUEST);
125120

126121
// call tested method

tests/Middleware/DatabaseOnlineMiddlewareTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ protected function setUp(): void
3030
$this->doctrineConnectionMock = $this->createMock(Connection::class);
3131

3232
// create database online middleware instance
33-
$this->middleware = new DatabaseOnlineMiddleware(
34-
$this->errorManagerMock,
35-
$this->doctrineConnectionMock
36-
);
33+
$this->middleware = new DatabaseOnlineMiddleware($this->errorManagerMock, $this->doctrineConnectionMock);
3734
}
3835

3936
/**
@@ -62,8 +59,9 @@ public function testDatabaseConnectionFailure(): void
6259
{
6360
// mock database connection failure
6461
$exceptionMessage = 'Connection refused';
65-
$this->doctrineConnectionMock->expects($this->once())
66-
->method('executeQuery')->with('SELECT 1')->willThrowException(new Exception($exceptionMessage));
62+
$this->doctrineConnectionMock->expects($this->once())->method('executeQuery')->with('SELECT 1')->willThrowException(
63+
new Exception($exceptionMessage)
64+
);
6765

6866
// expect error manager to be called
6967
$this->errorManagerMock->expects($this->once())->method('handleError')->with(

tests/Middleware/EscapeRequestDataMiddlewareTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public function testEscapeRequestData(): void
4949
/** @var HttpKernelInterface&MockObject $kernel */
5050
$kernel = $this->createMock(HttpKernelInterface::class);
5151
/** @var Request $request */
52-
$event = new RequestEvent(
53-
$kernel,
54-
$request,
55-
HttpKernelInterface::MAIN_REQUEST
56-
);
52+
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST);
5753

5854
// call tested method
5955
$middleware = new EscapeRequestDataMiddleware($securityUtil);

0 commit comments

Comments
 (0)