Skip to content

Commit f9fe266

Browse files
committed
update files to run via docker compose
1 parent bd313c3 commit f9fe266

File tree

6 files changed

+22
-39
lines changed

6 files changed

+22
-39
lines changed

backend/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
# backend/Dockerfile
2-
FROM golang:1.24 AS builder
1+
FROM golang:latest AS builder
32

43
# Set the Current Working Directory inside the container
54
WORKDIR /app
65

7-
# Copy go.mod and go.sum files first for caching dependencies
6+
# Copy go.mod and go.sum files for caching dependencies
87
COPY go.mod go.sum ./
98
RUN go mod download
109

1110
# Copy the source code
1211
COPY . .
1312

1413
# Build the Go app
15-
RUN go build -o main .\...
14+
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/api/*.go
1615

17-
# Start a new stage from scratch
18-
FROM gcr.io/distroless/base
16+
FROM scratch AS prod
1917

2018
# Copy the Pre-built binary file from the previous stage
2119
COPY --from=builder /app/main .

backend/cmd/api/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"github.com/joho/godotenv"
14+
// "github.com/joho/godotenv"
1515
)
1616

1717
func gracefulShutdown(apiServer *http.Server, done chan bool) {
@@ -32,10 +32,10 @@ func gracefulShutdown(apiServer *http.Server, done chan bool) {
3232
}
3333

3434
func main() {
35-
err := godotenv.Load()
36-
if err != nil {
37-
log.Fatalf("Error loading .env file: %s", err)
38-
}
35+
// err := godotenv.Load()
36+
// if err != nil {
37+
// log.Fatalf("Error loading .env file: %s", err)
38+
// }
3939

4040
config := config.GetConfig()
4141

backend/internals/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func GetConfig() *Config {
4242
)
4343

4444
config := Config{
45-
ServerPort: getStr("SERVER_PORT", ":8080"),
45+
ServerPort: getStr("SERVER_PORT", "8080"),
4646
DBURI: connStr,
4747
DBMaxOpenConns: getInt("DBMaxOpenConns", 30),
4848
DBMaxIdleConns: getInt("DBMaxIdleConns", 30),

docker-compose.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
2-
app:
2+
backend:
33
build:
44
context: ./backend
55
dockerfile: Dockerfile
@@ -8,9 +8,8 @@ services:
88
ports:
99
- ${SERVER_PORT}:${SERVER_PORT}
1010
environment:
11-
APP_ENV: ${APP_ENV}
1211
PORT: ${SERVER_PORT}
13-
DB_HOST: ${DB_HOST}
12+
DB_HOST: database
1413
DB_PORT: ${DB_PORT}
1514
DB_DATABASE_NAME: ${DB_DATABASE_NAME}
1615
DB_USER: ${DB_USER}
@@ -22,12 +21,12 @@ services:
2221
- dashnest_net
2322
frontend:
2423
build:
25-
context: .
24+
context: ./frontend
2625
dockerfile: Dockerfile
2726
target: frontend
2827
restart: unless-stopped
2928
depends_on:
30-
- app
29+
- backend
3130
ports:
3231
- 5173:5173
3332
networks:
@@ -42,8 +41,8 @@ services:
4241
ports:
4342
- "${DB_PORT}:5432"
4443
volumes:
45-
- dashnest_vol
46-
- ./backend/cmd/migrate/migrations:/docker-entrypoint-initdb.d
44+
- ./local_db_data:/var/lib/postgresql/data # Database data in local directory
45+
- ./backend/cmd/migrate/migrations:/docker-entrypoint-initdb.d # Migrations
4746
healthcheck:
4847
test: ["CMD-SHELL", "sh -c 'pg_isready -U ${DB_USER} -d ${DB_DATABASE_NAME}'"]
4948
interval: 5s
@@ -53,7 +52,5 @@ services:
5352
networks:
5453
- dashnest_net
5554

56-
volumes:
57-
dashnest_vol:
5855
networks:
59-
dashnest_net:
56+
dashnest_net:

frontend/Dockerfile

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
# frontend/Dockerfile
2-
FROM node:23 AS build
1+
FROM node:18-alpine AS frontend
32

4-
# Set the Current Working Directory inside the container
53
WORKDIR /app
64

7-
# Copy package.json and package-lock.json
8-
COPY package*.json ./
5+
COPY package.json .
96

10-
# Install the dependencies
117
RUN npm install
128

13-
# Copy the rest of the application code
149
COPY . .
1510

16-
# Build the application
17-
RUN npm run build
11+
EXPOSE 8080
1812

19-
# Serve the app with a lightweight HTTP server
20-
FROM nginx:alpine
21-
COPY --from=build /app/build /usr/share/nginx/html
22-
23-
# Expose the port the app runs on
24-
EXPOSE 80
25-
CMD ["nginx", "-g", "daemon off;"]
13+
CMD [ "npm", "run", "dev" ]

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite",
7+
"dev": "vite --host",
88
"build": "vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview"

0 commit comments

Comments
 (0)