Skip to content

Commit 5f06a5f

Browse files
authored
Merge pull request #3 from relaxgameing/issue/#1
Dockerized the project
2 parents e94121f + ecfa1e4 commit 5f06a5f

File tree

10 files changed

+117
-43
lines changed

10 files changed

+117
-43
lines changed

client/.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Dockerfile
2+
.dockerignore
3+
.gitignore
4+
.git
5+
README.md
6+
frontend.dockerfile
7+
8+
build
9+
node_modules

client/client.dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:alpine3.19
2+
3+
WORKDIR /app
4+
5+
COPY client/package*.json ./
6+
7+
RUN npm install --ignore-platform
8+
9+
COPY client/ .
10+
11+
EXPOSE 5173
12+
13+
CMD [ "npm" , "run" , "dev" ]

client/package.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
{
2-
"name": "client",
3-
"private": true,
4-
"version": "0.0.0",
5-
"type": "module",
6-
"scripts": {
7-
"dev": "vite",
8-
"build": "tsc -b && vite build",
9-
"lint": "eslint .",
10-
"preview": "vite preview"
11-
},
12-
"dependencies": {
13-
"@chakra-ui/react": "^2.10.3",
14-
"@emotion/react": "^11.13.3",
15-
"@emotion/styled": "^11.13.0",
16-
"@tanstack/react-query": "^5.59.15",
17-
"framer-motion": "^11.11.9",
18-
"react": "^18.3.1",
19-
"react-dom": "^18.3.1",
20-
"react-icons": "^5.3.0"
21-
},
22-
"devDependencies": {
23-
"@eslint/js": "^9.11.1",
24-
"@types/react": "^18.3.10",
25-
"@types/react-dom": "^18.3.0",
26-
"@vitejs/plugin-react": "^4.3.2",
27-
"eslint": "^9.11.1",
28-
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
29-
"eslint-plugin-react-refresh": "^0.4.12",
30-
"globals": "^15.9.0",
31-
"typescript": "^5.5.3",
32-
"typescript-eslint": "^8.7.0",
33-
"vite": "^5.4.8"
34-
}
2+
"name": "client",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite --host",
8+
"build": "tsc -b && vite build",
9+
"lint": "eslint .",
10+
"preview": "vite preview"
11+
},
12+
"dependencies": {
13+
"@chakra-ui/react": "^2.10.3",
14+
"@emotion/react": "^11.13.3",
15+
"@emotion/styled": "^11.13.0",
16+
"@tanstack/react-query": "^5.59.15",
17+
"framer-motion": "^11.11.9",
18+
"react": "^18.3.1",
19+
"react-dom": "^18.3.1",
20+
"react-icons": "^5.3.0"
21+
},
22+
"devDependencies": {
23+
"@eslint/js": "^9.11.1",
24+
"@types/react": "^18.3.10",
25+
"@types/react-dom": "^18.3.0",
26+
"@vitejs/plugin-react": "^4.3.2",
27+
"eslint": "^9.11.1",
28+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
29+
"eslint-plugin-react-refresh": "^0.4.12",
30+
"globals": "^15.9.0",
31+
"typescript": "^5.5.3",
32+
"typescript-eslint": "^8.7.0",
33+
"vite": "^5.4.8"
34+
}
3535
}

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
backend:
3+
container_name: go-server
4+
build:
5+
context: .
6+
dockerfile: server/server.dockerfile
7+
environment:
8+
MONGODB_URI: <db_connection_string>
9+
PORT: "5000"
10+
ENV: production
11+
ports:
12+
- "5000:5000"
13+
14+
healthcheck:
15+
interval: 2s
16+
test: "exit 0"
17+
18+
frontend:
19+
container_name: react-frontend
20+
build:
21+
context: .
22+
dockerfile: client/client.dockerfile
23+
24+
ports:
25+
- "5173:5173"
26+
depends_on:
27+
backend:
28+
condition: service_healthy

server/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tmp
2+
backend.dockerfile
3+
.dockerignore
File renamed without changes.

go.mod renamed to server/go.mod

File renamed without changes.

go.sum renamed to server/go.sum

File renamed without changes.

main.go renamed to server/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88

99
"github.com/gofiber/fiber/v2"
10-
"github.com/joho/godotenv"
10+
"github.com/gofiber/fiber/v2/middleware/cors"
1111
"go.mongodb.org/mongo-driver/bson"
1212
"go.mongodb.org/mongo-driver/bson/primitive"
1313
"go.mongodb.org/mongo-driver/mongo"
@@ -27,10 +27,10 @@ func main() {
2727

2828
if os.Getenv("ENV") != "production" {
2929
// Load the .env file if not in production
30-
err := godotenv.Load(".env")
31-
if err != nil {
32-
log.Fatal("Error loading .env file:", err)
33-
}
30+
// err := godotenv.Load(".env")
31+
// if err != nil {
32+
// log.Fatal("Error loading .env file:", err)
33+
// }
3434
}
3535

3636
MONGODB_URI := os.Getenv("MONGODB_URI")
@@ -54,10 +54,10 @@ func main() {
5454

5555
app := fiber.New()
5656

57-
// app.Use(cors.New(cors.Config{
58-
// AllowOrigins: "http://localhost:5173",
59-
// AllowHeaders: "Origin,Content-Type,Accept",
60-
// }))
57+
app.Use(cors.New(cors.Config{
58+
AllowOrigins: "http://localhost:5173",
59+
AllowHeaders: "Origin,Content-Type,Accept",
60+
}))
6161

6262
app.Get("/api/todos", getTodos)
6363
app.Post("/api/todos", createTodo)
@@ -70,7 +70,7 @@ func main() {
7070
}
7171

7272
if os.Getenv("ENV") == "production" {
73-
app.Static("/", "./client/dist")
73+
app.Static("/", "./dist")
7474
}
7575

7676
log.Fatal(app.Listen("0.0.0.0:" + port))

server/server.dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# use official Golang image
2+
FROM golang:alpine3.20
3+
4+
# set working directory
5+
WORKDIR /app
6+
RUN mkdir dist
7+
8+
# Copy the source code
9+
COPY server/ .
10+
COPY client/dist ./dist
11+
# Download and install the dependencies
12+
RUN go mod tidy
13+
14+
# Build the Go app
15+
RUN go build -o todoApp .
16+
17+
#EXPOSE the port
18+
EXPOSE 5000
19+
20+
# Run the executable
21+
CMD ["./todoApp"]

0 commit comments

Comments
 (0)