Luisnguyen1 commited on
Commit
8c70e0b
·
1 Parent(s): 85bce53

them dockerfile chay backend golang

Browse files
Files changed (5) hide show
  1. .env +0 -1
  2. Dockerfile +26 -8
  3. public/index.html +1 -1
  4. public/join.html +1 -1
  5. public/js/room.js +1 -1
.env CHANGED
@@ -1,5 +1,4 @@
1
  PORT=50000
2
- DEBUG=false
3
  DEBUG=true
4
  NODE_ENV='development'
5
 
 
1
  PORT=50000
 
2
  DEBUG=true
3
  NODE_ENV='development'
4
 
Dockerfile CHANGED
@@ -1,23 +1,41 @@
1
- FROM node:16-slim
2
 
3
  # Set working directory
4
  WORKDIR /app
5
 
6
- # Copy package files
7
- COPY package*.json ./
8
 
9
- # Install dependencies
10
- RUN npm install
11
 
12
- # Copy project files
13
  COPY . .
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # Expose port
16
  EXPOSE 7860
17
 
18
  # Set environment variables
19
  ENV PORT=7860
20
  ENV HOST=0.0.0.0
 
21
 
22
- # Start the application
23
- CMD ["node", "index.js"]
 
1
+ FROM golang:1.21-bullseye AS builder
2
 
3
  # Set working directory
4
  WORKDIR /app
5
 
6
+ # Copy go.mod and go.sum files
7
+ COPY go.mod go.sum ./
8
 
9
+ # Download dependencies
10
+ RUN go mod download
11
 
12
+ # Copy the source code
13
  COPY . .
14
 
15
+ # Build the application
16
+ RUN CGO_ENABLED=0 GOOS=linux go build -o bebank-server main.go
17
+
18
+ # Use a smaller base image for the final image
19
+ FROM alpine:3.18
20
+
21
+ # Add CA certificates for HTTPS support
22
+ RUN apk --no-cache add ca-certificates
23
+
24
+ WORKDIR /app
25
+
26
+ # Copy the binary from the builder stage
27
+ COPY --from=builder /app/bebank-server .
28
+ # Copy any static files or configurations
29
+ COPY --from=builder /app/.env .
30
+ COPY --from=builder /app/public ./public
31
+
32
  # Expose port
33
  EXPOSE 7860
34
 
35
  # Set environment variables
36
  ENV PORT=7860
37
  ENV HOST=0.0.0.0
38
+ ENV GIN_MODE=release
39
 
40
+ # Run the binary
41
+ CMD ["./bebank-server"]
public/index.html CHANGED
@@ -217,7 +217,7 @@
217
  backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
218
  websocketUrl: isLocalhost
219
  ? 'ws://localhost:50000/ws'
220
- : currentUrl.replace('http', 'ws').replace('https', 'wss')
221
  };
222
 
223
  console.log('Using endpoints:', config);
 
217
  backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
218
  websocketUrl: isLocalhost
219
  ? 'ws://localhost:50000/ws'
220
+ : currentUrl.replace('http', 'ws').replace('https', 'wss') + '/ws'
221
  };
222
 
223
  console.log('Using endpoints:', config);
public/join.html CHANGED
@@ -155,7 +155,7 @@
155
  backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
156
  websocketUrl: isLocalhost
157
  ? 'ws://localhost:50000/ws'
158
- : currentUrl.replace('http', 'ws').replace('https', 'wss')
159
  };
160
  const baseAPI = isLocalhost ? 'http://localhost:50000' : currentUrl;
161
  const calls = new CloudflareCalls(config);
 
155
  backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
156
  websocketUrl: isLocalhost
157
  ? 'ws://localhost:50000/ws'
158
+ : currentUrl.replace('http', 'ws').replace('https', 'wss') + '/ws'
159
  };
160
  const baseAPI = isLocalhost ? 'http://localhost:50000' : currentUrl;
161
  const calls = new CloudflareCalls(config);
public/js/room.js CHANGED
@@ -9,7 +9,7 @@ const config = {
9
  backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
10
  websocketUrl: isLocalhost
11
  ? 'ws://localhost:50000/ws'
12
- : currentUrl.replace('http', 'ws').replace('https', 'wss')
13
  };
14
  const baseAPI = isLocalhost ? 'http://localhost:50000' : currentUrl;
15
  const calls = new CloudflareCalls(config);
 
9
  backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
10
  websocketUrl: isLocalhost
11
  ? 'ws://localhost:50000/ws'
12
+ : currentUrl.replace('http', 'ws').replace('https', 'wss') + '/ws'
13
  };
14
  const baseAPI = isLocalhost ? 'http://localhost:50000' : currentUrl;
15
  const calls = new CloudflareCalls(config);