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

AWS DMS 예제 #68

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
crash.log

# Exclude all .tfvars files, which are likely to contain sentitive 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
# 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

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
Expand Down
1 change: 1 addition & 0 deletions computer_science/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
| ---- | ---- | ---- |
| 1 | ssh 비대칭키로 암호화와 복호화 | [링크](./encryption_and_decryption/) |
| 2 | ssh vs telnet | [링크](./ssh_vs_telnet/) |
| 3 | AWS DMS를 사용한 DB 마이그레이션 | [링크](./db_migration_with_aws/) |
4 changes: 4 additions & 0 deletions computer_science/db_migration_with_aws/application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 개요
* 간단히 메모를 추가하는 웹 애플리케이션
* django로 개발
* mysql를 DB로 사용
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Python cache
__pycache__/
*.pyc
*.pyo
*.pyd

# Virtual environments
venv/
.env/

# Local settings
*.env
*.local
*.log

# Django static and media files (if generated locally)
staticfiles/
media/

# Node modules (if you're using npm or yarn)
node_modules/

# Distribution / Packaging
*.egg-info/
dist/
build/

# Docker
Dockerfile
docker-compose.yml

# Git
.git/
.gitignore

# IDEs and editors
*.vscode/
*.idea/
*.swp

Makefile
docker-compose.yml

.idea/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.12

WORKDIR /app

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


COPY ./ /app

RUN pip install --upgrade pip
RUN pip install poetry
RUN poetry install

RUN poetry run python manage.py collectstatic --noinput

EXPOSE 8000

CMD ["poetry", "run", "gunicorn", "--bind", "0.0.0.0:8000", "memo_project.asgi:application"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IMAGE_NAME=choisunguk/dms-example-memo
IMAGE_TAG=v1

create-builder:
docker buildx create --name mybuilder --use

build-push:
docker buildx build --platform linux/amd64,linux/arm64 -t $(IMAGE_NAME):${IMAGE_TAG} --push .

.PHONY: create-builder build-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 로컬 개발환경 설정

* mysql 컨테이너 실행

```sh
docker-compose up -d
```

* 환경변수 설정하기 위해 .env파일 생성

```sh
$ cd memo_project
$ vi .env
DEBUG=True
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306
DATABASE_NAME=memo_db
DATABASE_USER=memo
DATABASE_PASSWORD=password
```

# 로컬 실행 방법
* 파이썬 패키지 설치

```sh
# poetry 파이썬 가상환경 실행
$ poetry shell
# 파이썬 패키지 설치
$ poetry install
```

* django 실행

```sh
python manage.py runserver
```

* 웹브라우저에서 http://127.0.0.1:8000/ 접속
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.8'

services:
mysql:
image: mysql:8.0
container_name: django_mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: memo_db
MYSQL_USER: memo
MYSQL_PASSWORD: password
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
networks:
- mysql_network

volumes:
mysql_data:

networks:
mysql_network:
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", "memo_project.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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MemoConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "memo"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import forms
from .models import Memo

class MemoForm(forms.ModelForm):
class Meta:
model = Memo
fields = ['title', 'content']
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

# Create your models here.
class Memo(models.Model):
title = models.CharField(max_length=100) # VARCHAR
content = models.TextField() # TEXT
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
color: #333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.container {
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 600px;
}

h1 {
font-size: 24px;
margin-bottom: 20px;
color: #444;
text-align: center;
}

ul {
list-style-type: none;
padding: 0;
}

li {
background-color: #fafafa;
margin: 10px 0;
padding: 10px;
border-radius: 4px;
display: flex;
justify-content: space-between;
align-items: center;
}

li a {
text-decoration: none;
color: #007bff;
}

li a:hover {
text-decoration: underline;
}

a.button {
display: inline-block;
padding: 10px 15px;
margin-top: 10px;
background-color: #007bff;
color: white;
border-radius: 4px;
text-decoration: none;
text-align: center;
}

a.button:hover {
background-color: #0056b3;
}

form {
display: flex;
flex-direction: column;
}

form input[type="text"], form textarea {
margin-bottom: 10px;
padding: 10px;
border-radius: 4px;
border: 1px solid #ccc;
}

form button {
padding: 10px 15px;
border: none;
border-radius: 4px;
background-color: #28a745;
color: white;
cursor: pointer;
}

form button:hover {
background-color: #218838;
}

/* 기본 버튼 스타일 */
a.button {
display: inline-block; /* 링크를 인라인 요소에서 블록 요소로 변경 */
padding: 10px 20px; /* 내부 여백을 추가하여 버튼처럼 보이게 함 */
font-size: 16px; /* 글자 크기 설정 */
color: #ffffff; /* 텍스트 색상 */
background-color: #007bff; /* 버튼 배경색 */
text-align: center; /* 텍스트를 가운데 정렬 */
text-decoration: none; /* 기본 링크의 밑줄 제거 */
border-radius: 5px; /* 버튼 모서리를 둥글게 */
transition: background-color 0.3s ease, transform 0.1s ease; /* 배경색 및 크기 변화에 애니메이션 추가 */
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* 버튼에 약간의 그림자 추가 */
}

/* 마우스를 올렸을 때 */
a.button:hover {
background-color: #0056b3; /* 더 짙은 파란색으로 변경 */
transform: scale(1.05); /* 약간 확대되는 효과 */
}

/* 클릭 중인 상태 */
a.button:active {
background-color: #00376b; /* 클릭 중일 때 더 짙은 색으로 변경 */
transform: scale(0.98); /* 클릭 중일 때 약간 축소되어 눌리는 느낌 */
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'css/styles.css' %}">
<title>Memo App</title>
</head>
<body>
<div class="container">
{% block content %}
{% endblock %}
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block content %}
<h1>Delete Memo</h1>
<p>Are you sure you want to delete the memo "{{ memo.title }}"?</p>
<form method="post">
{% csrf_token %}
<button type="submit">Confirm Delete</button>
</form>
<a href="{% url 'memo_list' %}" class="button">Cancel</a>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block content %}
<h1>{% if form.instance.pk %}Edit Memo{% else %}Create Memo{% endif %}</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save</button>
</form>
<a href="{% url 'memo_list' %}" class="button">Back to List</a>
{% endblock %}
Loading