diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c69d96d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,32 @@ +**/*.pyc +**/*.pyo +**/*.mo +**/*.db +**/*.css.map +**/*.egg-info +**/*.sql.gz +**/__pycache__/ +.cache +.project +.idea +.pydevproject +.idea/workspace.xml +.DS_Store +.git/ +.sass-cache +.vagrant/ +dist +docs +env +logs +src/{{ project_name }}/settings/local.py +src/node_modules +web/media +web/static/CACHE +stats +Dockerfile +.gitignore +Dockerfile +db.sqlite3 +**/*.md +logs/ \ No newline at end of file diff --git a/.github/workflows/pbp-deploy.yml b/.github/workflows/pbp-deploy.yml new file mode 100644 index 0000000..55d9dfd --- /dev/null +++ b/.github/workflows/pbp-deploy.yml @@ -0,0 +1,24 @@ +name: Deploy + +on: + push: + branches: + - main + - master + +jobs: + Deployment: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Cloning repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Push to Dokku server + uses: dokku/github-action@master + with: + branch: 'main' + git_remote_url: ssh://dokku@${{ secrets.DOKKU_SERVER_IP }}/${{ secrets.DOKKU_APP_NAME }} + ssh_private_key: ${{ secrets.DOKKU_SSH_PRIVATE_KEY }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..82ba771 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM python:3.10-slim-buster + +WORKDIR /app + +ENV PYTHONUNBUFFERED=1 \ + PYTHONPATH=/app \ + DJANGO_SETTINGS_MODULE=shopping_list.settings \ + PORT=8000 \ + WEB_CONCURRENCY=2 + +# Install system packages required Django. +RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \ +&& rm -rf /var/lib/apt/lists/* + +RUN addgroup --system django \ + && adduser --system --ingroup django django + +# Requirements are installed here to ensure they will be cached. +COPY ./requirements.txt /requirements.txt +RUN pip install -r /requirements.txt + +# Copy project code +COPY . . + +RUN python manage.py collectstatic --noinput --clear + +# Run as non-root user +RUN chown -R django:django /app +USER django + +# Run application +# CMD gunicorn shopping_list.wsgi:application \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..b45c7f5 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: django-admin migrate --noinput +web: gunicorn arto_moro_pbp.wsgi \ No newline at end of file diff --git a/arto_moro_pbp/settings.py b/arto_moro_pbp/settings.py index df7d2d2..0834b33 100644 --- a/arto_moro_pbp/settings.py +++ b/arto_moro_pbp/settings.py @@ -11,16 +11,22 @@ """ from pathlib import Path +import environ # Tambahkan kode berikut +import os # Tambahkan kode berikut # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +env = environ.Env() # Tambahkan kode berikut # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-v*syeixx(l9xfe6#^2xeac(2wv9b&3!-#xal@179+9q&m&anwm' +# Automatically determine environment by detecting if DATABASE_URL variable. +# DATABASE_URL is provided by Heroku if a database add-on is added (e.g. Heroku Postgres). +PRODUCTION = env.bool('PRODUCTION', False) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -81,6 +87,12 @@ } } +# Set database settings automatically using DATABASE_URL. +if PRODUCTION: + DATABASES = { + 'default': env.db('DATABASE_URL') + } + DATABASES["default"]["ATOMIC_REQUESTS"] = True # Password validation # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators @@ -118,6 +130,8 @@ STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') + # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field diff --git a/requirements.txt b/requirements.txt index c458349..1d1bf52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ gunicorn whitenoise psycopg2-binary requests -urllib3 \ No newline at end of file +urllib3 +django-environ \ No newline at end of file