Skip to content

Commit

Permalink
feat: move proxy docker image into proxy folder
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Jun 18, 2024
1 parent 5ca3b0e commit 79055b5
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ backend: swagger
test-frontend: frontend-types
cd ./cahfrontend && pnpm run test

GO_TEST_ARGS=-v -benchmem -parallel 16 ./... -race -cover -coverpkg ./... -covermode=atomic -coverprofile=coverage.out
GO_TEST_ARGS=-v -benchmem ./... -race -cover -coverpkg ./... -covermode=atomic -coverprofile=coverage.out

.PHONY: test-backend
test-backend: backend
Expand Down
97 changes: 97 additions & 0 deletions Makefile.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
.PHONY: all
all: frontend backend
echo "Building Done"

# Swagger defs
.PHONY: swagger
swagger:
cd backend && go generate ./...

# Frontend
.PHONY: frontend-install
frontend-install:
cd ./cahfrontend/ && pnpm i

.PHONY: frontend-api
frontend-api: swagger
npx swagger-typescript-api -p ./backend/docs/swagger.json -o ./cahfrontend/src/ -n api.ts

.PHONY: frontend-tygo
frontend-tygo:
go install github.com/gzuidhof/tygo@latest
cd backend && tygo generate

.PHONY: frontend-types
frontend-types: frontend-tygo frontend-api
echo "Generated types"

.PHONY: frontend-storybook
frontend-storybook: frontend-install
cd ./cahfrontend && pnpm run build-storybook

.PHONY: frontend
frontend: frontend-install frontend-types
cd ./cahfrontend && pnpm run build

# Backend
.PHONY: backend
backend: swagger
cd ./backend/ && go build

# Tests
.PHONY: test-frontend
test-frontend: frontend-types
cd ./cahfrontend && pnpm run test

GO_TEST_ARGS=-v -benchmem -parallel 16 ./... -race -cover -coverpkg ./... -covermode=atomic -coverprofile=coverage.out

.PHONY: test-backend
test-backend: backend
cd ./backend/ && go test './...' ${GO_TEST_ARGS}

.PHONY: start-docker-compose
start-docker-compose:
docker-compose up --build --detach

# Everything is tested within docker, so this can be started imediately
.PHONY: test-e2e
test-e2e: start-docker-compose
cd ./e2e/ && go test './...' ${GO_TEST_ARGS}

.PHONY: test
test: test-backend test-frontend test-e2e frontend-storybook
echo "Testing Done"

.PHONY: bench
bench: backend
cd ./backend/ && go test '-bench=./...'

# Formatters
.PHONY: e2e-fmt
e2e-fmt:
cd ./e2e/ && gofmt -l -w .

.PHONY: backend-fmt
backend-fmt:
cd ./backend/ && swag fmt && gofmt -l -w .

.PHONY: frontend-fmt
frontend-fmt:
cd ./cahfrontend/ && prettier -w .

.PHONY: fmt
fmt: backend-fmt frontend-fmt e2e-fmt
echo "Formatting Done"

# Debug scripts
.PHONY: debug-e2e-tests
debug-e2e-tests:
cd ./e2e/ && go test -c && gdb ./e2e.test

.PHONY: debug-backend-tests
debug-backend-tests:
cd ./backend/ && go test -c && gdb ./backend.test

.PHONY: debug-backend
debug-backend:
cd ./backend/ && go build && gdb ./backend
7 changes: 7 additions & 0 deletions devProxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nginx

WORKDIR /app
COPY ./mime.types .
COPY docker.nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
75 changes: 45 additions & 30 deletions devProxy/docker.nginx.conf
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
server {
listen 80;
worker_processes 10;

location / {
proxy_set_header Host $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 http;
events {
worker_connections 1024;
}

proxy_pass http://frontend:80/;
http {
default_type application/octet-stream;

proxy_connect_timeout 7d;
proxy_read_timeout 7d;
}
sendfile on;
keepalive_timeout 65;

location /api/ {
proxy_set_header Host $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 http;
include "/app/mime.types";

proxy_pass http://backend:8080/;
server {
listen 80;

proxy_connect_timeout 7d;
proxy_read_timeout 7d;
}
location / {
proxy_set_header Host $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 http;

proxy_pass http://frontend:80/;

proxy_connect_timeout 7d;
proxy_read_timeout 7d;
}

location /api/ {
proxy_set_header Host $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 http;

proxy_pass http://backend:8080/;

proxy_connect_timeout 7d;
proxy_read_timeout 7d;
}

location /ws {
proxy_set_header Host $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 http;
location /ws {
proxy_set_header Host $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 http;

proxy_pass http://backend:8080/games/join;
proxy_pass http://backend:8080/games/join;

proxy_connect_timeout 7d;
proxy_connect_timeout 7d;

proxy_http_version 1.1;
proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ services:
retries: 3
gateway:
build:
context: .
dockerfile: proxy.Dockerfile
context: devProxy
dockerfile: Dockerfile
ports:
- "8000:80"
networks:
Expand Down
8 changes: 0 additions & 8 deletions proxy.Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions proxy.nginx.conf

This file was deleted.

0 comments on commit 79055b5

Please sign in to comment.