diff --git a/.env.example b/.env.example index 354fa3a..6621bba 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,6 @@ LOG_DB_QUERIES=true ACCESS_SECRET=devaccesssecret -FILE_STORAGE_PATH=/ +FILE_STORAGE_PATH=./dev/upload ENABLE_ACCESS_LOG=true diff --git a/Makefile b/Makefile index 30dad27..911ae20 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,8 @@ generate: go generate ./... + +docker-compose-up: + docker-compose up --detach + +docker-compose-down: + docker-compose down \ No newline at end of file diff --git a/README.md b/README.md index 8b1a2b6..bce07e1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/dev/.gitignore b/dev/.gitignore new file mode 100644 index 0000000..514f4b7 --- /dev/null +++ b/dev/.gitignore @@ -0,0 +1,2 @@ +./upload +./pgdata \ No newline at end of file diff --git a/dev/nginx.conf b/dev/nginx.conf new file mode 100644 index 0000000..18745cf --- /dev/null +++ b/dev/nginx.conf @@ -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; + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0382753 --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file