docker&k8s支持
This commit is contained in:
parent
953a6c14f1
commit
dcd906b270
47
Dockerfile
47
Dockerfile
|
@ -1,8 +1,43 @@
|
|||
#sudo docker build -t centos7-gopub .
|
||||
#sudo docker run --name centos7-gopub -d centos7-gopub:latest
|
||||
From 192.168.176.2:81/test/centos7-gopub
|
||||
MAINTAINER Linc "13579443@qq.com"
|
||||
#docker 17.05+版本支持
|
||||
#sudo docker build -t gopub .
|
||||
#sudo docker run --name gopub -p 8192:8192 --restart always -d gopub:latest
|
||||
FROM golang:1.10.1-alpine3.7 as golang
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
|
||||
apk update && \
|
||||
apk add bash && \
|
||||
rm -rf /var/cache/apk/* /tmp/*
|
||||
ADD src/ /data/gopub/src/
|
||||
ADD control /data/gopub/control
|
||||
RUN cd /data/gopub &&./control build
|
||||
CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
|
||||
WORKDIR /data/gopub/
|
||||
RUN ./control build
|
||||
|
||||
FROM node:9.11.1-alpine as node
|
||||
ADD ./ /data/gopub/
|
||||
WORKDIR /data/gopub/vue-gopub
|
||||
RUN npm install && npm run build
|
||||
|
||||
FROM alpine:3.7
|
||||
MAINTAINER Linc "13579443@qq.com"
|
||||
ENV TZ='Asia/Shanghai'
|
||||
RUN TERM=linux && export TERM
|
||||
USER root
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
|
||||
apk update && \
|
||||
apk add ca-certificates bash tzdata sudo curl wget openssh git && \
|
||||
echo "Asia/Shanghai" > /etc/timezone && \
|
||||
cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
rm -rf /var/cache/apk/* /tmp/* && \
|
||||
mkdir -p /data/htdocs && \
|
||||
mkdir -p /data/logs && \
|
||||
ssh-keygen -q -N "" -f /root/.ssh/id_rsa && \
|
||||
#输出的key需要加入发布目标机的 ~/.ssh/authorized_keys
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
WORKDIR /data/gopub
|
||||
ADD control /data/gopub/control
|
||||
COPY --from=golang /data/gopub/src/gopub /data/gopub/src/gopub
|
||||
COPY --from=golang /data/gopub/src/conf /data/gopub/src/conf
|
||||
COPY --from=golang /data/gopub/src/logs /data/gopub/src/logs
|
||||
COPY --from=golang /data/gopub/src/agent /data/gopub/src/agent
|
||||
COPY --from=node /data/gopub/src/views /data/gopub/src/views
|
||||
COPY --from=node /data/gopub/src/static /data/gopub/src/static
|
||||
CMD ["./control","rundocker"]
|
||||
|
|
23
README.md
23
README.md
|
@ -21,6 +21,25 @@ gopub已在我们预发布和生产环境完成37000+次稳定部署,支持单
|
|||
* API支持:提供所有配置和发布操作API,便于对接其他系统 [API使用example](api_example/example.go)
|
||||
* 部署钩子:支持部署前准备任务,代码检出后处理任务,同步后更新软链前置任务,发布完毕后收尾任务4种钩子函数脚本执行
|
||||
|
||||
## Docker快速启动
|
||||
``` shell
|
||||
#使用dockerhub镜像启动,连接外部数据库
|
||||
sudo docker run --name gopub -e MYSQL_HOST=127.0.0.1 -e MYSQL_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASS=123456 -e MYSQL_DB=walle -p 8192:8192 --restart always -d lc13579443/gopub:latest
|
||||
```
|
||||
### Docker 镜像制作
|
||||
``` shell
|
||||
#使用multi-stage(多阶段构建)需要docker 17.05+版本支持
|
||||
sudo docker build -t gopub .
|
||||
sudo docker run --name gopub -e MYSQL_HOST=127.0.0.1 -e MYSQL_PORT=3306 -e MYSQL_USER=root -e MYSQL_PASS=123456 -e MYSQL_DB=walle -p 8192:8192 --restart always -d gopub:latest
|
||||
|
||||
```
|
||||
### Kubernetes快速部署
|
||||
``` shell
|
||||
#apiVersion: apps/v1 需要kubernetes 1.9.0+版本支持
|
||||
kubectl apply -f gopub-kubernetes.yml
|
||||
|
||||
```
|
||||
|
||||
## 源码编译安装
|
||||
### 编译环境
|
||||
- golang >= 1.8+
|
||||
|
@ -46,7 +65,7 @@ npm run build
|
|||
#执行数据库初始化
|
||||
./control init
|
||||
|
||||
#启动服务 启动成功后 可访问 127.0.0.1:8092 用户名:admin 密码:123456
|
||||
#启动服务 启动成功后 可访问 127.0.0.1:8192 用户名:admin 密码:123456
|
||||
./control start
|
||||
|
||||
#停止服务
|
||||
|
@ -59,7 +78,7 @@ npm run build
|
|||
### 快速使用
|
||||
|
||||
``` shell
|
||||
# 下载项目release包,无需安装go环境和node环境
|
||||
# 下载项目[二进制包](https://gitee.com/dev-ops/gopub/attach_files/download?i=127597&u=http%3A%2F%2Ffiles.git.oschina.net%2Fgroup1%2FM00%2F03%2F4B%2FPaAvDFrJ7iOAeiJJAJ9Zw8cLgzM9739.gz%3Ftoken%3D4b1fd7be9453d7417b567d4bf98f7657%26ts%3D1523253033%26attname%3Dgopub-1.0.0.tar.gz),无需安装go环境和node环境
|
||||
|
||||
|
||||
#给control和src/gopub给可执行权限
|
||||
|
|
|
@ -171,5 +171,3 @@ elif [ "$1" == "sslkey" ];then
|
|||
else
|
||||
help
|
||||
fi
|
||||
#bee api gopub -driver=mysql -conn="mysql:mysql888@tcp(192.168.143.62:3306)/walle"
|
||||
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: gopub
|
||||
namespace: default
|
||||
labels:
|
||||
name: gopub
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
name: gopub
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 1
|
||||
maxUnavailable: 1
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
name: gopub
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
hostAliases:
|
||||
- ip: "192.168.162.66"
|
||||
hostnames:
|
||||
- "gitlab.example.org"
|
||||
- "packagist.example.org"
|
||||
- "toran.example.org"
|
||||
- ip: "192.168.143.41"
|
||||
hostnames:
|
||||
- "jenkins.example.org"
|
||||
- ip: "127.0.0.1"
|
||||
hostnames:
|
||||
- "mysql"
|
||||
containers:
|
||||
- name: gopub
|
||||
image: "lc13579443/gopub:latest"
|
||||
imagePullPolicy: Always
|
||||
securityContext:
|
||||
privileged: true
|
||||
ports:
|
||||
- containerPort: 8192
|
||||
name: http-port
|
||||
env:
|
||||
- name: MYSQL_HOST
|
||||
value: '127.0.0.1'
|
||||
- name: MYSQL_PORT
|
||||
value: '3306'
|
||||
- name: MYSQL_USER
|
||||
value: 'root'
|
||||
- name: MYSQL_PASS
|
||||
value: '123456'
|
||||
- name: MYSQL_DB
|
||||
value: 'walle'
|
||||
resources:
|
||||
limits:
|
||||
cpu: 2
|
||||
memory: 4096Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 200Mi
|
||||
volumeMounts:
|
||||
- name: localtime
|
||||
mountPath: /etc/localtime
|
||||
readOnly: true
|
||||
- name: cgroup
|
||||
mountPath: /sys/fs/cgroup
|
||||
readOnly: true
|
||||
- name: mysql
|
||||
image: "mysql:5.7"
|
||||
imagePullPolicy: Always
|
||||
env:
|
||||
- name: MYSQL_ROOT_PASSWORD
|
||||
value: '123456'
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
name: mysql-port
|
||||
resources:
|
||||
limits:
|
||||
cpu: 2
|
||||
memory: 4096Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 200Mi
|
||||
volumeMounts:
|
||||
- name: localtime
|
||||
mountPath: /etc/localtime
|
||||
readOnly: true
|
||||
- name: cgroup
|
||||
mountPath: /sys/fs/cgroup
|
||||
readOnly: true
|
||||
- name: mysql-data
|
||||
mountPath: /var/lib/mysql
|
||||
terminationGracePeriodSeconds: 30
|
||||
volumes:
|
||||
- name: localtime
|
||||
hostPath:
|
||||
path: /etc/localtime
|
||||
- name: cgroup
|
||||
hostPath:
|
||||
path: /sys/fs/cgroup
|
||||
- name: mysql-data
|
||||
hostPath:
|
||||
path: /data/gopub-mysql
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: gopub
|
||||
namespace: default
|
||||
labels:
|
||||
name: gopub
|
||||
spec:
|
||||
type: NodePort
|
||||
selector:
|
||||
name: gopub
|
||||
ports:
|
||||
- name: gopub
|
||||
port: 8192
|
||||
nodePort: 8192
|
||||
|
Loading…
Reference in New Issue