feat: Add a compose file
This commit is contained in:
		
							parent
							
								
									ded5e4ecfa
								
							
						
					
					
						commit
						5d38f46aeb
					
				
							
								
								
									
										6
									
								
								backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					FROM drop:alpine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN apk add --no-cache nodejs
 | 
				
			||||||
 | 
					ADD bundle.js /home/cuser/bundle.js
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ENTRYPOINT ["/usr/local/bin/drop", "/usr/bin/node", "/home/cuser/bundle.js"]
 | 
				
			||||||
@ -14,3 +14,6 @@ dev:
 | 
				
			|||||||
.PHONY: start
 | 
					.PHONY: start
 | 
				
			||||||
start: dev
 | 
					start: dev
 | 
				
			||||||
	node dist/bundle.js
 | 
						node dist/bundle.js
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dockerfile: dist/bundle.js
 | 
				
			||||||
 | 
						sudo docker build -t lateinicus/server -f Dockerfile dist/
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										23
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
								
							@ -23,6 +23,15 @@
 | 
				
			|||||||
                "@types/node": "*"
 | 
					                "@types/node": "*"
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        "@types/cors": {
 | 
				
			||||||
 | 
					            "version": "2.8.4",
 | 
				
			||||||
 | 
					            "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.4.tgz",
 | 
				
			||||||
 | 
					            "integrity": "sha512-ipZjBVsm2tF/n8qFGOuGBkUij9X9ZswVi9G3bx/6dz7POpVa6gVHcj1wsX/LVEn9MMF41fxK/PnZPPoTD1UFPw==",
 | 
				
			||||||
 | 
					            "dev": true,
 | 
				
			||||||
 | 
					            "requires": {
 | 
				
			||||||
 | 
					                "@types/express": "*"
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        "@types/events": {
 | 
					        "@types/events": {
 | 
				
			||||||
            "version": "1.2.0",
 | 
					            "version": "1.2.0",
 | 
				
			||||||
            "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
 | 
					            "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
 | 
				
			||||||
@ -1001,6 +1010,15 @@
 | 
				
			|||||||
            "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
 | 
					            "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
 | 
				
			||||||
            "dev": true
 | 
					            "dev": true
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        "cors": {
 | 
				
			||||||
 | 
					            "version": "2.8.4",
 | 
				
			||||||
 | 
					            "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz",
 | 
				
			||||||
 | 
					            "integrity": "sha1-K9OB8usgECAQXNUOpZ2mMJBpRoY=",
 | 
				
			||||||
 | 
					            "requires": {
 | 
				
			||||||
 | 
					                "object-assign": "^4",
 | 
				
			||||||
 | 
					                "vary": "^1"
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        "create-ecdh": {
 | 
					        "create-ecdh": {
 | 
				
			||||||
            "version": "4.0.3",
 | 
					            "version": "4.0.3",
 | 
				
			||||||
            "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz",
 | 
					            "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz",
 | 
				
			||||||
@ -3068,6 +3086,11 @@
 | 
				
			|||||||
            "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
 | 
					            "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
 | 
				
			||||||
            "dev": true
 | 
					            "dev": true
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        "object-assign": {
 | 
				
			||||||
 | 
					            "version": "4.1.1",
 | 
				
			||||||
 | 
					            "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
 | 
				
			||||||
 | 
					            "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        "object-copy": {
 | 
					        "object-copy": {
 | 
				
			||||||
            "version": "0.1.0",
 | 
					            "version": "0.1.0",
 | 
				
			||||||
            "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz",
 | 
					            "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz",
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,12 @@
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    "homepage": "https://gitlab.com/Polynomdivision/lateinicusserver#readme",
 | 
					    "homepage": "https://gitlab.com/Polynomdivision/lateinicusserver#readme",
 | 
				
			||||||
    "dependencies": {
 | 
					    "dependencies": {
 | 
				
			||||||
        "express": "4.16.3",
 | 
					        "body-parser": "1.18.3",
 | 
				
			||||||
        "body-parser": "1.18.3"
 | 
					        "cors": "^2.8.4",
 | 
				
			||||||
 | 
					        "express": "4.16.3"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "devDependencies": {
 | 
					    "devDependencies": {
 | 
				
			||||||
 | 
					        "@types/cors": "^2.8.4",
 | 
				
			||||||
        "@types/express": "4.16.0",
 | 
					        "@types/express": "4.16.0",
 | 
				
			||||||
        "ts-loader": "^5.1.1",
 | 
					        "ts-loader": "^5.1.1",
 | 
				
			||||||
        "typescript": "3.0.3",
 | 
					        "typescript": "3.0.3",
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
import * as express from "express";
 | 
					import * as express from "express";
 | 
				
			||||||
 | 
					import * as cors from "cors";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import * as bodyparser from "body-parser";
 | 
					import * as bodyparser from "body-parser";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -34,12 +35,13 @@ authRouter.use(async (req, res, next) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					const app = express();
 | 
				
			||||||
app.use(bodyparser.json());
 | 
					app.use(bodyparser.json());
 | 
				
			||||||
app.use((req, res, next) => {
 | 
					// app.use((req, res, next) => {
 | 
				
			||||||
    // TODO: Change this to our domain
 | 
					//     // TODO: Change this to our domain
 | 
				
			||||||
    res.append("Access-Control-Allow-Origin", "*");
 | 
					//     res.append("Access-Control-Allow-Origin", "*");
 | 
				
			||||||
    res.append("Access-Control-Allow-Headers", "Content-Type,Token");
 | 
					//     res.append("Access-Control-Allow-Headers", "Content-Type,Token");
 | 
				
			||||||
    next();
 | 
					//     next();
 | 
				
			||||||
});
 | 
					// });
 | 
				
			||||||
 | 
					app.options("*", cors());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.use("/api/level", LevelRouter);
 | 
					app.use("/api/level", LevelRouter);
 | 
				
			||||||
app.use("/api/class", ClassRouter);
 | 
					app.use("/api/class", ClassRouter);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										51
									
								
								compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								compose.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
				
			|||||||
 | 
					version: "3.6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					services:
 | 
				
			||||||
 | 
					  # db:
 | 
				
			||||||
 | 
					  #   image: mongo:4.1.3-xenial
 | 
				
			||||||
 | 
					  #   expose:
 | 
				
			||||||
 | 
					  #     - "27017"
 | 
				
			||||||
 | 
					  #   networks:
 | 
				
			||||||
 | 
					  #     backend:
 | 
				
			||||||
 | 
					  #       ipv4_address: 128.1.0.2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  backend:
 | 
				
			||||||
 | 
					    image: lateinicus/server
 | 
				
			||||||
 | 
					    expose:
 | 
				
			||||||
 | 
					      - "8080"
 | 
				
			||||||
 | 
					    # depends_on:
 | 
				
			||||||
 | 
					    #   - db
 | 
				
			||||||
 | 
					    networks:
 | 
				
			||||||
 | 
					      backend:
 | 
				
			||||||
 | 
					        ipv4_address: 128.1.0.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  proxy:
 | 
				
			||||||
 | 
					    image: nginx:1.15.4-alpine
 | 
				
			||||||
 | 
					    ports:
 | 
				
			||||||
 | 
					      - "80:80"
 | 
				
			||||||
 | 
					      - "443:443"
 | 
				
			||||||
 | 
					    networks:
 | 
				
			||||||
 | 
					      - outside
 | 
				
			||||||
 | 
					      - backend
 | 
				
			||||||
 | 
					    volumes:
 | 
				
			||||||
 | 
					      # TODO: DEBUG
 | 
				
			||||||
 | 
					      - ./server/nginx.conf:/etc/nginx/nginx.conf:ro
 | 
				
			||||||
 | 
					      - ./frontend/dist/:/srv/www/:ro
 | 
				
			||||||
 | 
					    depends_on:
 | 
				
			||||||
 | 
					      - backend
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# The outside network is needed to only expose the reverse
 | 
				
			||||||
 | 
					# proxy to the outside
 | 
				
			||||||
 | 
					networks:
 | 
				
			||||||
 | 
					  backend:
 | 
				
			||||||
 | 
					    driver: bridge
 | 
				
			||||||
 | 
					    internal: yes
 | 
				
			||||||
 | 
					    driver_opts:
 | 
				
			||||||
 | 
					      com.docker.network.bridge.name: 'backend'
 | 
				
			||||||
 | 
					    ipam:
 | 
				
			||||||
 | 
					      driver: default
 | 
				
			||||||
 | 
					      config:
 | 
				
			||||||
 | 
					        - subnet: 128.1.0.0/8
 | 
				
			||||||
 | 
					  outside:
 | 
				
			||||||
 | 
					    driver: bridge
 | 
				
			||||||
@ -17,7 +17,7 @@ watch: node_modules
 | 
				
			|||||||
.PHONY: build
 | 
					.PHONY: build
 | 
				
			||||||
build: node_modules dist/minified
 | 
					build: node_modules dist/minified
 | 
				
			||||||
	@echo Building with parcel
 | 
						@echo Building with parcel
 | 
				
			||||||
	./node_modules/.bin/parcel build src/index.html
 | 
						./node_modules/.bin/parcel build --out-dir dist/app src/index.html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@echo Minifying
 | 
						@echo Minifying
 | 
				
			||||||
	$(foreach file, $(wildcard dist/*.js), $(call minify, $(file)))
 | 
						$(foreach file, $(wildcard dist/*.js), $(call minify, $(file)))
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										37
									
								
								server/nginx.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								server/nginx.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					events {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					http {
 | 
				
			||||||
 | 
					     # Log warnings
 | 
				
			||||||
 | 
					     #error_log /var/log/nginx.log warn;
 | 
				
			||||||
 | 
					     # TODO: Remove
 | 
				
			||||||
 | 
					     error_log /dev/stdout info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     # No idea, but nginx refuses to start without it
 | 
				
			||||||
 | 
					     server_names_hash_bucket_size 64;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					     # The actual webserver duties
 | 
				
			||||||
 | 
					     server {
 | 
				
			||||||
 | 
					            # server_name lateinicus;
 | 
				
			||||||
 | 
					            listen 80 default_server;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Reverse Proxy
 | 
				
			||||||
 | 
					            location /api/ {
 | 
				
			||||||
 | 
					                     # Seems weird, but it is (Prevent /api/api/)
 | 
				
			||||||
 | 
					                     rewrite /api/(.*) /api/$1 break;
 | 
				
			||||||
 | 
					                     proxy_set_header Host $host;
 | 
				
			||||||
 | 
					                     proxy_set_header X-Real-IP $remote_addr;
 | 
				
			||||||
 | 
					                     proxy_pass http://128.1.0.3:8080;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # The web app
 | 
				
			||||||
 | 
					            location /app/ {
 | 
				
			||||||
 | 
					                     # CSS might not get the correct Content-Type header
 | 
				
			||||||
 | 
					                     include  /etc/nginx/mime.types;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                     root /srv/www;
 | 
				
			||||||
 | 
					                     # For react-router
 | 
				
			||||||
 | 
					                     try_files $uri /app/index.html;
 | 
				
			||||||
 | 
					                     index index.html;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					     }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user