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
72 changes: 26 additions & 46 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,51 @@
name: Backend Deployment

on:
# Allows manual deployment
workflow_dispatch:
push:
# Triggers only when code is pushed to the development branch
# that modifies files in the API directory
branches:
- development
- deployment # production
- development # development

paths:
- 'API/**'

jobs:
build:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2' # Adjust PHP version as needed

- name: Create .env file
run: |
cd API
echo "${{ secrets.LARAVEL_ENV }}" > .env

- name: Install Composer dependencies
run: |
cd API
composer install --no-interaction --prefer-dist --optimize-autoloader
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push nginx image
run: |
cd API/docker/production
docker compose build nginx
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/mynginx:latest ${{ secrets.DOCKER_HUB_USERNAME }}/mynginx:latest
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/mynginx:latest

- name: Build and push app image
run: |
cd API/docker/production
docker compose build app
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:latest ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:latest
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/myapp:latest

- name: SSH and Deploy
uses: appleboy/ssh-action@master
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
debug: true
script: |
cd API
php artisan migrate
cd ${{ secrets.DOCKER_COMPOSE_DIRECTORY }}
docker-compose pull
docker-compose up -d
context: .
push: true
# If the branch is deployment, tag the image with prod (otherwise, tag it with dev)
tags: |
${{ secrets.IMAGE_NAME }}:${{ github.ref == 'refs/heads/deployment' && 'prod' || 'dev' }}

trigger-do-deployment:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Trigger DigitalOcean App Platform redeploy
# We have two apps, one for prod and one for dev
run: |
APP_ID=${{ github.ref == 'refs/heads/deployment' && secrets.DO_APP_ID_PROD || secrets.DO_APP_ID_DEV }}
curl -X POST "https://api.digitalocean.com/v2/apps/$APP_ID/deployments" \
-H "Authorization: Bearer ${{ secrets.DO_API_TOKEN }}"
48 changes: 48 additions & 0 deletions API/docker/production/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM php:8.2-apache

# Set working directory
WORKDIR /var/www/html

# Install system dependencies
RUN apt-get update && apt-get install -y \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libzip-dev \
--no-install-recommends \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql mbstring exif pcntl bcmath gd intl zip soap

# Enable Apache Rewrite module (required by Laravel)
RUN a2enmod rewrite

# Copy existing application directory contents
COPY . /var/www/html

# Copy existing application directory permissions
RUN chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html

# Set recommended PHP.ini settings
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini

# Set Laravel permissions
RUN chown -R www-data:www-data /var/www/html/

# Install Composer
COPY --from=composer:2.6 /usr/bin/composer /usr/bin/composer

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

# Expose Apache port
EXPOSE 80
1 change: 0 additions & 1 deletion API/docker/production/build.sh

This file was deleted.

29 changes: 0 additions & 29 deletions API/docker/production/docker-compose.yml

This file was deleted.

10 changes: 0 additions & 10 deletions API/docker/production/nginx/Dockerfile

This file was deleted.

34 changes: 0 additions & 34 deletions API/docker/production/nginx/conf.d/default.conf

This file was deleted.

5 changes: 0 additions & 5 deletions API/docker/production/nginx/snippets/fastcgi-php.conf

This file was deleted.

51 changes: 0 additions & 51 deletions API/docker/production/php/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion Frontend/shared/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
API_DOMAIN=api.speedcartapp.com
API_PORT=8443
API_PORT=80
TESTING_MODE=false
5 changes: 4 additions & 1 deletion Frontend/shared/src/hooks/AuthContext/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children

const login = (token: string) => {
const userInfo: GoogleToken = jwtDecode(JSON.parse(token).credential);
if (TESTING_MODE) {
console.log(`TESTING_MODE === true`);
}
// Initialize CSRF protection for the application

fetch(`${BASE_URL}/sanctum/csrf-cookie`, {
method: 'GET',
credentials: 'include', // Important: include credentials to allow the cookie to be set
credentials: TESTING_MODE ? 'omit' : 'include', // Important: include credentials to allow the cookie to be set
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Expand Down