-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactored the project building and deploying procedure. Added frontend #43
Changes from 6 commits
34236ab
f51724e
30548a6
203f755
71357e3
d7a62de
aca2230
3fce5d2
92b75f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,26 +37,47 @@ jobs: | |
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/volunteers_backend:latest | ||
|
||
# build_frontend_and_push_to_docker_hub: | ||
# name: Push frontend Docker image to DockerHub | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: Check out the repo | ||
# uses: actions/checkout@v3 | ||
# - name: Set up Docker Buildx | ||
# uses: docker/setup-buildx-action@v2 | ||
# - name: Login to Docker | ||
# uses: docker/login-action@v2 | ||
# with: | ||
# username: ${{ secrets.DOCKER_USERNAME }} | ||
# password: ${{ secrets.DOCKER_PASSWORD }} | ||
# - name: Push to DockerHub | ||
# uses: docker/build-push-action@v4 | ||
# with: | ||
# context: [email protected]:volunteers-for-city-projects/volunteers-frontend.git | ||
# file: /infra_bt/Dockerfile | ||
# push: true | ||
# tags: ${{ secrets.DOCKER_USERNAME }}/volunteers_frontend:latest | ||
build_frontend_and_push_to_docker_hub: | ||
name: Push frontend Docker image to DockerHub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Push to DockerHub | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: [email protected]:volunteers-for-city-projects/volunteers-frontend.git#deployDocker | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/volunteers_frontend:latest | ||
|
||
build_gateway_and_push_to_docker_hub: | ||
name: Push gateway Docker image to DockerHub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Push to DockerHub | ||
uses: docker/build-push-action@v4 | ||
with: | ||
build-args: | ||
NGINX_VERSION=${{ vars.NGINX_VERSION_BUILD }} | ||
context: ./infra_bt/ | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/volunteers_gateway:latest | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
|
@@ -77,7 +98,8 @@ jobs: | |
key: ${{ secrets.SSH_KEY }} | ||
passphrase: ${{ secrets.SSH_PASSPHRASE }} | ||
source: "infra_bt/docker-compose.production.yml" | ||
target: "volunteers-for-city-projects" | ||
target: "better-together/" | ||
strip_components: 1 | ||
- name: Executing remote ssh commands to deploy | ||
uses: appleboy/ssh-action@master | ||
with: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,3 +167,6 @@ cython_debug/ | |
# static | ||
**/collected_static/ | ||
media/ | ||
|
||
# pre-commit | ||
.pre-commit-config.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
.env.example | ||
docker-compose.production.yml | ||
docker-compose.yml | ||
Dockerfile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ARG NGINX_VERSION_BUILD | ||
FROM nginx:$NGINX_VERSION_BUILD | ||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ version: '3.3' | |
|
||
volumes: | ||
pg_data: | ||
static: | ||
media: | ||
static_data: | ||
media_data: | ||
|
||
|
||
name: volunteers | ||
|
@@ -32,45 +32,40 @@ services: | |
build: ../backend/ | ||
env_file: .env | ||
volumes: | ||
- static:/backend_static | ||
- media:/media | ||
- static_data:/backend_static | ||
- media_data:/app/media | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Через /app/media пробовал, почему-то не работает так. В корне есть /media по умолчанию в контейнере, он почему-то на нее ссылаться начинает. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот из-за того, что в контейнер вольюм подключается по пути /media, мы и получимаем в итоге ссылки на подключаемое оборудование в ОС контейнера (особенность линукса, у которого /media - это директория куда автоматом монтируются подключаемые носители flopy, cdrom и прочее). Это и есть "сюрприз". Поэтому и подключил /app/media, так как при сборке контейнера бэкэнд складывается в директорию /app. |
||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
python manage.py collectstatic -c --noinput | ||
cp -r /app/collected_static/. /backend_static/static/ | ||
cp -r /app/collected_static/. /backend_static/static | ||
python manage.py migrate | ||
gunicorn --bind 0.0.0.0:8000 backend.wsgi | ||
restart: unless-stopped | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
|
||
# frontend: | ||
# build: | ||
# context: [email protected]:volunteers-for-city-projects/volunteers-frontend.git | ||
# dockerfile: Dockerfile | ||
# command: | ||
# - /bin/sh | ||
# - -c | ||
# - | | ||
# npm run build result_build | ||
# cp -r /app/result_build/ static_files/ | ||
# volumes: | ||
# - ../frontend:/app/ | ||
# - static:/static_files | ||
frontend: | ||
build: | ||
context: https://github.com/volunteers-for-city-projects/volunteers-frontend.git#feature/deployDocker | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
cp -r /app/. /static_files/ | ||
volumes: | ||
- static_data:/static_files | ||
|
||
nginx: | ||
image: nginx:1.25.2-alpine3.18-slim | ||
ports: | ||
- "8000:80" | ||
volumes: | ||
- ./nginx.conf:/etc/nginx/conf.d/default.conf | ||
# - ../frontend/build:/usr/share/nginx/html/ | ||
# - ../docs/:/usr/share/nginx/html/api/docs/ | ||
- static:/static | ||
- media:/media | ||
- static_data:/usr/share/nginx/html | ||
- media_data:/usr/share/nginx/html/media/ | ||
depends_on: | ||
backend: | ||
condition: service_started |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
server { | ||
listen 80; | ||
|
||
root /usr/share/nginx/html; | ||
|
||
location /api/ { | ||
proxy_set_header Host $http_host; | ||
proxy_pass http://backend:8000/api/; | ||
|
@@ -9,24 +11,16 @@ server { | |
proxy_set_header Host $http_host; | ||
proxy_pass http://backend:8000/swagger/; | ||
} | ||
location /redoc/ { | ||
proxy_set_header Host $http_host; | ||
proxy_pass http://backend:8000/redoc/; | ||
} | ||
location /admin/ { | ||
proxy_set_header Host $http_host; | ||
proxy_pass http://backend:8000/admin/; | ||
} | ||
location /static/ { | ||
root /static; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тоже не понимаю зачем затирать эти настройки... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь эти строчки становятся не нужными из-за изменения настроек монтирования тома static_data и переноса настройки root вне секции location / {} |
||
location /media/ { | ||
root /; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И эти настройки тоже зачем удалены? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А вот тут я тоже погорячился убрать и не вернуть прежде чем обсудить где именно расположить папку медиа относительно всей статики вцелом. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Предлагаю в settings изменить MEDIA_ROOT = '/media' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, я тоже к этому пришел и внес эти изменения в свой ПР. |
||
|
||
# location / { | ||
# proxy_set_header Host $http_host; | ||
# proxy_pass http://backend:8000/; | ||
# } | ||
|
||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html index.htm; | ||
try_files $uri /index.html; | ||
proxy_set_header Host $host; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поясни зачем настройки media совсем убрал, а не исправил на media_data:/media?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалял, так как был "сюрприз" с той строчкой, которую ты прописал, а корректную версию прописать забыл. Было бы не плохо созвониться обсудить, там еще есть пара "моментов", которые на счет медиа хотел прояснить.