Skip to content

Commit

Permalink
Fix/61/docker2 (#85)
Browse files Browse the repository at this point in the history
* #61 fix : change docker's user ubuntu

* #61 fix : modify all routes
  • Loading branch information
0321minji authored Jul 24, 2024
1 parent cfcc78e commit 60c07c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
8 changes: 5 additions & 3 deletions .config/uwsgi/UPCY.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[uwsgi]
chdir = /srv/UPCY_BE/

chdir = /home/ubuntu/UPCY_BE/
module = UpcyProject.wsgi:application

home = /srv/UPCY_BE/myvenv/
home = /home/ubuntu/myvenv/


uid = ubuntu
gid = ubuntu
Expand All @@ -16,4 +18,4 @@ master = true
vacuum = true
pidfile = /tmp/UPCY.pid
logto = /var/log/uwsgi/UPCY/@(exec://date +%%Y-%%m-%%d).log
log-reopen=true
log-reopen = true
41 changes: 29 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
# pull official base image
FROM python:3.10-alpine as builder
# Dockerfile

# ubuntu 사용자 및 그룹 추가
RUN addgroup -S ubuntu || true && adduser -S ubuntu -G ubuntu || true
# 기존 명령들 위에 아래 명령을 추가합니다
RUN mkdir -p /UPCY_BE/logs
RUN touch /UPCY_BE/logs/debug.log
RUN chown -R ubuntu:ubuntu /UPCY_BE/logs
RUN addgroup -S ubuntu && adduser -S ubuntu -G ubuntu

# 로그 디렉토리 및 파일 생성
RUN mkdir -p /var/log/uwsgi/UPCY
RUN chown -R ubuntu:ubuntu /var/log/uwsgi

# 의존성 패키지 설치 및 삭제

RUN apk update && apk add python3 python3-dev mariadb-dev build-base coreutils linux-headers pcre-dev && pip3 install mysqlclient && apk del python3-dev mariadb-dev build-base
RUN apk add --no-cache gcc musl-dev python3-dev mariadb-connector-c-dev

RUN pip install ruamel.yaml.clib
RUN mkdir /srv/UPCY_BE
WORKDIR /srv/UPCY_BE
COPY requirements.txt /srv/UPCY_BE/requirements.txt
RUN python3 -m pip install --upgrade pip
RUN pip install -r requirements.txt
COPY . /srv/UPCY_BE/

# 애플리케이션 디렉토리로 작업 디렉토리 설정
WORKDIR /home/ubuntu/UPCY_BE

# 가상 환경 생성
RUN python3 -m venv /home/ubuntu/myvenv

# requirements.txt 파일을 복사한 후 패키지 설치
COPY requirements.txt /home/ubuntu/UPCY_BE/requirements.txt
RUN /home/ubuntu/myvenv/bin/pip install --upgrade pip
RUN /home/ubuntu/myvenv/bin/pip install -r requirements.txt

# 애플리케이션 소스 복사
COPY . /home/ubuntu/UPCY_BE/

# 소유자 변경
RUN chown -R ubuntu:ubuntu /home/ubuntu/UPCY_BE

USER ubuntu

# 기본 명령어 설정
ENTRYPOINT ["/home/ubuntu/myvenv/bin/uwsgi", "--ini", "/home/ubuntu/UPCY_BE/.config/uwsgi/UPCY.ini"]
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ services:
build:
context: ./
dockerfile: Dockerfile
command: sh -c "python manage.py migrate && uwsgi --ini .config/uwsgi/UPCY.ini"
command: >
sh -c "
python manage.py migrate &&
/home/ubuntu/myvenv/bin/uwsgi --ini /home/ubuntu/UPCY_BE/.config/uwsgi/UPCY.ini --logto /var/log/uwsgi/UPCY/@(exec://date +%%Y-%%m-%%d).log"
environment:
DJANGO_SETTINGS_MODULE: UpcyProject.settings.production
env_file:
- .env
volumes:
- .:/srv/UPCY_BE
- .:/home/ubuntu/UPCY_BE
- /tmp:/tmp
- /var/log/uwsgi:/var/log/uwsgi
- ./logs:/UPCY_BE/logs
- ./logs:/home/ubuntu/UPCY_BE/logs
expose:
- 8000

nginx:
image: nginx:latest
ports:
- 80:80
- "80:80"
volumes:
- ./.config/nginx/UPCY.conf:/etc/nginx/nginx.conf
depends_on:
Expand Down

0 comments on commit 60c07c2

Please sign in to comment.