Skip to content

Commit

Permalink
Initialize project
Browse files Browse the repository at this point in the history
  • Loading branch information
uniglot committed Jun 16, 2024
0 parents commit ac51354
Show file tree
Hide file tree
Showing 37 changed files with 1,728 additions and 0 deletions.
212 changes: 212 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# Created by https://www.toptal.com/developers/gitignore/api/django,terraform
# Edit at https://www.toptal.com/developers/gitignore?templates=django,terraform

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo

# Django stuff:

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Terraform ###
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

# End of https://www.toptal.com/developers/gitignore/api/django,terraform

.DS_Store
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Base

FROM python:3.12-slim-bookworm as base

ENV PYTHONBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Builder

FROM base as builder

ENV POETRY_VERSION=1.8.3 \
POETRY_VIRTUALENVS_IN_PROJECT=false \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_NO_INTERACTION=1

COPY ./application/poetry.lock ./application/pyproject.toml ./
RUN pip install poetry==$POETRY_VERSION \
&& poetry install --no-root

# Runner

FROM base as runner

COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY ./application /app

ARG DJANGO_SETTINGS
ENV DJANGO_SETTINGS=$DJANGO_SETTINGS

CMD [ "/bin/bash", "-c", "python manage.py migrate && gunicorn config.wsgi:application --bind 0.0.0.0:8000"]
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Fastcampus - System Designs with Anti-Patterns

## Instruction

### Preliminary

1. Create your AWS credentials and store them safely.
2. Create a file named `secrets.tfvars` inside the directory `infrastructure`.
3. Fill the file as below:
```
aws_access_key = "YOURAWSACCESSKEY"
aws_secret_key = "YOURAWSSECRETACCESSKEY"
```
4. Move inside the `infrastructure` directory and enter `terraform init` in your terminal.
### Terraform plan and apply
- To plan the infrastructure definitions, enter `terraform plan -var-file=secrets.tfvars` inside the terraform root.
- To apply the plan results, issue the command `terraform apply -var-file=secrets.tfvars`.
### Access the EKS cluster
1. Install AWS CLI and kubectl.
2. Register your AWS credentials as a profile in your AWS CLI configuration file.
3. Enter `aws eks --region ap-northeast-2 update-kubeconfig --name fc-sre-cluster` to register your cluster to the `kubectl` configuration.
- If you're using a profile other than the default profile, you should append `--profile your-profile` on the command above.
4. Enter `kubectl config use-context arn:aws:eks:ap-northeast-2:1234567890:cluster/fc-sre-cluster` (change `1234567890` to your account ID).
5. Check `kubectl get nodes`
### Destroying resources
To destory all the resources that have been provisioned, make sure issuing `terraform destroy -var-file=secrets.tfvars`.
Empty file added application/config/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions application/config/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for config 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/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
6 changes: 6 additions & 0 deletions application/config/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os

from .base import *

if os.environ.get("DJANGO_SETTINGS", "local") == "prod":
from .prod import *
Loading

0 comments on commit ac51354

Please sign in to comment.