[backend] add basic files for deploying and extending backend operations
This commit is contained in:
		
						commit
						83838a4ca4
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					**/*.env
 | 
				
			||||||
							
								
								
									
										20
									
								
								backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								backend/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					FROM alpine:latest AS build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN apk add python3
 | 
				
			||||||
 | 
					RUN mkdir /venv /app
 | 
				
			||||||
 | 
					RUN python3 -m venv /venv
 | 
				
			||||||
 | 
					ENV PATH="/venv/bin:$PATH"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN apk add build-base linux-headers musl-dev python3-dev libpq-dev
 | 
				
			||||||
 | 
					RUN pip3 install flask uwsgi psycopg2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#FROM alpine:latest AS prod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#RUN apk add python3
 | 
				
			||||||
 | 
					#ENV PATH="/venv/bin:$PATH"
 | 
				
			||||||
 | 
					#COPY --from=build /venv /venv
 | 
				
			||||||
 | 
					EXPOSE 9090/tcp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ENTRYPOINT ["uwsgi", "--http", ":9090", "--callable", "app", "--wsgi-file", "/app/main.py"]
 | 
				
			||||||
							
								
								
									
										8
									
								
								backend/docker-compose.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								backend/docker-compose.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					services:
 | 
				
			||||||
 | 
					  backend:
 | 
				
			||||||
 | 
					    build: .
 | 
				
			||||||
 | 
					    ports:
 | 
				
			||||||
 | 
					      - "80:9090"
 | 
				
			||||||
 | 
					    volumes:
 | 
				
			||||||
 | 
					      - "./src/:/app:ro"
 | 
				
			||||||
 | 
					    env_file: backend.env
 | 
				
			||||||
							
								
								
									
										28
									
								
								backend/src/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								backend/src/main.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					from flask import Flask
 | 
				
			||||||
 | 
					import psycopg2 as psql
 | 
				
			||||||
 | 
					from os import environ as env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = Flask(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					db_params = {
 | 
				
			||||||
 | 
					    'database': env.get('DB_NAME'),
 | 
				
			||||||
 | 
					    'user': env.get('DB_USER'),
 | 
				
			||||||
 | 
					    'password': env.get('DB_PASS'),
 | 
				
			||||||
 | 
					    'host': env.get('DB_HOST'),
 | 
				
			||||||
 | 
					    'port': int(env.get('DB_PORT'))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					db = psql.connect(**db_params)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route("/")
 | 
				
			||||||
 | 
					def test():
 | 
				
			||||||
 | 
					    c = db.cursor()
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        c.execute('SELECT * FROM movies')
 | 
				
			||||||
 | 
					    except Exception:
 | 
				
			||||||
 | 
					        db.rollback()
 | 
				
			||||||
 | 
					        return "Failed to fetch table 'movies'"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    res = c.fetchmany(10)
 | 
				
			||||||
 | 
					    c.close()
 | 
				
			||||||
 | 
					    return "<p>Hello, World! test data:<br>" + "<br>".join(str(i) for i in res) + "</p>"
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user