Skip to content

Commit bb4ce57

Browse files
Add bare metal deployment setup
1 parent da94bf2 commit bb4ce57

5 files changed

Lines changed: 107 additions & 3 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea/
2-
randoms/
2+
randoms/
3+
deployment/
4+
.vagrant/

Vagrantfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "hashicorp/bionic64"
3+
4+
config.vm.synced_folder ".", "/home/vagrant/app"
5+
6+
config.vm.provision :shell, path: "vagrant_setup_dep.sh"
7+
8+
config.vm.provision :shell, inline: <<-SHELL
9+
sudo su - vagrant -c "cd /home/vagrant/app && make docker-up"
10+
SHELL
11+
12+
config.vm.network "forwarded_port", guest: 8007, host: 8004
13+
end

docker-compose.yaml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ services:
5454
networks:
5555
- buzz_network
5656

57-
api:
58-
container_name: buzz
57+
api_1:
5958
restart: always
6059
build:
6160
context: .
@@ -79,6 +78,42 @@ services:
7978
networks:
8079
- buzz_network
8180

81+
api_2:
82+
restart: always
83+
build:
84+
context: .
85+
dockerfile: Dockerfile
86+
ports:
87+
- "8004:8004"
88+
depends_on:
89+
- mysql_db
90+
- mysql_db_go_migrate
91+
- redis
92+
environment:
93+
- BUZZ_HTTP_HOST=0.0.0.0
94+
- BUZZ_HTTP_PORT=8003
95+
- BUZZ_DEBUG=true
96+
- BUZZ_DATABASE_URL=mysql://user:password@mysql_db:3306/buzz
97+
- BUZZ_REDIS_URL=redis://redis:6379
98+
- BUZZ_JWT_KEY=wTkjqFUqqDpUGinAJqHZ
99+
- BUZZ_PASSWORD_HASHER_SALT=wTkjqFUqqDpUGinAJqHZ
100+
- BUZZ_FAKE_USER_PASSWORD=password123
101+
- BUZZ_SEED_USERS=true
102+
networks:
103+
- buzz_network
104+
105+
load_balancer:
106+
image: nginx:alpine
107+
depends_on:
108+
- api_1
109+
- api_2
110+
ports:
111+
- "8007:80"
112+
volumes:
113+
- ./nginx/load_balancer.conf:/etc/nginx/conf.d/default.conf:ro
114+
networks:
115+
- buzz_network
116+
82117
volumes:
83118
mysql-data:
84119
driver: local

nginx/load_balancer.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
upstream backend_app {
2+
server api_1:8003;
3+
server api_2:8004;
4+
}
5+
6+
server {
7+
listen 80;
8+
server_name buzz.app;
9+
10+
location / {
11+
proxy_pass http://backend_app;
12+
proxy_set_header Host $host;
13+
proxy_set_header X-Real-IP $remote_addr;
14+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15+
}
16+
}

vagrant_setup_dep.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Update package lists
6+
sudo apt-get update -y
7+
8+
# Install required packages
9+
sudo apt-get install -y \
10+
apt-transport-https \
11+
ca-certificates \
12+
curl \
13+
gnupg \
14+
lsb-release \
15+
make
16+
17+
# Add Docker’s official GPG key
18+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor \
19+
-o /usr/share/keyrings/docker-archive-keyring.gpg
20+
21+
# Set up the stable repository
22+
echo \
23+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
24+
https://download.docker.com/linux/ubuntu \
25+
$(lsb_release -cs) \
26+
stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
27+
28+
# Install Docker Engine
29+
sudo apt-get update -y
30+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
31+
32+
# Install Docker Compose plugin (official CLI plugin approach)
33+
sudo apt-get install -y docker-compose-plugin
34+
35+
# Optionally add the 'vagrant' user to the 'docker' group for non-root docker usage
36+
sudo usermod -aG docker vagrant
37+
38+
echo "Docker and Docker Compose installed successfully!"

0 commit comments

Comments
 (0)