Skip to content

Commit

Permalink
Set up crontab for certbot renew (#578)
Browse files Browse the repository at this point in the history
* Set up crontab for certbot renew

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
xepozz and StyleCIBot committed Mar 21, 2023
1 parent 20e27ab commit 3ba9cff
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 3 deletions.
20 changes: 20 additions & 0 deletions ansible/roles/certbot/tasks/update_certificates.yml
Expand Up @@ -16,3 +16,23 @@
args:
chdir: /home/deploy/demo.yiiframework.com
shell: docker-compose -f docker-compose.yml exec gateway nginx -t && docker-compose -f docker-compose.yml exec gateway nginx -s reload

# Crontab file location is /var/spool/cron/crontabs/deploy
# Every 2nd month on 15th day of month
# See https://crontab.guru/#0_0_15_*/2_*
- name: Set periodic certificates update
cron:
name: certbot-renew
user: deploy
minute: '0'
hour: '0'
day: '15'
month: '*/2'
job: >
/bin/bash -c "
cd /home/deploy/demo.yiiframework.com &&
docker-compose -f docker-compose.yml up certbot &&
sleep 180 &&
docker-compose -f docker-compose.yml exec -T gateway nginx -t &&
docker-compose -f docker-compose.yml exec -T gateway nginx -s reload
"
2 changes: 1 addition & 1 deletion blog-api/config/web/di/application.php
Expand Up @@ -14,7 +14,7 @@
Yiisoft\Yii\Http\Application::class => [
'__construct()' => [
'dispatcher' => DynamicReference::to(static function (Injector $injector) use ($params) {
return ($injector->make(MiddlewareDispatcher::class))
return $injector->make(MiddlewareDispatcher::class)
->withMiddlewares($params['middlewares']);
}),
'fallbackHandler' => Reference::to(NotFoundHandler::class),
Expand Down
13 changes: 13 additions & 0 deletions blog-api/src/Auth/AuthController.php
Expand Up @@ -42,13 +42,17 @@ public function __construct(
* path="/auth/",
* summary="Authenticate by params",
* description="",
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
Expand All @@ -58,15 +62,20 @@ public function __construct(
* },
* )
* ),
*
* @OA\Response(
* response="400",
* description="Bad request",
*
* @OA\JsonContent(ref="#/components/schemas/BadResponse")
* ),
*
* @OA\RequestBody(
* required=true,
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(ref="#/components/schemas/AuthRequest"),
* ),
* ),
Expand All @@ -93,14 +102,18 @@ public function login(AuthRequest $request): ResponseInterface
* summary="Logout",
* description="",
* security={{"ApiKey": {}}},
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(ref="#/components/schemas/Response")
* ),
*
* @OA\Response(
* response="400",
* description="Bad request",
*
* @OA\JsonContent(ref="#/components/schemas/BadResponse")
* ),
* )
Expand Down
1 change: 1 addition & 0 deletions blog-api/src/Auth/AuthRequest.php
Expand Up @@ -12,6 +12,7 @@
/**
* @OA\Schema(
* schema="AuthRequest",
*
* @OA\Property(example="Opal1144", property="login", format="string"),
* @OA\Property(example="Opal1144", property="password", format="string"),
* )
Expand Down
31 changes: 31 additions & 0 deletions blog-api/src/Blog/BlogController.php
Expand Up @@ -17,7 +17,9 @@
* name="blog",
* description="Blog"
* )
*
* @OA\Parameter(
*
* @OA\Schema(
* type="int",
* example="2"
Expand Down Expand Up @@ -55,22 +57,29 @@ public function __construct(
* path="/blog/",
* summary="Returns paginated blog posts",
* description="",
*
* @OA\Parameter(ref="#/components/parameters/PageRequest"),
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(
* property="posts",
* type="array",
*
* @OA\Items(ref="#/components/schemas/Post")
* ),
*
* @OA\Property(
* property="paginator",
* type="object",
Expand Down Expand Up @@ -105,19 +114,25 @@ public function index(PaginatorFormatter $paginatorFormatter, #[Query('page')] i
* path="/blog/{id}",
* summary="Returns a post with a given ID",
* description="",
*
* @OA\Parameter(
*
* @OA\Schema(type="int", example="2"),
* in="path",
* name="id",
* parameter="id"
* ),
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
Expand All @@ -131,13 +146,17 @@ public function index(PaginatorFormatter $paginatorFormatter, #[Query('page')] i
* },
* )
* ),
*
* @OA\Response(
* response="404",
* description="Not found",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/BadResponse"),
* @OA\Schema(
*
* @OA\Property(property="error_message", example="Entity not found"),
* @OA\Property(property="error_code", nullable=true, example=404)
* ),
Expand All @@ -164,17 +183,22 @@ public function view(#[Route('id')] int $id): Response
* summary="Creates a blog post",
* description="",
* security={{"ApiKey": {}}},
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* ref="#/components/schemas/Response"
* )
* ),
*
* @OA\RequestBody(
* required=true,
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(ref="#/components/schemas/EditPostRequest"),
* ),
* ),
Expand All @@ -197,23 +221,30 @@ public function create(EditPostRequest $postRequest, UserRequest $userRequest):
* summary="Updates a blog post with a given ID",
* description="",
* security={{"ApiKey": {}}},
*
* @OA\Parameter(
*
* @OA\Schema(type="int", example="2"),
* in="path",
* name="id",
* parameter="id"
* ),
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* ref="#/components/schemas/Response"
* )
* ),
*
* @OA\RequestBody(
* required=true,
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(ref="#/components/schemas/EditPostRequest"),
* ),
* )
Expand Down
1 change: 1 addition & 0 deletions blog-api/src/Blog/EditPostRequest.php
Expand Up @@ -14,6 +14,7 @@
/**
* @OA\Schema(
* schema="EditPostRequest",
*
* @OA\Property(example="Title post", property="title", format="string"),
* @OA\Property(example="Text post", property="text", format="string"),
* @OA\Property(example=1, property="status", format="int"),
Expand Down
1 change: 1 addition & 0 deletions blog-api/src/Blog/PostFormatter.php
Expand Up @@ -9,6 +9,7 @@
/**
* @OA\Schema(
* schema="Post",
*
* @OA\Property(example="100", property="id", format="int"),
* @OA\Property(example="Title", property="title", format="string"),
* @OA\Property(example="Text", property="content", format="string"),
Expand Down
1 change: 1 addition & 0 deletions blog-api/src/Dto/ApiResponseData.php
Expand Up @@ -15,6 +15,7 @@
* allOf={
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="status",
* example="failed",
Expand Down
1 change: 1 addition & 0 deletions blog-api/src/Formatter/PaginatorFormatter.php
Expand Up @@ -10,6 +10,7 @@
/**
* @OA\Schema(
* schema="Paginator",
*
* @OA\Property(example="10", property="pageSize", format="int"),
* @OA\Property(example="1", property="currentPage", format="int"),
* @OA\Property(example="3", property="totalPages", format="int"),
Expand Down
4 changes: 4 additions & 0 deletions blog-api/src/InfoController.php
Expand Up @@ -22,13 +22,17 @@ public function __construct(private VersionProvider $versionProvider)
* path="/",
* summary="Returns info about the API",
* description="",
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
Expand Down
11 changes: 11 additions & 0 deletions blog-api/src/User/UserController.php
Expand Up @@ -42,19 +42,24 @@ public function __construct(
* summary="Returns paginated users",
* description="",
* security={{"ApiKey": {}}},
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(
* property="users",
* type="array",
*
* @OA\Items(ref="#/components/schemas/User")
* ),
* ),
Expand Down Expand Up @@ -86,19 +91,25 @@ public function list(): ResponseInterface
* summary="Returns a user with a given ID",
* description="",
* security={{"ApiKey": {}}},
*
* @OA\Parameter(
*
* @OA\Schema(type="int", example="2"),
* in="path",
* name="id",
* parameter="id"
* ),
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
Expand Down
1 change: 1 addition & 0 deletions blog-api/src/User/UserFormatter.php
Expand Up @@ -9,6 +9,7 @@
/**
* @OA\Schema(
* schema="User",
*
* @OA\Property(example="UserName", property="login", format="string"),
* @OA\Property(example="13.12.2020 00:04:20", property="created_at", format="string"),
* )
Expand Down
4 changes: 2 additions & 2 deletions blog/config/common/routes/routes.php
Expand Up @@ -101,7 +101,7 @@
// Blog routes
Group::create('/blog')
->routes(
// Index
// Index
Route::get('[/page{page:\d+}]')
->middleware(
fn (HttpCache $httpCache, PostRepository $postRepository) => $httpCache->withLastModified(function (ServerRequestInterface $request, $params) use ($postRepository) {
Expand Down Expand Up @@ -144,7 +144,7 @@
// Archive
Group::create('/archive')
->routes(
// Index page
// Index page
Route::get('')
->action([ArchiveController::class, 'index'])
->name('blog/archive/index'),
Expand Down
1 change: 1 addition & 0 deletions blog/src/Controller/Actions/ApiInfo.php
Expand Up @@ -26,6 +26,7 @@ public function __construct(DataResponseFactoryInterface $responseFactory)
/**
* @OA\Get(
* path="/api/info/v2",
*
* @OA\Response(response="200", description="Get api version")
* )
*/
Expand Down
4 changes: 4 additions & 0 deletions blog/src/User/Controller/ApiUserController.php
Expand Up @@ -28,6 +28,7 @@ public function __construct(private DataResponseFactoryInterface $responseFactor
* @OA\Get(
* path="/api/user",
* tags={"user"},
*
* @OA\Response(response="200", description="Get users list")
* )
*/
Expand All @@ -52,12 +53,15 @@ public function index(UserRepository $userRepository): ResponseInterface
* @OA\Get(
* path="/api/user/{login}",
* tags={"user"},
*
* @OA\Parameter(
*
* @OA\Schema(type="string"),
* in="path",
* name="login",
* parameter="login"
* ),
*
* @OA\Response(response="200", description="Get user info")
* )
*/
Expand Down

0 comments on commit 3ba9cff

Please sign in to comment.