-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from SELab-2/9-continuous-deployment
9 continuous deployment
- Loading branch information
Showing
51 changed files
with
5,848 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length=120 | ||
exclude=testapi/migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.