Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Apr 24, 2022
2 parents b83d45d + 25aa57d commit c2ee0de
Show file tree
Hide file tree
Showing 38 changed files with 1,368 additions and 1,464 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
35 changes: 14 additions & 21 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# shamelessly copied from https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio
# modified to meet our needs
name: "Docker Image"

on:
push:
branches:
- develop
- release
tags:
- v*

Expand All @@ -27,35 +22,33 @@ jobs:
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
[ "$VERSION" == "main" ] && VERSION=main
docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${{ github.run_number }}" \
--label "org.opencontainers.image.title=The Traewelling container image" \
echo "$VERSION" > VERSION
docker build . --file Dockerfile \
--tag traewelling:$VERSION \
--tag traewelling:latest \
--label "runnumber=${{ github.run_number }}" \
--label "org.opencontainers.image.title=Traewelling" \
--label "org.opencontainers.image.version=$VERSION" \
--label "org.opencontainers.image.description=Easy-to-use deployment image of the Traewelling project" \
--label "org.opencontainers.image.url=https://github.com/Traewelling/traewelling#readme" \
--label "org.opencontainers.image.source=https://github.com/Traewelling/traewelling.git" \
--label "org.opencontainers.image.authors=Jonas Möller <[email protected]>" \
--label "org.opencontainers.image.vendor=The Traewelling team <[email protected]>" \
--label "org.opencontainers.image.license=AGPL-3.0" \
--label "org.opencontainers.image.base.name=docker.io/library/php:8-apache"
--label "org.opencontainers.image.vendor=The Traewelling team <[email protected]>" \
--label "org.opencontainers.image.license=AGPL-3.0"
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "release" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:latest
4 changes: 3 additions & 1 deletion .github/workflows/nodejs-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [ 16.x, 17.x ]
node-version: [ 17.x, 18.x ]

steps:
- uses: actions/checkout@v1
Expand All @@ -21,6 +21,8 @@ jobs:
run: npm install
- name: Run production build
run: npm run production
- name: Check for vulnerabilities
run: npm audit

env:
CI: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
vendor/
node_modules/
npm-debug.log
report/
tests-coverage/
clover.xml

# Profile pictures
Expand Down
15 changes: 15 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/trwl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
FROM node:16-alpine as NodeBuildContainer
FROM node:18-alpine as NodeBuildContainer
COPY . /usr/src/trwl
WORKDIR /usr/src/trwl
RUN npm i && npm run prod

FROM composer:2 as ComposerBuildContainer
COPY --from=NodeBuildContainer /usr/src/trwl /usr/src/trwl
WORKDIR /usr/src/trwl
RUN composer install --ignore-platform-reqs
RUN composer install --ignore-platform-reqs --no-interaction --no-dev --no-progress --no-suggest --optimize-autoloader

FROM php:8.1-apache
RUN apt update && apt install -y zlib1g-dev libpng-dev wait-for-it
RUN docker-php-ext-install gd exif pdo pdo_mysql
RUN a2enmod rewrite
FROM php:8.1.5-apache
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

RUN apt update && \
apt upgrade -y && \
apt install -y zlib1g-dev libpng-dev wait-for-it && \
docker-php-ext-install gd exif pdo pdo_mysql && \
a2enmod rewrite && \
a2enmod http2 && \
sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf && \
sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

COPY --from=ComposerBuildContainer --chown=www-data:www-data /usr/src/trwl /var/www/html

ENTRYPOINT ["/var/www/html/docker-entrypoint.sh"]
CMD ["apache2-foreground"]
14 changes: 14 additions & 0 deletions app/Enum/HafasTravelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,18 @@ enum HafasTravelType: string
case SUBWAY = 'subway';
case TRAM = 'tram';
case TAXI = 'taxi';

public function getEmoji(): string {
return match ($this->value) {
'nationalExpress', 'national' => '🚄',
'regionalExp', 'regional' => '🚆',
'suburban' => '🚋',
'bus' => '🚌',
'ferry' => '',
'subway' => '🚇',
'tram' => '🚊',
'taxi' => '🚖',
default => '',
};
}
}
9 changes: 9 additions & 0 deletions app/Exceptions/Checkin/AlreadyCheckedInException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Exceptions\Checkin;

use Exception;

class AlreadyCheckedInException extends Exception
{
}
10 changes: 0 additions & 10 deletions app/Exceptions/IdenticalModelException.php

This file was deleted.

3 changes: 3 additions & 0 deletions app/Http/Controllers/API/TransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\API;

use App\Enum\TravelType;
use App\Exceptions\Checkin\AlreadyCheckedInException;
use App\Exceptions\CheckInCollisionException;
use App\Exceptions\HafasException;
use App\Exceptions\StationNotOnTripException;
Expand Down Expand Up @@ -182,6 +183,8 @@ public function TrainCheckin(Request $request) {
} catch (StationNotOnTripException $exception) {
report($exception);
return $this->sendError('Given stations are not on the trip.', 400);
} catch (AlreadyCheckedInException) {
return $this->sendError(__('messages.exception.already-checkedin', [], 'en'), 400);
} catch (Throwable $exception) {
report($exception);
return $this->sendError('Unknown Error occurred', 500);
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/API/v1/FollowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
namespace App\Http\Controllers\API\v1;

use App\Exceptions\AlreadyFollowingException;
use App\Exceptions\IdenticalModelException;
use App\Exceptions\PermissionException;
use App\Http\Controllers\API\ResponseController;
use App\Http\Controllers\Backend\User\FollowController as FollowBackend;
use App\Http\Controllers\Backend\User\FollowController as SettingsBackend;
use App\Http\Controllers\UserController as UserBackend;
use App\Http\Resources\UserResource;
use App\Models\Follow;
Expand All @@ -18,6 +16,7 @@
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
use InvalidArgumentException;

class FollowController extends ResponseController
{
Expand All @@ -30,7 +29,7 @@ public static function createFollow(Request $request, FollowController $instance
$createFollowResponse = UserBackend::createOrRequestFollow(Auth::user(), $userToFollow);
} catch (AlreadyFollowingException) {
return $instance->sendv1Error(['message' => __('controller.user.follow-error')], 409);
} catch (IdenticalModelException) {
} catch (InvalidArgumentException) {
abort(409);
}

Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/API/v1/TransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enum\Business;
use App\Enum\StatusVisibility;
use App\Enum\TravelType;
use App\Exceptions\Checkin\AlreadyCheckedInException;
use App\Exceptions\CheckInCollisionException;
use App\Exceptions\HafasException;
use App\Exceptions\StationNotOnTripException;
Expand Down Expand Up @@ -155,6 +156,8 @@ public function create(Request $request): JsonResponse {
return $this->sendv1Error('Given stations are not on the trip/have wrong departure/arrival.', 400);
} catch (HafasException $exception) {
return $this->sendv1Error($exception->getMessage(), 400);
} catch (AlreadyCheckedInException) {
return $this->sendv1Error(__('messages.exception.already-checkedin', [], 'en'), 400);
} catch (TrainCheckinAlreadyExistException) {
return $this->sendv1Error('CheckIn already exists', 409);
}
Expand Down
Loading

0 comments on commit c2ee0de

Please sign in to comment.