Skip to content

Commit

Permalink
Routing and Products Page
Browse files Browse the repository at this point in the history
  • Loading branch information
DChasmar committed Apr 3, 2024
2 parents cf6be67 + 3b5609e commit 1d1c76c
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 42 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build and Deploy Backend

on:
push:
branches:
- main

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

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

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

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

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

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: ./backend
push: true
tags: franciszekszeptycki/ecommerce-tbeitw:latest
deploy:
runs-on: ubuntu-latest
needs: build-and-push

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

- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Create SSH private key file
run: |
echo "$SSH_PRIVATE_KEY" > ./ssh-private-key
shell: bash

- name: Run deploy.sh
run: |
ssh -o StrictHostKeyChecking=no -i ./ssh-private-key ${{ secrets.USER }}@${{ secrets.HOST }} '~/deploy.sh'
shell: bash
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ venv
.idea
.env
__pycache__
db.sqlite3
db.sqlite3
docker-compose.yml
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
media/*
!media/placeholder.jpg
!media/hero-placeholder.jpg
static/*
static/*
.env.backup
14 changes: 14 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10

RUN useradd -m django-user
USER django-user

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .

HEALTHCHECK CMD curl --fail http://localhost:8000/admin/ || exit 1",
CMD ["./entrypoint.sh", "python", "-m", "gunicorn", "backend.wsgi:application", "-b", "0.0.0.0:8000"]
31 changes: 21 additions & 10 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import os
import dotenv


BASE_DIR = Path(__file__).resolve().parent.parent

dotenv.load_dotenv(BASE_DIR / '.env')

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down Expand Up @@ -79,16 +82,26 @@
'corsheaders',
]

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',

DATABASE_URL = os.environ.get('DATABASE_URL')

if DATABASE_URL:
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default=DATABASE_URL)
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


SECRET_KEY = 'django-insecure-b^%_b6zm_eo8+34mnt%!o8zjvg!ymon*q5^4*-v_k3e&g*@vq'
DEBUG = True
ALLOWED_HOSTS = []
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG = os.getenv('DEBUG', 'True').lower() != 'false'
ALLOWED_HOSTS = ["*"]

INSTALLED_APPS.insert(0, 'jazzmin')

Expand All @@ -98,8 +111,6 @@

APPEND_SLASH = True

dotenv.load_dotenv(BASE_DIR / '.env')

if not os.getenv('USE_S3'):
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'
Expand Down
6 changes: 6 additions & 0 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# python manage.py collectstatic --noinput
python manage.py migrate

exec "$@"
16 changes: 13 additions & 3 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
asgiref==3.8.1
boto3==1.34.74
botocore==1.34.74
dj-database-url==2.1.0
Django==5.0.3
django-cors-headers==4.3.1
django-dotenv==1.4.2
django-jazzmin==2.6.1
django-storages==1.14.2
djangorestframework==3.15.1
drf-yasg==1.21.7
gunicorn==21.2.0
inflection==0.5.1
jmespath==1.0.1
packaging==24.0
pillow==10.2.0
psycopg2-binary==2.9.9
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
pytz==2024.1
PyYAML==6.0.1
s3transfer==0.10.1
six==1.16.0
sqlparse==0.4.4
typing_extensions==4.10.0
uritemplate==4.1.1

pip~=22.0.2
setuptools~=59.6.0
urllib3==2.2.1
5 changes: 4 additions & 1 deletion backend/store/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
admin.site.unregister(User)
admin.site.unregister(Group)

admin.site.register(Product)
admin.site.register([Product, ProductGallery])


class WebsiteConfigAdmin(admin.ModelAdmin):
fieldsets = (
('Hero', {
'fields': ('hero_title', 'hero_subtitle', 'hero_image',),
}),
('Slider', {
'fields': ('slider_images',),
}),
)

def _remove_actions(self, extra_context):
Expand Down
18 changes: 18 additions & 0 deletions backend/store/migrations/0005_websiteconfig_slider_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-04-03 18:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('store', '0004_websiteconfig_delete_heroconfig'),
]

operations = [
migrations.AddField(
model_name='websiteconfig',
name='slider_images',
field=models.ManyToManyField(related_name='sliders', to='store.productgallery'),
),
]
4 changes: 3 additions & 1 deletion backend/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __str__(self):
return self.image.url

class Meta:
verbose_name_plural = 'Product Galleries'
verbose_name_plural = 'Product gallery'


class Product(models.Model):
Expand All @@ -34,6 +34,8 @@ class WebsiteConfig(models.Model):
hero_subtitle = models.CharField(max_length=255)
hero_image = models.ImageField(upload_to='hero/', default=DEFAULT_IMG_PATH)

slider_images = models.ManyToManyField('ProductGallery', related_name='sliders')

def __str__(self):
return "Website configuration"

Expand Down
4 changes: 3 additions & 1 deletion backend/store/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ProductGallerySerializer(serializers.ModelSerializer):
class Meta:
model = ProductGallery
fields = ['image', 'created_at', 'updated_at']
fields = ['image']


class ProductSerializer(serializers.ModelSerializer):
Expand All @@ -23,6 +23,8 @@ class Meta:


class WebsiteConfigSerializer(serializers.ModelSerializer):
slider_images = ProductGallerySerializer(many=True, read_only=True)

class Meta:
model = WebsiteConfig
fields = '__all__'
24 changes: 0 additions & 24 deletions setup_backend.sh

This file was deleted.

0 comments on commit 1d1c76c

Please sign in to comment.