Apply Git Commit Message Template

git config --local commit.template ./.gitmessage

Poetry에서 개발 의존성 추가

poetry add --group dev isort

Gunicorn with Uvicorn workers

  1. poetry 가상환경에 gunicorn, uvicorn 설치: poetry install --sync --without dev --no-root

  2. 환경변수 설정: sudo vim /etc/environment

    GUNICORN_CMD_ARGS="--bind=127.0.0.1:8000 --worker-class uvicorn.workers.UvicornWorker --workers 2”
    
  3. Gunicorn 서비스 정의: sudo vim /etc/systemd/system/gunicorn.service

    [Unit]
    Description=gunicorn daemon
    After=network.target
    
    [Service]
    User=ubuntu
    Group=ubuntu
    WorkingDirectory=/var/www/auth-proxy/src
    EnvironmentFile=/etc/environment
    ExecStart=/home/ubuntu/.local/bin/poetry run gunicorn main:app
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s TERM $MAINPID
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    
  4. sudo systemctl daemon-reload

  5. sudo systemctl restart gunicorn.service

NGINX

  1. NGINX 설치: sudo apt install nginx

  2. NGINX 설정 파일 생성: sudo vim /etc/nginx/sites-available/auth-proxy.conf

    server {
        listen 80;
        server_name 52.78.85.40;  # EC2 인스턴스의 탄력적 IP주소
    
        # access_log /var/log/nginx/eight_access.log timed_combined;
        # error_log /var/log/nginx/eight_error.log;
    
        location = /favicon.ico {
             access_log off;
             log_not_found off;
        }
    
        location / {
            include proxy_params;
            # proxy_set_header Host $http_host;
            # proxy_set_header X-Real-IP $remote_addr;
            # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass <http://127.0.0.1:8000>;  # gunicorn bind 경로와 통일
        }
    }
    
  3. NGINX 설정 파일 연결:

    cd /etc/nginx/sites-enabled

    sudo rm default

    sudo ln -s /etc/nginx/sites-available/auth-proxy.conf

  4. NGINX 서비스 재시작: sudo systemctl restart nginx

배포 스크립트

git pull
poetry install --sync --without dev --no-root
sudo systemctl restart gunicorn.service

Express 배포