diff --git a/.github/workflows/test-and-publish.yml b/.github/workflows/test-and-publish.yml new file mode 100644 index 0000000..021bbaf --- /dev/null +++ b/.github/workflows/test-and-publish.yml @@ -0,0 +1,43 @@ +name: Test and Publish + +on: + push: + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run unit tests + run: docker-compose -f actions-services.yml run --rm app ./run-tests.sh + - name: Run API tests + run: docker-compose -f actions-services.yml run --rm app ./run-tests-api.sh + - name: Check PSR2 + run: docker-compose -f actions-services.yml run --rm app ./check-psr2.sh + + build-and-publish: + name: Build and Publish + needs: [unit-tests,api-tests,psr2-check] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ vars.DOCKER_ORG }}/email-service + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/actions-services.yml b/actions-services.yml new file mode 100644 index 0000000..dfcc7df --- /dev/null +++ b/actions-services.yml @@ -0,0 +1,28 @@ +version: '2' +services: + db: + image: mariadb:10 + environment: + MYSQL_ROOT_PASSWORD: r00tp@ss! + MYSQL_DATABASE: test + MYSQL_USER: email + MYSQL_PASSWORD: email + + app: + build: . + depends_on: + - db + working_dir: /data + environment: + APP_ENV: test + MYSQL_HOST: db + MYSQL_DATABASE: test + MYSQL_USER: email + MYSQL_PASSWORD: email + API_ACCESS_KEYS: abc123 + APP_NAME: email-service + MAILER_HOST: test + MAILER_USERNAME: test + MAILER_PASSWORD: test + NOTIFICATION_EMAIL: test@test.com + FROM_EMAIL: test@test.com diff --git a/application/common/config/main.php b/application/common/config/main.php index aefd793..58343b0 100644 --- a/application/common/config/main.php +++ b/application/common/config/main.php @@ -72,6 +72,17 @@ ], [ 'class' => EmailTarget::class, + 'except' => [ + 'yii\web\HttpException:400', + 'yii\web\HttpException:401', + 'yii\web\HttpException:403', + 'yii\web\HttpException:404', + 'yii\web\HttpException:409', + 'yii\web\HttpException:410', + 'yii\web\HttpException:422', + 'yii\web\HttpException:429', + 'yii\web\HttpException:503', + ], 'categories' => ['application'], // stick to messages from this app, not all of Yii's built-in messaging. 'logVars' => [], // no need for default stuff: http://www.yiiframework.com/doc-2.0/yii-log-target.html#$logVars-detail 'levels' => ['error'], diff --git a/application/frontend/controllers/SiteController.php b/application/frontend/controllers/SiteController.php index f5e11ca..d91019e 100644 --- a/application/frontend/controllers/SiteController.php +++ b/application/frontend/controllers/SiteController.php @@ -6,10 +6,12 @@ use Yii; use yii\rest\Controller; use yii\web\NotFoundHttpException; -use yii\web\ServerErrorHttpException; +use yii\web\HttpException; class SiteController extends Controller { + public const HttpExceptionServiceUnavailable = 503; + public function behaviors() { $behaviors = parent::behaviors(); @@ -29,7 +31,8 @@ public function actionStatus() Yii::$app->db->open(); } catch (Exception $e) { \Yii::error($e->getMessage()); - throw new ServerErrorHttpException( + throw new HttpException( + self::HttpExceptionServiceUnavailable, 'Database connection problem.', $e->getCode() ); diff --git a/codeship-services.yml b/codeship-services.yml deleted file mode 100644 index da054bc..0000000 --- a/codeship-services.yml +++ /dev/null @@ -1,30 +0,0 @@ -db: - image: mariadb:10 - environment: - MYSQL_ROOT_PASSWORD: r00tp@ss! - MYSQL_DATABASE: test - MYSQL_USER: email - MYSQL_PASSWORD: email - -app: - build: - image: silintl/email-service - dockerfile_path: ./Dockerfile - cached: true - links: - - db - working_dir: /data - command: /data/run-tests.sh - environment: - APP_ENV: test - MYSQL_HOST: db - MYSQL_DATABASE: test - MYSQL_USER: email - MYSQL_PASSWORD: email - API_ACCESS_KEYS: abc123 - APP_NAME: email-service - MAILER_HOST: test - MAILER_USERNAME: test - MAILER_PASSWORD: test - NOTIFICATION_EMAIL: test@test.com - FROM_EMAIL: test@test.com diff --git a/codeship-steps.yml b/codeship-steps.yml deleted file mode 100644 index 61c865f..0000000 --- a/codeship-steps.yml +++ /dev/null @@ -1,30 +0,0 @@ - -- type: parallel - steps: - - name: unit test - service: app - command: whenavail db 3306 100 /data/run-tests.sh - - name: api test - service: app - command: whenavail db 3306 100 /data/run-tests-api.sh - - name: check_psr2 - service: app - command: /data/check-psr2.sh - -- name: push - service: app - type: push - image_name: silintl/email-service - image_tag: "{{.Branch}}" - exclude: main - registry: https://index.docker.io/v1/ - encrypted_dockercfg_path: dockercfg.encrypted - -- name: push_latest - service: app - type: push - image_name: silintl/email-service - image_tag: "latest" - tag: main - registry: https://index.docker.io/v1/ - encrypted_dockercfg_path: dockercfg.encrypted diff --git a/dockercfg.encrypted b/dockercfg.encrypted deleted file mode 100644 index 8f02c34..0000000 --- a/dockercfg.encrypted +++ /dev/null @@ -1,2 +0,0 @@ -codeship:v2 -VlUkVRmcLlulmam1KEV1a1OJXhyDA8Y5+KEh01iZnv6ND30I10C6VzivTjvBM7UrzJcMaTEP0PUE5nAHbQXc2q4QnyP+94JDcPLJjqydx7qlNe94/Og8A/0lRnAumlddPbbJmRj3bjMloU3lU/G4COViCy5JHTzvVRSjdrmnGpULjP0hriqwQ4HrrL8TRWJ6bbiR65MZ/ZiG3t9vugIpjMcOo8iFVNq15MksHSpM7MJUjLyyYGV1I58S9OwzLl45xIgFIWPF6DfhfJLbev2/Cm7aGE31FOwvOlrit9J/+Yxjyy/+UyedGnM2AiyN \ No newline at end of file