1. 介绍
BaGet是一个轻量级的包管理服务。有些时候公司或者个人不希望某一些包进行公开,那么就需要使用私有的包管理服务程序,该服务是用.netcore进行编写的(感谢开发者为.NET社区做出的贡献)
Github:https://github.com/loic-sharma/BaGet
具体配置操作可参考官方文档,
为了能够从nuget 库中获取其他的包文件,需要配置使用官放镜像
{ ... "Mirror": { "Enabled": true, "PackageSource": "https://api.nuget.org/v3/index.json" }, ... }
2. Docker部署
在当前目录下执行创建配置文件baget.env
# The following config is the API Key used to publish packages.
# You should change this to a secret value to secure your server.
ApiKey=63edf12c-b70c-45c7-b3ed-f53c9f791e26 # 随机生成,上传包时候使用
Storage__Type=FileSystem
Storage__Path=E:
uget #windows下的写法
Database__Type=Sqlite
Database__ConnectionString=Data Source=/var/baget/baget.db
Search__Type=Database
Mirror__Enabled=true
在当前目录下执行
# linux
docker run -d --name BaGet-nuget -p 9002:80 --env-file baget.env -v "$(pwd)/baget-data:/var/baget" loicsharma/baget:latest
# windows
docker run -d --name BaGet-nuget -p 9002:80 --env-file baget.env -v "F://nuget//baget-data:/var/baget" loicsharma/baget:latest
3. Kubernetes部署
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
pv.kubernetes.io/bind-completed: "yes"
pv.kubernetes.io/bound-by-controller: "yes"
creationTimestamp: "2021-04-22T12:29:55Z"
finalizers:
- kubernetes.io/pvc-protection
managedFields:
- apiVersion: v1
manager: kube-controller-manager
operation: Update
time: "2021-04-22T12:29:55Z"
- apiVersion: v1
manager: tke-apiserver
operation: Update
time: "2021-04-22T12:29:55Z"
name: baget
namespace: default
resourceVersion: "16807551935"
selfLink: /api/v1/namespaces/default/persistentvolumeclaims/baget
uid: fbf18d16-d8e1-4c00-b1c6-fad9caff47c4
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: cbs
volumeMode: Filesystem
volumeName: baget
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 90Gi
phase: Bound
-----------------------------------------------------------------------------------
apiVersion: apps/v1
kind: StatefulSet
metadata:
creationTimestamp: "2021-04-22T13:49:37Z"
generation: 2
labels:
k8s-app: baget
qcloud-app: baget
managedFields:
- apiVersion: apps/v1
manager: tke-apiserver
operation: Update
time: "2021-04-22T13:57:07Z"
- apiVersion: apps/v1
manager: kube-controller-manager
operation: Update
time: "2021-04-22T13:57:27Z"
name: baget
namespace: default
resourceVersion: "16809436783"
selfLink: /apis/apps/v1/namespaces/default/statefulsets/baget
uid: 97cf6cd7-3cfe-4a57-9e36-c997018c5971
spec:
podManagementPolicy: OrderedReady
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: baget
qcloud-app: baget
serviceName: ""
template:
metadata:
creationTimestamp: null
labels:
k8s-app: baget
qcloud-app: baget
spec:
containers:
- env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: ASPNETCORE_URLS
value: http://+:80
- name: DOTNET_RUNNING_IN_CONTAINER
value: "true"
- name: ApiKey
value: afe0f754-68b0-38a1-b7bf-44a34263465d
- name: Storage__Type
value: FileSystem
- name: Storage__Path
value: /var/baget/packages
- name: Database__Type
value: Sqlite
- name: Database__ConnectionString
value: Data Source=/var/baget/baget.db
- name: Search__Type
value: Database
- name: AllowPackageOverwrites
value: "true"
image: ccr.ccs.tencentyun.com/weyhd/baget:0.3.1
imagePullPolicy: IfNotPresent
name: baget
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 250m
memory: 256Mi
securityContext:
privileged: false
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/baget
name: bagetpackage
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: qcloudregistrykey
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: bagetpackage
persistentVolumeClaim:
claimName: baget
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
status:
collisionCount: 0
currentReplicas: 1
currentRevision: baget-6b9767d59b
observedGeneration: 2
readyReplicas: 1
replicas: 1
updateRevision: baget-6b9767d59b
updatedReplicas: 1
--------------------------------------------------------------------
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2021-04-22T13:49:37Z"
managedFields:
- apiVersion: v1
manager: tke-apiserver
operation: Update
time: "2021-04-22T13:49:37Z"
name: baget
namespace: default
resourceVersion: "16809267660"
selfLink: /api/v1/namespaces/default/services/baget
uid: f7fcc0c9-afea-4b1d-8b89-3978ce7b69af
spec:
clusterIP: 172.20.252.235
externalTrafficPolicy: Cluster
ports:
- name: 80-80-tcp
nodePort: 30020
port: 80
protocol: TCP
targetPort: 80
selector:
k8s-app: baget
qcloud-app: baget
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
使用存储来保存nuget 包,数据库演示选用了sqlite, 生产环境可以选择其他的数据库比如mysql,pgsql,sqlserver。 通过StatefulSet 部署,nodeport方式公开访问
3. 简单使用
3.1 访问
界面和 https://www.nuget.org/ 很相似,推送方法也很简单,提供了4种方式进行推送:
轻量NuGet服务—BaGet:https://mp.weixin.qq.com/s/xF5K2U3OhF7I9moGMeOibw