This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #13 from unb-mds/feature/django-bootstrap
[feature request] Adicionar bootstrap inicial da aplicação
- Loading branch information
Showing
22 changed files
with
692 additions
and
29 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,48 @@ | ||
name: Test application | ||
|
||
on: | ||
push: | ||
pull_request: | ||
types: | ||
- reopened | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: ["3.11"] | ||
poetry-version: ["1.6.1"] | ||
|
||
env: | ||
DATABASE_URL: "sqlite:///db.sqlite3" | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Poetry ${{ matrix.poetry-version }} | ||
uses: snok/install-poetry@v1 | ||
with: | ||
version: ${{ matrix.poetry-version }} | ||
virtualenvs-create: false | ||
installer-parallel: true | ||
|
||
- name: Install dependencies | ||
run: | | ||
poetry run pip install --no-deps --upgrade pip | ||
poetry install --with dev | ||
- name: Run hooks | ||
uses: pre-commit/[email protected] | ||
|
||
- name: Run tests | ||
run: | | ||
poetry run python manage.py test \ | ||
--settings=server.settings.development |
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 |
---|---|---|
@@ -1 +1 @@ | ||
# 2023-2-Squad06 | ||
# 2023-2-Squad06 |
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,14 @@ | ||
#!/bin/bash | ||
|
||
# This script creates a .env file in the config directory and generates a | ||
# random secret key for the Django app automatically. | ||
|
||
read -r -d '' SECRET_KEY_CMD << EOM | ||
from django.utils.crypto import get_random_string; | ||
print(get_random_string(64)) | ||
EOM | ||
|
||
SECRET_KEY=$(python3 -c "${SECRET_KEY_CMD}") | ||
OUTPUT=$(sed "s/^\(DJANGO_SECRET_KEY=\).*/\1$SECRET_KEY/" config/.env.example) | ||
|
||
echo "$OUTPUT" > config/.env |
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 @@ | ||
|
||
############ | ||
# Django # | ||
############ | ||
|
||
DJANGO_SECRET_KEY= | ||
|
||
################ | ||
# PostgreSQL # | ||
################ | ||
|
||
POSTGRES_HOST=postgres | ||
POSTGRES_PORT=5432 | ||
|
||
POSTGRES_USER=virtualjudge | ||
POSTGRES_PASSWORD=virtualjudge | ||
POSTGRES_DB=virtualjudge |
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,42 @@ | ||
services: | ||
django: | ||
image: virtual-judge:dev | ||
container_name: django | ||
build: | ||
context: . | ||
dockerfile: docker/django/Dockerfile | ||
target: development-build | ||
args: | ||
- DJANGO_ENV=development | ||
- UID=${UID:-1000} | ||
- GID=${GID:-1000} | ||
cache_from: | ||
- "virtual-judge:dev" | ||
- "virtual-judge:latest" | ||
- "*" | ||
volumes: | ||
- .:/app | ||
ports: | ||
- 8000:8000 | ||
networks: | ||
- main | ||
env_file: | ||
- config/.env | ||
command: python -Wd manage.py runserver 0.0.0.0:8000 | ||
|
||
postgres: | ||
image: postgres:16.0-alpine | ||
container_name: postgres | ||
volumes: | ||
- data:/var/lib/postgresql/data | ||
networks: | ||
- main | ||
env_file: | ||
- config/.env | ||
restart: unless-stopped | ||
|
||
volumes: | ||
data: | ||
|
||
networks: | ||
main: |
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,102 @@ | ||
# We use multi-stage builds to reduce the size of the image in production and | ||
# to avoid installing unnecessary dependencies in the production image. | ||
# See: https://docs.docker.com/develop/develop-images/multistage-build/ | ||
|
||
####################### | ||
# Development stage # | ||
####################### | ||
|
||
FROM python:3.11.5-slim-bullseye AS development-build | ||
|
||
ARG DJANGO_ENV \ | ||
# This is needed to fix permissions of files created in the container, so | ||
# that they are owned by the host user. | ||
UID=1000 \ | ||
GID=1000 | ||
|
||
ENV DJANGO_ENV=${DJANGO_ENV} \ | ||
# Python: | ||
PYTHONFAULTHANDLER=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONHASHSEED=random \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
# Pip: | ||
PIP_NO_CACHE_DIR=1 \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
PIP_DEFAULT_TIMEOUT=100 \ | ||
# Poetry: | ||
POETRY_VERSION=1.6.1 \ | ||
POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_CREATE=false \ | ||
POETRY_CACHE_DIR='/var/cache/pypoetry' \ | ||
POETRY_HOME='/usr/local' \ | ||
# Tini | ||
TINI_VERSION=v0.19.0 \ | ||
# Dockerize: | ||
DOCKERIZE_VERSION=v0.7.0 | ||
|
||
SHELL ["/bin/bash", "-eo", "pipefail", "-c"] | ||
|
||
|
||
# Install system dependencies: | ||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y --no-install-recommends \ | ||
bash \ | ||
brotli \ | ||
build-essential \ | ||
curl \ | ||
gettext \ | ||
git \ | ||
libpq-dev \ | ||
# Installing Poetry: | ||
&& curl -sSL 'https://install.python-poetry.org' | python - \ | ||
&& poetry --version \ | ||
# Installing Dockerize: | ||
&& curl -sSLO "https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz" \ | ||
&& tar -C /usr/local/bin -xzvf "dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz" \ | ||
&& rm "dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz" \ | ||
&& dockerize --version \ | ||
# Installing Tini: | ||
&& dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \ | ||
&& curl -o /usr/local/bin/tini -sSLO "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${dpkgArch}" \ | ||
&& chmod +x /usr/local/bin/tini \ | ||
&& tini --version \ | ||
# Cleaning cache: | ||
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
|
||
# We create a non-root user to run the application, so that we don't run the | ||
# application as root. | ||
RUN groupadd -g "${GID}" -r web \ | ||
&& useradd -d '/app' -g web -l -r -u "${UID}" web \ | ||
&& chown web:web -R '/app' | ||
|
||
COPY --chown=web:web ./poetry.lock ./pyproject.toml /app/ | ||
|
||
RUN --mount=type=cache,target="$POETRY_CACHE_DIR" echo "${DJANGO_ENV}" \ | ||
&& poetry version \ | ||
&& poetry run pip install --no-deps --upgrade pip \ | ||
&& poetry install \ | ||
$(if [ "${DJANGO_ENV}" = 'production' ]; then echo '--only main'; fi) \ | ||
--no-interaction --no-ansi | ||
|
||
COPY ./docker/django/entrypoint.sh /docker-entrypoint.sh | ||
|
||
RUN chmod +x '/docker-entrypoint.sh' | ||
|
||
USER web | ||
|
||
# We customize how our app is loaded with the custom entrypoint: | ||
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"] | ||
|
||
|
||
###################### | ||
# Production stage # | ||
###################### | ||
|
||
FROM development AS production | ||
|
||
COPY --chown=web:web . /app |
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,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
readonly cmd="$*" | ||
|
||
: "${POSTGRES_HOST:=postgres}" | ||
: "${POSTGRES_PORT:=5432}" | ||
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" | ||
|
||
# We need this line to make sure that this container is started after the one | ||
# with PostgreSQL: | ||
dockerize \ | ||
-wait "tcp://${POSTGRES_HOST}:${POSTGRES_PORT}" \ | ||
-timeout 90s | ||
|
||
>&2 echo 'PostgreSQL is up -- continuing...' | ||
|
||
exec $cmd |
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,21 @@ | ||
import sys | ||
from os import environ | ||
|
||
|
||
def main() -> None: | ||
environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings.development") | ||
|
||
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() |
Oops, something went wrong.