add docker-compose.yml, update README.md and .env.example, add two new commands to Makefile (docker-compose-up, docker-compose-down)

This commit is contained in:
Dawid Wysokiński 2021-11-01 08:20:42 +01:00
parent bc79e35cfe
commit 906b35a5e0
Signed by: Kichiyaki
GPG Key ID: EF14026D247EB867
6 changed files with 92 additions and 18 deletions

View File

@ -9,6 +9,6 @@ LOG_DB_QUERIES=true
ACCESS_SECRET=devaccesssecret
FILE_STORAGE_PATH=/
FILE_STORAGE_PATH=./dev/upload
ENABLE_ACCESS_LOG=true

View File

@ -1,2 +1,8 @@
generate:
go generate ./...
docker-compose-up:
docker-compose up --detach
docker-compose-down:
docker-compose down

View File

@ -6,26 +6,15 @@ This project contains the API and other core infrastructure items needed for all
### Prerequisites
1. Golang
2. PostgreSQL database
2. Docker + docker-compose
3. make
### Installation
**Required ENV variables (you can set them directly in your system or create the .env.local file):**
```
DB_USER=db_user
DB_NAME=db_name
DB_PORT=db_port
DB_HOST=db_host
DB_PASSWORD=db_pass
DB_POOL_SIZE=40
LOG_DB_QUERIES=true
ACCESS_SECRET=access_token_secret
FILE_STORAGE_PATH=path_to_the_folder_where_uploaded_files_will_be_stored
ENABLE_ACCESS_LOG=false
```
1. Clone this repo - ``git clone git@github.com:zdam-egzamin-zawodowy/backend.git``.
2. Set the required env variables.
3. Run the app - ``go run ./cmd/server/main.go``.
1. ``git clone git@github.com:zdam-egzamin-zawodowy/backend.git``.
2. ``cd backend && cp .env.example .env.local``
3. ``make docker-compose-up``
4. Run the app - ``go run ./cmd/server/main.go``.
## License
Distributed under the MIT License. See ``LICENSE`` for more information.

2
dev/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
./upload
./pgdata

51
dev/nginx.conf Normal file
View File

@ -0,0 +1,51 @@
# auto detects a good number of processes to run
worker_processes auto;
#Provides the configuration file context in which the directives that affect connection processing are specified.
events {
# Sets the maximum number of simultaneous connections that can be opened by a worker process.
worker_connections 8000;
# Tells the worker to accept multiple connections at a time
multi_accept on;
}
http {
# what times to include
include /etc/nginx/mime.types;
# what is the default one
default_type application/octet-stream;
# Sets the path, format, and configuration for a buffered log write
log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $upstream_addr '
'"$http_referer" "$http_user_agent"';
server {
# listen on port 80
listen 80;
# save logs here
access_log /var/log/nginx/access.log compression;
# where the root here
root /usr/share/nginx/html;
# Fonts and media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|ttf|webp)$ {
expires 1m;
add_header Cache-Control "public";
}
# Javascript and CSS files
location ~* \.(?:css|webmanifest|js|woff2|manifest)$ {
expires 1y;
add_header Cache-Control "public";
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to redirecting to index.html
try_files $uri $uri/ =404;
}
}
}

26
docker-compose.yml Normal file
View File

@ -0,0 +1,26 @@
version: '3.6'
services:
cdn:
image: nginx:alpine
volumes:
- ./dev/upload:/usr/share/nginx/html
- ./dev/nginx.conf:/etc/nginx/nginx.conf
ports:
- "9000:80"
environment:
- NGINX_PORT=80
restart: unless-stopped
zdamegzzawodowydb:
image: postgres:12.8
container_name: zdamegzzawodowydb
restart: unless-stopped
volumes:
- './dev/pgdata:/var/lib/postgresql/data'
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=zdamegzzawodowy
- POSTGRES_DB=zdamegzzawodowy
- TZ=UTC