Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# .github/workflows/deploy.yml
name: Deploy to AWS EC2

on:
push:
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, pdo, mysql, bcmath, opcache

- name: Install dependencies
working-directory: ./backend
run: composer install --no-interaction --prefer-dist

- name: Run tests
working-directory: ./backend
env:
APP_ENV: testing
DB_CONNECTION: sqlite
DB_DATABASE: ':memory:'
run: php artisan test

deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.AWS_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.AWS_HOST }} >> ~/.ssh/known_hosts

- name: Deploy backend
run: |
rsync -avz --delete \
--exclude='.env' \
--exclude='vendor/' \
--exclude='node_modules/' \
--exclude='.git/' \
--exclude='storage/logs/' \
--exclude='storage/framework/cache/data/' \
--exclude='storage/framework/sessions/' \
--exclude='storage/framework/views/' \
--exclude='bootstrap/cache/' \
./backend/ ${{ secrets.AWS_USER }}@${{ secrets.AWS_HOST }}:/var/www/backend/

- name: Post-deploy on server
run: |
ssh ${{ secrets.AWS_USER }}@${{ secrets.AWS_HOST }} << 'EOF'
cd /var/www/backend

# Install production dependencies
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev

# Run migrations
php artisan migrate --force

# Cache everything
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

# Optimize
php artisan optimize

# Fix permissions
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache

# Reload PHP-FPM
sudo systemctl reload php8.3-fpm
sudo systemctl reload nginx
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class InsufficientFundsException extends \Exception
{
protected $message = 'Niewystarczające środki na koncie.';
protected $message = 'Niewystarczająco środków na koncie.';

public function render(): JsonResponse
{
Expand Down
8 changes: 8 additions & 0 deletions backend/docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ server {

location / {
try_files $uri $uri/ /index.php?$query_string;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}

location = /favicon.ico { access_log off; log_not_found off; }
Expand Down
Loading