Skip to content

Commit

Permalink
Cicd (#8)
Browse files Browse the repository at this point in the history
* cicd cleanup

Co-authored-by: sharnoff <[email protected]>
  • Loading branch information
cicdteam and sharnoff authored Nov 28, 2022
1 parent ad76267 commit 9c85272
Show file tree
Hide file tree
Showing 13 changed files with 3,343 additions and 49 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: release

on:
push:
branches:
- main
tags:
- v*

env:
KUSTOMIZE_VERSION: "4.5.7"
CONTROLLER_TOOLS_VERSION: "0.10.0"
CODE_GENERATOR_VERSION: "0.25.4"
GOFLAGS: "-buildvcs=false"
IMG: "neondatabase/neonvm-controller"
IMG_RUNNER: "neondatabase/neonvm-runner"
VM_KERNEL_IMAGE: "neondatabase/vm-kernel"
VM_KERNEL_VERSION: "5.15.80"

jobs:
release:
runs-on: ubuntu-latest
steps:

- id: get_version
run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: git checkout
uses: actions/checkout@v3
- name: install golang
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true

- name: generate go code
run: |
git clone --branch=v${{ env.CODE_GENERATOR_VERSION }} --depth=1 https://github.com/kubernetes/code-generator.git ${RUNNER_TEMP}/code-generator
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v${{ env.CONTROLLER_TOOLS_VERSION }}
${RUNNER_TEMP}/code-generator/generate-groups.sh "deepcopy,client,informer,lister" github.com/neondatabase/neonvm/client github.com/neondatabase/neonvm/apis neonvm:v1 --go-header-file hack/boilerplate.go.txt
controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
- name: build binaries
run: make build

- name: docker - install qemu
uses: docker/setup-qemu-action@v2
- name: docker - setup buildx
uses: docker/setup-buildx-action@v2
- name: login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.NEON_DOCKERHUB_USERNAME }}
password: ${{ secrets.NEON_DOCKERHUB_PASSWORD }}

- name: load vm kernel
run: |
docker pull --quiet ${{ env.VM_KERNEL_IMAGE }}:${{ env.VM_KERNEL_VERSION }}
ID=$(docker create ${{ env.VM_KERNEL_IMAGE }}:${{ env.VM_KERNEL_VERSION }} true)
docker cp ${ID}:/vmlinuz hack/vmlinuz
docker rm -f ${ID}
- name: build and push runner image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
push: true
#push: ${{ github.event_name != 'pull_request' }}
file: runner/Dockerfile
tags: ${{ env.IMG_RUNNER }}:${{ steps.get_version.outputs.version }}

- name: build and push controller image
uses: docker/build-push-action@v3
with:
build-args: VM_RUNNER_IMAGE=${{ env.IMG_RUNNER }}:${{ steps.get_version.outputs.version }}
context: .
platforms: linux/amd64
push: true
#push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.IMG }}:${{ steps.get_version.outputs.version }}

- name: render kubernetes resources
uses: stefanprodan/kube-tools@v1
with:
kustomize: ${{ env.KUSTOMIZE_VERSION }}
command: |
kustomize version --short
cd config/controller && kustomize edit set image controller=${{ env.IMG }}:${{ steps.get_version.outputs.version }}
cd ${GITHUB_WORKSPACE} && kustomize build config/default --output neonvm.yaml
- name: github release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
neonvm.yaml
bin/vm-builder
42 changes: 42 additions & 0 deletions .github/workflows/vm-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: vm-example

on:
schedule:
- cron: '40 * * * *'
workflow_dispatch: # adds ability to run this manually

env:
VM_EXAMPLE_SOURCE: postgres:14-alpine
VM_EXAMPLE_IMAGE: neondatabase/vm-postgres:14-alpine

jobs:
vm-example:
runs-on: ubuntu-latest
steps:

- name: git checkout
uses: actions/checkout@v3

- name: install golang
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true

- name: build vm-builder
run: go build -o bin/vm-builder tools/vm-builder/main.go

- name: docker - install qemu
uses: docker/setup-qemu-action@v2
- name: docker - setup buildx
uses: docker/setup-buildx-action@v2
- name: login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.NEON_DOCKERHUB_USERNAME }}
password: ${{ secrets.NEON_DOCKERHUB_PASSWORD }}

- name: build and push vm-example image
run: |
bin/vm-builder -src ${{ env.VM_EXAMPLE_SOURCE }} -dst ${{ env.VM_EXAMPLE_IMAGE }}
docker push -q ${{ env.VM_EXAMPLE_IMAGE }}
40 changes: 40 additions & 0 deletions .github/workflows/vm-kernel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: vm-kernel

on:
schedule:
- cron: '40 * * * *'
workflow_dispatch: # adds ability to run this manually

env:
VM_KERNEL_IMAGE: "neondatabase/vm-kernel"
VM_KERNEL_VERSION: "5.15.80"

jobs:
vm-kernel:
runs-on: ubuntu-latest
steps:

- name: git checkout
uses: actions/checkout@v3

- name: docker - install qemu
uses: docker/setup-qemu-action@v2
- name: docker - setup buildx
uses: docker/setup-buildx-action@v2
- name: login to docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.NEON_DOCKERHUB_USERNAME }}
password: ${{ secrets.NEON_DOCKERHUB_PASSWORD }}

- name: build linux kernel
uses: docker/build-push-action@v3
with:
build-args: KERNEL_VERSION=${{ env.VM_KERNEL_VERSION }}
context: .
platforms: linux/amd64
push: true
pull: true
no-cache: true
file: hack/Dockerfile.kernel-builder
tags: ${{ env.VM_KERNEL_IMAGE }}:${{ env.VM_KERNEL_VERSION }}
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot

ARG VM_RUNNER_IMAGE=runner:dev
ENV VM_RUNNER_IMAGE=${VM_RUNNER_IMAGE}

WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
Expand Down
32 changes: 22 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VM_EXAMPLE_SOURCE ?= postgres:14-alpine
VM_EXAMPLE_IMAGE ?= vm-postgres:14-alpine

# kernel for guests
VM_KERNEL_VERSION ?= "5.15.76"
VM_KERNEL_VERSION ?= "5.15.80"

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
Expand Down Expand Up @@ -57,6 +57,12 @@ generate: ## Generate boilerplate DeepCopy methods, manifests, and Go client
docker build -f hack/Dockerfile.generate --iidfile $$iidfile . && \
docker run --rm -v $$PWD:/go/src/github.com/neondatabase/neonvm -w /go/src/github.com/neondatabase/neonvm $$(cat $$iidfile) ./hack/generate.sh && \
rm -rf $$iidfile
go fmt ./...

# if buildvcs=false is not given, then we can run into issues with git worktrees.
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
GOFLAGS="-buildvcs=false" $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -88,10 +94,9 @@ run: fmt vet ## Run a controller from your host.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: build test ## Build docker image with the controller.
docker build -t $(IMG) .
docker build --build-arg VM_RUNNER_IMAGE=$(IMG_RUNNER) -t $(IMG) .
docker build -t $(IMG_RUNNER) -f runner/Dockerfile .
bin/vm-builder -src $(VM_EXAMPLE_SOURCE) -dst $(VM_EXAMPLE_IMAGE)
# docker build -t $(VM_EXAMPLE) samples/vm-example

#.PHONY: docker-push
#docker-push: ## Push docker image with the controller.
Expand Down Expand Up @@ -122,19 +127,20 @@ ifndef ignore-not-found
endif

.PHONY: install
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

DEPLOYTS := $(shell date +%s)
.PHONY: deploy
deploy: kind-load kustomize install ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/controller && $(KUSTOMIZE) edit set image controller=$(IMG) && $(KUSTOMIZE) edit add annotation redeploy-at:$(DEPLOYTS) --force
deploy: kind-load manifests kustomize install ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/controller && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/default | kubectl apply -f -
kubectl -n neonvm-system rollout status deployment neonvm-controller
kubectl -n neonvm-system rollout restart deployment neonvm-controller
kubectl -n neonvm-system rollout status deployment neonvm-controller

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand All @@ -150,10 +156,11 @@ $(LOCALBIN):
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
ENVTEST ?= $(LOCALBIN)/setup-envtest
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2
KUSTOMIZE_VERSION ?= v4.5.7
CONTROLLER_TOOLS_VERSION ?= v0.10.0
GENERATE_GROUPS_VERSION ?= v0.25.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
Expand All @@ -167,6 +174,11 @@ envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: kernel
kernel: ## Build linux kernel.
rm -f hack/vmlinuz
Expand Down
11 changes: 3 additions & 8 deletions config/controller/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: controller
newTag: dev
commonAnnotations:
redeploy-at: "1669290550"

resources:
- manager.yaml
5 changes: 1 addition & 4 deletions config/controller/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ spec:
- /manager
args:
- --leader-elect
image: controller:latest
image: controller:dev
name: manager
env:
- name: VM_RUNNER_IMAGE
value: runner:dev
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
Loading

0 comments on commit 9c85272

Please sign in to comment.