-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgo_create.sh
More file actions
executable file
·110 lines (86 loc) · 2.34 KB
/
Copy pathgo_create.sh
File metadata and controls
executable file
·110 lines (86 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# ================================================
# setup_go_microservice.sh
# 建立 microservice_container/go-nim-service 專案骨架
# ================================================
set -e
# === 建立目錄結構 ===
mkdir -p microservice_container/go-nim-service
cd microservice_container/go-nim-service
# === main.go ===
cat <<'EOF' > main.go
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
// HealthCheck 回傳服務狀態
func healthCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{
"status": "ok",
})
}
// Protein Folding 模擬端點
func foldProtein(w http.ResponseWriter, r *http.Request) {
var input map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
result := map[string]string{
"sequence": fmt.Sprintf("%v", input["sequence"]),
"structure": "mock_structure_xyz",
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(result)
}
func main() {
http.HandleFunc("/health", healthCheck)
http.HandleFunc("/fold", foldProtein)
fmt.Println("🚀 Go NIM Service running at http://0.0.0.0:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
EOF
# === go.mod ===
cat <<'EOF' > go.mod
module go-nim-service
go 1.22
EOF
# === Dockerfile ===
cat <<'EOF' > Dockerfile
# === Build Stage ===
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o ai-med-service main.go
# === Run Stage ===
FROM alpine:3.19
WORKDIR /app
COPY --from=builder /app/ai-med-service .
CMD ["./ai-med-service"]
EOF
# === build.sh ===
cat <<'EOF' > build.sh
#!/bin/bash
# build.sh - 自動化建置 & 推送 Go NIM Service 容器
set -e
IMAGE_NAME="go-nim-service"
TAG="latest"
DOCKER_USER="your-dockerhub-username" # ⚠️ 改成你自己的帳號
echo "🚀 建立 Docker 映像檔..."
docker build -t $DOCKER_USER/$IMAGE_NAME:$TAG .
echo "🔑 登入 Docker Registry..."
docker login
echo "⬆️ 推送映像檔到 Registry..."
docker push $DOCKER_USER/$IMAGE_NAME:$TAG
echo "✅ 完成!執行方式:"
echo "docker run --rm -it $DOCKER_USER/$IMAGE_NAME:$TAG"
EOF
chmod +x build.sh
cd ../..
echo "✅ microservice_container/go-nim-service 已建立完成!"