Skip to content

Commit

Permalink
Merge pull request #128 from PlasmicZ/Plasmicz/Proxy
Browse files Browse the repository at this point in the history
proxied the frontend through nginx
  • Loading branch information
0x0elliot authored Nov 14, 2023
2 parents 44d60e3 + 6222259 commit d858652
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: docker/Dockerfile
file: docker/Dockerfile.backend
push: true
tags: ghcr.io/thirdeye-dev/thirdeye:latest
6 changes: 3 additions & 3 deletions backend/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def retrieve(self, request, *args, **kwargs):

def google_login(request):
# for development
REPLACEMENT_DOMAIN = "localhost:3000"
REPLACEMENT_DOMAIN = "localhost"

if settings.DEMO_INSTANCE:
REPLACEMENT_DOMAIN = settings.API_DOMAIN
Expand All @@ -133,7 +133,7 @@ def google_login(request):

def google_login(request):
# for development
REPLACEMENT_DOMAIN = "localhost:3000"
REPLACEMENT_DOMAIN = "localhost"

if settings.DEMO_INSTANCE:
REPLACEMENT_DOMAIN = settings.API_DOMAIN
Expand All @@ -159,7 +159,7 @@ def google_login(request):

def github_login(request):
# for development
REPLACEMENT_DOMAIN = "localhost:3000"
REPLACEMENT_DOMAIN = "localhost"

if settings.DEMO_INSTANCE:
REPLACEMENT_DOMAIN = settings.FRONTEND_DOMAIN
Expand Down
6 changes: 3 additions & 3 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
]

APPEND_SLASH = False
FRONTEND_URL = "http://localhost:3000/"
FRONTEND_URL = "http://localhost/"

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
Expand Down Expand Up @@ -172,7 +172,7 @@
FRONTEND_URL = (
FRONTEND_URL_MAIN
if DEMO_INSTANCE
else os.environ.get("FRONTEND_URL", "http://localhost:3000/")
else os.environ.get("FRONTEND_URL", "http://localhost/")
)

# SECURITY WARNING: keep the secret key used in production secret!
Expand Down Expand Up @@ -309,7 +309,7 @@
"VERSION": "0.0.1",
"SERVE_INCLUDE_SCHEMA": False,
"SERVERS": [
{"url": "http://localhost:3000/", "description": "Localhost API base URL"},
{"url": "http://localhost/", "description": "Localhost API base URL"},
],
}

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions docker/Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Stage 1: Build frontend
FROM node:alpine AS frontend

WORKDIR /usr/app

RUN npm install --global pm2

COPY frontend/package*.json ./

RUN npm install --production --force

COPY frontend/ ./

RUN npm run build

EXPOSE 3000

USER node

CMD [ "pm2-runtime", "npm", "--", "start" ]
2 changes: 1 addition & 1 deletion docker/dev.demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- "8000"
build:
context: ..
dockerfile: docker/Dockerfile
dockerfile: docker/Dockerfile.backend
entrypoint: docker/entrypoint/entrypoint.sh
ports:
- "8000:8000"
Expand Down
48 changes: 38 additions & 10 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ services:
- ../postgres_data:/var/lib/postgresql/data
env_file:
- ./.env

frontend:
hostname: frontend
image: frontend_app_thirdeye
container_name: frontend_app_thirdeye
build:
context: ../
dockerfile: docker/Dockerfile.frontend
networks:
default:
internal:
volumes:
- ../:/app
env_file:
- ./.env
#ports:
# - "3000:3000"

nginx:
hostname: nginx
image: nginx:alpine
container_name: nginx_app_thirdeye
networks:
default:
internal:
volumes:
- ./nginx/default.conf:/etc/nginx/nginx.conf
ports:
- "80:80"

backend:
container_name: backend_app_thirdeye
Expand All @@ -20,8 +49,8 @@ services:
expose:
- "8000"
build:
context: ..
dockerfile: docker/Dockerfile
context: .
dockerfile: docker/Dockerfile.backend
entrypoint: docker/entrypoint/entrypoint.sh
depends_on:
- postgres
Expand All @@ -34,8 +63,8 @@ services:

celery:
build:
context: ..
dockerfile: docker/Dockerfile
context: .
dockerfile: docker/Dockerfile.backend
container_name: celery_thirdeye
volumes:
- ../:/app
Expand All @@ -51,8 +80,8 @@ services:

celery_beat:
build:
context: ..
dockerfile: docker/Dockerfile
context: .
dockerfile: docker/Dockerfile.backend
volumes:
- ../:/app
networks:
Expand Down Expand Up @@ -83,8 +112,7 @@ services:
internal:
image: redis:alpine


networks:
default:
internal:
internal: true
default:
internal:
internal: true
37 changes: 37 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
worker_processes auto; # auto-detect number of logical CPU cores

events {
worker_connections 512; # set the max number of simultaneous connections (per worker process)
}
http {
server {
listen 80 default_server;
server_name localhost;
server_tokens off;

gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml;

location / {
proxy_pass http://frontend:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

location /api {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://backend:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

}
}
8 changes: 0 additions & 8 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ const nextConfig = {
},
];
},
async rewrites() {
return [
{
source: "/api/:slug*",
destination: `${backendUrl}/:slug*`,
},
];
},
};

module.exports = removeImports(nextConfig);
Expand Down

0 comments on commit d858652

Please sign in to comment.