Skip to content

Commit

Permalink
feat: update devops config
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Feb 22, 2024
1 parent 6aa377e commit 4272a55
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 48 deletions.
3 changes: 1 addition & 2 deletions .env
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export POSTGRES_PASS=""
export IP_NODE=$(hostname)
export IP_V4_ADDRESS=$(hostname)

export SECRET_KEY_BASE=cyqpgMlaL59EKA4OQMFYT7JksQ6vTYMY
export DATABASE_URL=postgresql://zoedsoupe@localhost:5432/rinha_dev
export DATABASE_INFO="host=localhost port=5432 user=$POSTGRES_USER password=$POSTGRES_PASS dbname=rinha_dev sslmode=disable"
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Define variables
TAG=ghcr.io/cciuenf/rinha-backend-2024-q1

# Default target
all: build

# Build the Docker image
build:
docker build -t $(TAG) .

# Run the application
run:
docker compose down && docker build -t $(TAG) . && docker compose up

# Publish the Docker image
publish:
docker build -t $(TAG) . && docker push $(TAG)

# Use .PHONY to specify that these are not file names
.PHONY: build run publish
39 changes: 0 additions & 39 deletions config/init.sql

This file was deleted.

10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
image: ghcr.io/cciuenf/rinha-backend-2024-q1:latest
hostname: api01
environment:
- PORT=4000
- DATABASE_URL=postgresql://postgres:postgres@db:5432/rinha
- IP_V4_ADDRESS=192.0.1.11
- IP_NODE=192.0.1.12
Expand All @@ -27,19 +28,20 @@ services:
<<: *api
hostname: api02
environment:
- PORT=4001
- DATABASE_URL=postgresql://postgres:postgres@db:5432/rinha
- IP_V4_ADDRESS=192.0.1.12
- IP_NODE=192.0.1.11
ports:
- "4000:4001"
- "4001:4001"
networks:
erlcluster:
ipv4_address: 192.0.1.12

nginx:
image: nginx:latest
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf:ro
- ./setup/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api01
- api02
Expand All @@ -64,8 +66,8 @@ services:
ports:
- "5432:5432"
volumes:
- ./config/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./config/postgresql.conf:/etc/postgresql/postgresql.conf
- ./setup/init.sql:/docker-entrypoint-initdb.d/init.sql
- ./setup/postgresql.conf:/etc/postgresql/postgresql.conf
command: postgres -c config_file=/etc/postgresql/postgresql.conf
deploy:
resources:
Expand Down
27 changes: 27 additions & 0 deletions setup/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
max_limit INTEGER NOT NULL,
balance INTEGER CHECK (balance >= -max_limit) NOT NULL
);

CREATE TABLE transactions(
id SERIAL PRIMARY KEY,
value INTEGER NOT NULL,
customer_id INTEGER REFERENCES customers(id),
type VARCHAR(1) CHECK (type IN ('c', 'd')) NOT NULL,
description VARCHAR(10) NOT NULL,
created_at TIMESTAMP DEFAULT now() NOT NULL
);

DO $$
BEGIN
INSERT INTO customers (name, max_limit, balance)
VALUES
('o barato sai caro', 1000 * 100, 0),
('zan corp ltda', 800 * 100, 0),
('les cruders', 10000 * 100, 0),
('padaria joia de cocaia', 100000 * 100, 0),
('kid mais', 5000 * 100, 0);
END;
$$;
6 changes: 5 additions & 1 deletion config/nginx.conf → setup/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
worker_processes auto;

events {
worker_connections 1000;
}

http {
access_log off;
sendfile on;
sendfile off;
error_log /dev/null;

upstream api {
keepalive 128;
server api01:4000;
server api02:4001;
}
Expand Down
7 changes: 5 additions & 2 deletions config/postgresql.conf → setup/postgresql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
listen_addresses = '*'

# RESOURCE USAGE
max_connections = 30
max_connections = 300
shared_buffers = 35MB
# max_wal_size = 2MB


# QUERY TUNING
random_page_cost = 1.1
effective_io_concurrency = 30
effective_io_concurrency = 30

0 comments on commit 4272a55

Please sign in to comment.