Skip to content

Commit c7e5a20

Browse files
committed
Migrated HTTP server to docker
1 parent 8d13272 commit c7e5a20

File tree

3 files changed

+230
-156
lines changed

3 files changed

+230
-156
lines changed

Dockerfile.http

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Step 1: Use an official Go image to build the Go application
2+
FROM golang:1.22-alpine AS builder
3+
4+
# Step 2: Set the working directory inside the container
5+
WORKDIR /app
6+
7+
# Step 3: Copy the Go modules and dependencies
8+
COPY ./server/. ./
9+
10+
# Step 4: Download necessary Go dependencies
11+
RUN go mod download
12+
13+
# Step 6: Build the Go application
14+
RUN go build -ldflags="-s -w" -o tabletopper .
15+
16+
# Step 7: Create a small image to run the application
17+
FROM alpine:latest
18+
19+
# Step 8: Set the working directory in the final image
20+
WORKDIR /root/
21+
22+
# Step 9: Copy the Go binary from the builder stage
23+
COPY --from=builder /app/tabletopper .
24+
25+
COPY ./server/views ./views
26+
27+
COPY ./client/public ./public
28+
29+
# Step 10: Expose the port that the app will run on
30+
EXPOSE 3000
31+
32+
# Step 11: Command to run the Go app
33+
CMD ["./tabletopper"]

compose.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
services:
2+
reverse-proxy:
3+
image: traefik:v3.1
4+
command:
5+
- "--providers.docker"
6+
ports:
7+
- "80:80"
8+
volumes:
9+
- /var/run/docker.sock:/var/run/docker.sock
10+
networks:
11+
- app-network
12+
tabletopper:
13+
build:
14+
context: ./
15+
dockerfile: Dockerfile.http
16+
labels:
17+
- "traefik.http.routers.tabletopper.rule=Host(`tabletopper.local`)"
18+
volumes:
19+
- .:/app
20+
env_file: "./server/.env"
21+
depends_on:
22+
- mysql
23+
- reverse-proxy
24+
- redis
25+
networks:
26+
- app-network
27+
mysql:
28+
image: mysql:8.0
29+
environment:
30+
MYSQL_ROOT_PASSWORD: "password"
31+
MYSQL_DATABASE: "tabletopper"
32+
MYSQL_USER: "ttadmin"
33+
MYSQL_PASSWORD: "password"
34+
volumes:
35+
- mysql_data:/var/lib/mysql
36+
ports:
37+
- "3306:3306"
38+
networks:
39+
- app-network
40+
redis:
41+
image: redis:7
42+
ports:
43+
- "6379:6379"
44+
volumes:
45+
- redis-data:/data
46+
volumes:
47+
mysql_data:
48+
redis-data:
49+
networks:
50+
app-network:
51+
driver: bridge
52+

0 commit comments

Comments
 (0)