Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9 continuous deployment #20

Merged
merged 62 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
673b252
projects with connection test (no docker)
robinpdev Feb 20, 2024
b8553c0
move django folder up in hierarchy
robinpdev Feb 20, 2024
16f3d02
dockerized boilerplate
robinpdev Feb 20, 2024
2748e89
fix pycache in gitignore
robinpdev Feb 20, 2024
627f6db
rename backend and frontend
axellorreyne Feb 20, 2024
a46c76b
fix db env file in compose
axellorreyne Feb 20, 2024
7a31673
fix and sort requirements
axellorreyne Feb 20, 2024
c376062
cleanup compose
axellorreyne Feb 20, 2024
563c307
fix gitignore
axellorreyne Feb 20, 2024
6103497
update team setup
axellorreyne Feb 20, 2024
ad241de
Merge pull request #12 from SELab-2/7-boiler-plate-+-documentation-wiki
robinpdev Feb 20, 2024
3612769
linting instellen voor backend (frontend was al klaar)
robinpdev Feb 21, 2024
bedd18f
add github action workflows for linting
robinpdev Feb 21, 2024
2b57a8e
temporary remove tests workflow
robinpdev Feb 21, 2024
7a95e5f
troubleshooting
robinpdev Feb 21, 2024
9610e5c
fix pathnames
robinpdev Feb 21, 2024
6bf938b
Add user model
axellorreyne Feb 22, 2024
c016d8d
add account deletion
axellorreyne Feb 22, 2024
a021d47
add migrations dir for users
axellorreyne Feb 22, 2024
5c33e66
Add simple user property
axellorreyne Feb 22, 2024
4c493ba
fix lint
axellorreyne Feb 22, 2024
72bed41
cleanup requirements
axellorreyne Feb 22, 2024
b1fc107
Merge pull request #15 from SELab-2/feature/user-profiles
robinpdev Feb 23, 2024
406190f
add deploy script and compose file and workflow
robinpdev Feb 23, 2024
bbe964c
add volumes
robinpdev Feb 23, 2024
af76532
add production dockerfiles
robinpdev Feb 23, 2024
ffa220f
try to fix backen d dockerfile
robinpdev Feb 23, 2024
68efed4
try traefik path routing
robinpdev Feb 24, 2024
de6a98b
add https and path stripping to traefik
robinpdev Feb 24, 2024
faf64eb
fix allowed origins in backend
robinpdev Feb 24, 2024
51a69cb
trying to fix routing with traefik
robinpdev Feb 24, 2024
575645b
set backend url under /api
robinpdev Feb 24, 2024
ff8eb05
try fix for path routing
robinpdev Feb 24, 2024
a11efab
try to fix path trimming
robinpdev Feb 24, 2024
d6ba423
try to fix static url
robinpdev Feb 24, 2024
3a3fe84
try to fix static files
robinpdev Feb 24, 2024
32ff83a
reorder compose entry to correct routing?
robinpdev Feb 24, 2024
0e11461
try to fix static files location
robinpdev Feb 24, 2024
5f31322
fix static config and add collectstatic to entrypoint
robinpdev Feb 24, 2024
58fe0e7
try to fix static file collection
robinpdev Feb 24, 2024
5c72342
try to fix static files collection
robinpdev Feb 24, 2024
b08ad63
remove static for now
robinpdev Feb 24, 2024
1ab71c4
huh?
robinpdev Feb 24, 2024
62c5508
temp remove collectstatic
robinpdev Feb 24, 2024
71c80b0
testje
robinpdev Feb 24, 2024
82aea30
moment of truth
robinpdev Feb 24, 2024
84ecdff
experiment
robinpdev Feb 24, 2024
e49bc7b
addendum
robinpdev Feb 24, 2024
37a13c9
nog een experiment
robinpdev Feb 24, 2024
66db5b8
fixed normaal
robinpdev Feb 24, 2024
7df948c
re-enable static container
robinpdev Feb 24, 2024
1f02ea3
Update .flake8
robinpdev Feb 26, 2024
d66c734
fix installed apps
axellorreyne Feb 27, 2024
3fb1517
fix installed apps
axellorreyne Feb 27, 2024
2aa19bf
Merge remote-tracking branch 'origin/develop' into develop
axellorreyne Feb 27, 2024
d8f3097
Merge pull request #13 from SELab-2/8-github-actions-testing-linting
robinpdev Feb 28, 2024
9d82d81
fix db host in env file
axellorreyne Feb 28, 2024
72baa6a
Merge remote-tracking branch 'origin/develop' into develop
axellorreyne Feb 28, 2024
91fe17e
deploy compose file working
robinpdev Feb 28, 2024
a72ea47
Merge remote-tracking branch 'origin/develop' into 9-continuous-deplo…
robinpdev Feb 28, 2024
193e00b
deploy action first test
robinpdev Feb 28, 2024
b0379b7
bonus makefile
robinpdev Feb 28, 2024
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
12 changes: 12 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DEBUG=1
SECRET_KEY=development_key
DJANGO_ALLOWED_HOSTS='localhost 127.0.0.1 [::1] django'
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=pigeonhole_dev
SQL_USER=pigeonhole
SQL_PASSWORD=password
SQL_HOST=pigeonhole-database
SQL_PORT=5432
DATABASE=postgres
DJANGO_SUPERUSER_PASSWORD=abc
DJANGO_SUPERUSER_EMAIL=abc@example.com
16 changes: 16 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Continous deployment of the app

name: CD

on:
push:
branches: ["develop"]

jobs:
build:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3

- name: Run deploy script
run: bash /home/selab2/hosting/UGent-1/deploy.sh
45 changes: 45 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lint CI

on:
- pull_request

jobs:
flake8:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analysing the code with flake8
working-directory: ./backend
run: |
flake8 pigeonhole/ testapi/

ESLint:
runs-on: self-hosted
steps:

# Check out the repository
- uses: actions/checkout@v3

# Install Node.js
- uses: actions/setup-node@v3
with:
node-version: 18.17.0

# Install your dependencies
- name: Install your dependencies
working-directory: ./frontend
run: npm ci

# Run ESLint
- name: Run ESLint
working-directory: ./frontend
run: npm run lint
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/__pycache__
.env
django/db.sqlite3
venv/

# development environment
.idea/
.vscode/

#deploy
letsencrypt
.env.prod
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
start:
docker compose up -d

stop:
docker compose down

lint:
docker exec pigeonhole-backend flake8 .
docker exec pigeonhole-frontend npm run lint
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
- Alexander Van Oyen
- Axel Lorreyne: Projectleider
- Gilles Arnout
- Pieter-Jan De Smijter
- Reinhard De Paepe
- Pieter-Jan De Smijter: Technical lead
- Reinhard De Paepe: Backend lead
- Robin Paret: Systeembeheerder
- Rune Dyselinck
- Thibaud Collyn: Customer relations officer
- Thibaud Collyn : Customer relations officer, Frontend lead
3 changes: 3 additions & 0 deletions backend/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length=120
exclude=testapi/migrations
29 changes: 29 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pull official base image
FROM python:3.11.7-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# copy entrypoint.sh
COPY ./entrypoint.sh .
RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh

# copy project
COPY . .

# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
73 changes: 73 additions & 0 deletions backend/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
###########
# BUILDER #
###########

# pull official base image
FROM python:3.11.7-alpine as builder

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev

# lint
RUN pip install --upgrade pip
COPY . .

# install dependencies
COPY requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt


#########
# FINAL #
#########

# pull official base image
FROM python:3.11.7-alpine

# create directory for the app user
RUN mkdir -p /home/app

# create the app user
RUN addgroup -S app && adduser -S app -G app

# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/static
RUN mkdir $APP_HOME/uploads
WORKDIR $APP_HOME

# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --no-cache /wheels/*

# copy entrypoint.prod.sh
COPY ./entrypoint.prod.sh .
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.prod.sh
RUN chmod +x $APP_HOME/entrypoint.prod.sh

# copy project
COPY . $APP_HOME

RUN chmod +x $APP_HOME/entrypoint.prod.sh


# chown all the files to the app user
RUN chown -R app:app $APP_HOME/

# change to the app user
USER app

# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
14 changes: 14 additions & 0 deletions backend/entrypoint.prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."

while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1
done

echo "PostgreSQL started"
fi

exec "$@"
20 changes: 20 additions & 0 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."

while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1
done

echo "PostgreSQL started"
fi

#python manage.py flush --no-input
#python manage.py makemigrations
python manage.py migrate

python manage.py createsuperuser --noinput --email $DJANGO_SUPERUSER_EMAIL

exec "$@"
22 changes: 22 additions & 0 deletions backend/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pigeonhole.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Empty file added backend/pigeonhole/__init__.py
Empty file.
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions backend/pigeonhole/apps/users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
class Meta(AbstractUser.Meta):
db_table = "auth_user"

def delete_account(self):
self.first_name = ""
self.last_name = ""
self.email = ""
self.is_active = False
self.save()

@property
def name(self):
return f"{self.first_name.strip()} {self.last_name.strip()}"
16 changes: 16 additions & 0 deletions backend/pigeonhole/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for pigeonhole project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pigeonhole.settings')

application = get_asgi_application()
Loading
Loading