作者 yangfu

初始化

# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
*.vscode
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.log
*debug
*wasm
*.idea
*.tmp
*.sum
opp
/vendor
/*.exe~
... ...
FROM golang:1.13 as builder
ENV GOPROXY https://goproxy.cn
ENV GO111MODULE on
ENV GOPATH /go
RUN git clone http://gitlab.fjmaimaimai.com/mmm-go/gocomm.git /go/src/gocomm \
&& cd /go/src/gocomm \
&& git pull
WORKDIR /go/src/opp-building
COPY go.mod .
COPY . .
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -o opp-building main.go
EXPOSE 8080
CMD ["./opp-building"]
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q mmmopp-building
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building service install success!"
else
echo "mmmopp-building service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building deployment install success!"
else
echo "mmmopp-building deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/mmm-go-opp/opp.yaml
kubectl -n mmm-suplus-dev get svc | grep -q mmmopp-building
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q mmmopp-building
done
kubectl -n mmm-suplus-dev get pods | grep -q mmmopp-building
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q mmmopp-building
done
kubectl create -f /tmp/dev/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: mmmopp-building
namespace: mmm-suplus-dev
labels:
k8s-app: mmmopp-building
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: mmmopp-building
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mmmopp-building
namespace: mmm-suplus-dev
labels:
k8s-app: mmmopp-building
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: mmmopp-building
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: mmmopp-building
image: 192.168.0.243:5000/mmm/mmmopp-building:dev
imagePullPolicy: Always
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- mountPath: /var/www/opp/file
name: mmmjihuitest-pvc1
ports:
- containerPort: 8080
env:
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.port
volumes:
- name: accesslogs
emptyDir: {}
- name: mmmjihuitest-pvc1
persistentVolumeClaim:
claimName: mmmjihuitest-pvc
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp-building
if [ "$?" == "1" ];then
kubectl create -f /tmp/prd/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building service install success!"
else
echo "mmmopp-building service install fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building deployment install success!"
else
echo "mmmopp-building deployment install fail!"
fi
else
kubectl delete -f /tmp/prd/mmm-go-opp/opp.yaml
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp-building
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp-building
done
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp-building
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-prd get pods | grep -q mmmopp-building
done
kubectl create -f /tmp/prd/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-prd get svc | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-prd get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: mmmopp-building
namespace: mmm-suplus-prd
labels:
k8s-app: mmmopp-building
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: mmmopp-building
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mmmopp-building
namespace: mmm-suplus-prd
labels:
k8s-app: mmmopp-building
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: mmmopp-building
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: mmmopp-building
image: 192.168.0.243:5000/mmm/mmmopp-building:master
imagePullPolicy: Always
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- mountPath: /var/www/opp/file
name: opportunity-pvc1
ports:
- containerPort: 8080
env:
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.host
- name: MYSQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: mysql.port
volumes:
- name: accesslogs
emptyDir: {}
- name: opportunity-pvc1
persistentVolumeClaim:
claimName: opportunity-pvc5
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q mmmopp-building
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building service install success!"
else
echo "mmmopp-building service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building deployment install success!"
else
echo "mmmopp-building deployment install fail!"
fi
else
kubectl delete -f /tmp/test/mmm-go-opp/opp.yaml
kubectl -n mmm-suplus-test get svc | grep -q mmmopp-building
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q mmmopp-building
done
kubectl -n mmm-suplus-test get pods | grep -q mmmopp-building
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q mmmopp-building
done
kubectl create -f /tmp/test/mmm-go-opp/opp.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q mmmopp-building
if [ "$?" == "0" ];then
echo "mmmopp-building service update success!"
else
echo "opp service update fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q opp
if [ "$?" == "0" ];then
echo "opp deployment update success!"
else
echo "opp deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: mmmopp-building
namespace: mmm-suplus-test
labels:
k8s-app: mmmopp-building
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: mmmopp-building
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mmmopp-building
namespace: mmm-suplus-test
labels:
k8s-app: mmmopp-building
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: mmmopp-building
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: mmmopp-building
image: 192.168.0.243:5000/mmm/mmmopp-building:dev
imagePullPolicy: Always
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
- mountPath: /var/www/opp/file
name: mmmjihuitest2-pvc1
ports:
- containerPort: 8080
volumes:
- name: accesslogs
emptyDir: {}
- name: mmmjihuitest2-pvc1
persistentVolumeClaim:
claimName: mmmjihuitest2-pvc
\ No newline at end of file
... ...
module opp
go 1.12
require (
github.com/aliyun/alibaba-cloud-sdk-go v1.60.348
github.com/astaxie/beego v1.10.0
github.com/disintegration/imaging v1.6.2
github.com/go-sql-driver/mysql v1.4.1
github.com/gomodule/redigo v1.7.0
github.com/gorilla/websocket v1.4.1
github.com/klauspost/cpuid v1.2.1 // indirect
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/common v0.6.0
github.com/satori/go.uuid v1.2.0
github.com/sony/sonyflake v1.0.0
gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
google.golang.org/appengine v1.6.2 // indirect
)
replace gitlab.fjmaimaimai.com/mmm-go/gocomm => ../gocomm
... ...
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
sigs := make(chan os.Signal, 0)
exit := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGKILL)
fmt.Println("begin ...")
go func() {
sig := <-sigs
fmt.Println("notify:", sig)
exit <- true
}()
fmt.Println("awaiting signal")
<-exit
fmt.Println("exiting")
}
... ...