Expose git artifacts inside the cluster
This commit is contained in:
parent
d2b0653c34
commit
98901f2909
12
Dockerfile
12
Dockerfile
|
@ -1,20 +1,20 @@
|
|||
# Build the manager binary
|
||||
FROM golang:1.13 as builder
|
||||
|
||||
WORKDIR /workspace
|
||||
# Copy the Go Modules manifests
|
||||
|
||||
# copy modules manifests
|
||||
COPY go.mod go.mod
|
||||
COPY go.sum go.sum
|
||||
# cache deps before building and copying source so that we don't need to re-download as much
|
||||
# and so that source changes don't invalidate our downloaded layer
|
||||
|
||||
# cache modules
|
||||
RUN go mod download
|
||||
|
||||
# Copy the go source
|
||||
# copy source code
|
||||
COPY main.go main.go
|
||||
COPY api/ api/
|
||||
COPY controllers/ controllers/
|
||||
|
||||
# Build
|
||||
# build
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o sourcer main.go
|
||||
|
||||
FROM alpine:3.11
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# This kustomization.yaml is not intended to be run by itself,
|
||||
# since it depends on service name and namespace that are out of this kustomize package.
|
||||
# It should be run by config/default
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- bases/sourcer.fluxcd.io_gitrepositories.yaml
|
||||
- bases/sourcer.fluxcd.io_helmrepositories.yaml
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# Adds namespace to all resources.
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namespace: sourcer-system
|
||||
|
||||
namePrefix: sourcer-
|
||||
|
||||
bases:
|
||||
- ../crd
|
||||
- ../rbac
|
||||
|
|
|
@ -1,26 +1,19 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
name: system
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: controller-manager
|
||||
name: controller
|
||||
namespace: system
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
control-plane: controller
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
control-plane: controller-manager
|
||||
app: sourcer
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: controller-manager
|
||||
app: sourcer
|
||||
annotations:
|
||||
prometheus.io/scrape: "true"
|
||||
prometheus.io/port: "9090"
|
||||
|
@ -28,7 +21,7 @@ spec:
|
|||
terminationGracePeriodSeconds: 10
|
||||
containers:
|
||||
- name: manager
|
||||
image: fluxcd/sourcer:latest
|
||||
image: controller
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
|
@ -37,6 +30,11 @@ spec:
|
|||
args:
|
||||
- --enable-leader-election
|
||||
- --storage-path=/data
|
||||
env:
|
||||
- name: RUNTIME_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
resources:
|
||||
limits:
|
||||
cpu: 1000m
|
|
@ -1,2 +1,10 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- manager.yaml
|
||||
- namespace.yaml
|
||||
- service.yaml
|
||||
- deployment.yaml
|
||||
images:
|
||||
- name: controller
|
||||
newName: fluxcd/sourcer
|
||||
newTag: 0.0.1-alpha.1
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
labels:
|
||||
control-plane: controller
|
||||
name: system
|
|
@ -0,0 +1,16 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: controller
|
||||
namespace: system
|
||||
labels:
|
||||
control-plane: controller
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: sourcer
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
protocol: TCP
|
||||
targetPort: http
|
|
@ -1,6 +1,7 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- role.yaml
|
||||
- role_binding.yaml
|
||||
- leader_election_role.yaml
|
||||
- leader_election_role_binding.yaml
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
|
@ -197,7 +198,7 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
|||
|
||||
// store artifacts
|
||||
artifacts := filepath.Join(storage, fmt.Sprintf("%s.tar.gz", ref.Hash().String()))
|
||||
excludes := "--exclude=\\*.{jpg,gif,png,wmv,flv,tar.gz,zip} --exclude .git"
|
||||
excludes := "--exclude=\\*.{jpg,jpeg,gif,png,wmv,flv,tar.gz,zip} --exclude .git"
|
||||
command := exec.Command("/bin/sh", "-c",
|
||||
fmt.Sprintf("cd %s && tar -c %s -f - . | gzip > %s", dir, excludes, artifacts))
|
||||
err = command.Run()
|
||||
|
@ -211,13 +212,22 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
|||
}, "", ex
|
||||
}
|
||||
|
||||
output := fmt.Sprintf("/repositories/%s-%s/%s.tar.gz", gr.Name, gr.Namespace, ref.Hash().String())
|
||||
// compose artifacts URL
|
||||
hostname := "localhost"
|
||||
if os.Getenv("RUNTIME_NAMESPACE") != "" {
|
||||
svcParts := strings.Split(os.Getenv("HOSTNAME"), "-")
|
||||
hostname = fmt.Sprintf("%s.%s",
|
||||
strings.Join(svcParts[:len(svcParts)-2], "-"), os.Getenv("RUNTIME_NAMESPACE"))
|
||||
}
|
||||
artifactsURL := fmt.Sprintf("http://%s/repositories/%s-%s/%s.tar.gz",
|
||||
hostname, gr.Name, gr.Namespace, ref.Hash().String())
|
||||
|
||||
return sourcerv1.RepositoryCondition{
|
||||
Type: sourcerv1.RepositoryConditionReady,
|
||||
Status: corev1.ConditionTrue,
|
||||
Reason: "GitCloneSucceed",
|
||||
Message: fmt.Sprintf("Fetched artifacts are available at %s", artifacts),
|
||||
}, output, nil
|
||||
}, artifactsURL, nil
|
||||
}
|
||||
|
||||
func (r *GitRepositoryReconciler) shouldResetStatus(gr sourcerv1.GitRepository) bool {
|
||||
|
|
Loading…
Reference in New Issue