jenkins自动发布之go/golang项目
Contents
go语言项目
后端API接口
beego框架
Dockerfile
FROM golang:1.16-alpine as builder
WORKDIR /work
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app . \
&& mkdir run && cp -r conf app run && cp conf/app-test.conf run/conf/app.conf
#FROM scratch
FROM alpine
RUN apk add --no-cache ca-certificates tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
WORKDIR /work
COPY --from=builder /work/run .
EXPOSE 1500
ENTRYPOINT ["./app"]
创建pvc
|
|
创建secret
|
|
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: enjoy-dream-api
spec:
selector:
matchLabels:
app: enjoy-dream-api
replicas: 2
template:
metadata:
labels:
app: enjoy-dream-api
spec:
terminationGracePeriodSeconds: 30
containers:
- name: enjoy-dream-api
image: harbor.mkl.io/enjoydream/enjoy-dream-api:3.0-$BUILD_NUMBER
imagePullPolicy: IfNotPresent
volumeMounts:
- name: pvc-static
subPath: static
mountPath: "/work/static"
ports:
- containerPort: 1500
imagePullSecrets:
- name: secret-harbor-user
volumes:
- name: pvc-static
persistentVolumeClaim:
claimName: enjoydream-pvc-static
---
apiVersion: v1
kind: Service
metadata:
name: enjoy-dream-api
spec:
type: NodePort
selector:
app: enjoy-dream-api
ports:
- port: 1500
targetPort: 1500
前端vue
Dockerfile
FROM node:14.17.3 as nodebuilder
WORKDIR /Node
COPY . .
RUN apt update && apt-get -y install yarn && cp .env.test .env && yarn && yarn build
FROM nginx:alpine
MAINTAINER yanyong
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
COPY --from=nodebuilder /Node/dist/ /usr/share/nginx/html/
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: enjoy-dream-admin
spec:
selector:
matchLabels:
app: enjoy-dream-admin
replicas: 2
template:
metadata:
labels:
app: enjoy-dream-admin
spec:
terminationGracePeriodSeconds: 30
containers:
- name: enjoy-dream-admin
image: harbor.mkl.io/enjoydream/enjoy-dream-admin:3.0-$BUILD_NUMBER
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
imagePullSecrets:
- name: secret-harbor-user
---
apiVersion: v1
kind: Service
metadata:
name: enjoy-dream-admin
spec:
type: NodePort
selector:
app: enjoy-dream-admin
ports:
- port: 80
targetPort: 80
jenkins发布
后端,前端都参考以下脚本
jenkins, Build脚本
|
|
jenkins, Post-build Actions脚本
|
|