Skip to content

Commit

Permalink
Merge pull request #17 from vshn/common-repo
Browse files Browse the repository at this point in the history
Merge gRPC server with  composition functions, api server and controllers together
  • Loading branch information
zugao authored May 23, 2023
2 parents 198b44d + 3621f88 commit 211aa83
Show file tree
Hide file tree
Showing 171 changed files with 13,815 additions and 3,611 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on:
pull_request: {}
push:
branches:
- master

jobs:
go-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV

- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run build
run: make build
63 changes: 63 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docs

on:
push:
branches:
- master
tags:
- "*"

jobs:
antora:
runs-on: ubuntu-latest
if: ${{ contains(github.ref, 'tags') }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "Antora via GitHub Actions"
git config user.email "actions@github.com"
- name: Parse semver string
id: semver
uses: booxmedialtd/ws-action-parse-semver@v1
with:
input_string: ${{ github.ref }}
version_extractor_regex: '\/v(.*)$'
- name: Set variables
run: |
echo "MINOR_VERSION=${{ steps.semver.outputs.major }}.${{ steps.semver.outputs.minor }}" >> $GITHUB_ENV
echo "BRANCH_NAME=docs/v${{ steps.semver.outputs.major }}.${{ steps.semver.outputs.minor }}" >> $GITHUB_ENV
- name: Set branch name for Prerelease
if: ${{ steps.semver.outputs.prerelease != '' }}
run: echo "BRANCH_NAME=${{ env.BRANCH_NAME }}-rc" >> $GITHUB_ENV

- name: Checkout remote branch if exists
run: git checkout ${{ env.BRANCH_NAME }}
continue-on-error: true
- name: Rebase if possible
run: git rebase ${GITHUB_REF##*/} ${{ env.BRANCH_NAME }}
continue-on-error: true
- name: Create new branch if not existing
run: git switch --create ${{ env.BRANCH_NAME }}
continue-on-error: true

- name: Patch Antora file for Release
run: yq eval 'del(.prerelease) | del (.display_version) | .version = "${{ env.MINOR_VERSION }}"' -i docs/antora.yml
if: ${{ steps.semver.outputs.prerelease == '' }}
- name: Patch Antora file for Prerelease
run: yq eval 'del (.display_version) | .version = "${{ env.MINOR_VERSION }}", .prerelease = "-${{ steps.semver.outputs.prerelease }}"' -i docs/antora.yml
if: ${{ steps.semver.outputs.prerelease != '' }}

- name: Commit
run: git commit --all --message "Update version for Antora"
continue-on-error: true
- name: Push
run: git push --atomic --force --set-upstream origin ${{ env.BRANCH_NAME }}

- name: Cleanup prerelease branch if existing
if: ${{ steps.semver.outputs.prerelease == '' }}
run: git push origin --delete ${{ env.BRANCH_NAME }}-rc
continue-on-error: true
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
${{ runner.os }}-go-
- name: Run linters
run: make generate lint
run: make lint
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dist/
.github/release-notes.md

# Binaries for programs and plugins
appcat-apiserver
appcat

# temp file, editor and IDE paraphernalia
.idea
Expand All @@ -12,4 +12,8 @@ appcat-apiserver
.cache
.public

# debug
apiserver.local.config

# Kubebuilder
/apis/generated/
18 changes: 9 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
builds:
- binary: appcat-apiserver
- binary: appcat
env:
- CGO_ENABLED=0 # this is needed otherwise the Docker image build is faulty
goarch:
Expand All @@ -26,27 +26,27 @@ dockers:
build_flag_templates:
- "--platform=linux/amd64"
image_templates:
- "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}-amd64"
- "ghcr.io/vshn/appcat:v{{ .Version }}-amd64"

- goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64/v8"
image_templates:
- "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}-arm64"
- "ghcr.io/vshn/appcat:v{{ .Version }}-arm64"

docker_manifests:
# For prereleases, updating `latest` does not make sense.
# Only the image for the exact version should be pushed.
- name_template: "{{ if not .Prerelease }}ghcr.io/vshn/appcat-apiserver:latest{{ end }}"
- name_template: "{{ if not .Prerelease }}ghcr.io/vshn/appcat:latest{{ end }}"
image_templates:
- "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}-amd64"
- "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}-arm64"
- "ghcr.io/vshn/appcat:v{{ .Version }}-amd64"
- "ghcr.io/vshn/appcat:v{{ .Version }}-arm64"

- name_template: "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}"
- name_template: "ghcr.io/vshn/appcat:v{{ .Version }}"
image_templates:
- "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}-amd64"
- "ghcr.io/vshn/appcat-apiserver:v{{ .Version }}-arm64"
- "ghcr.io/vshn/appcat:v{{ .Version }}-amd64"
- "ghcr.io/vshn/appcat:v{{ .Version }}-arm64"

release:
prerelease: auto
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM docker.io/library/alpine:3.15 as runtime

ENTRYPOINT ["appcat-apiserver"]
ENTRYPOINT ["appcat"]

RUN \
apk add --update --no-cache \
Expand All @@ -11,8 +11,8 @@ RUN \
RUN \
mkdir /.cache && chmod -R g=u /.cache

COPY appcat-apiserver /usr/local/bin/
COPY appcat /usr/local/bin/

RUN chmod a+x /usr/local/bin/appcat-apiserver
RUN chmod a+x /usr/local/bin/appcat

USER 65532:0
39 changes: 23 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Image URL to use all building/pushing image targets
IMG_TAG ?= latest
GHCR_IMG ?= ghcr.io/vshn/appcat-apiserver:$(IMG_TAG)
GHCR_IMG ?= ghcr.io/vshn/appcat:$(IMG_TAG)
DOCKER_CMD ?= docker

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand All @@ -11,16 +11,23 @@ else
GOBIN=$(shell go env GOBIN)
endif

OS := $(shell uname)
ifeq ($(OS), Darwin)
sed ?= gsed
else
sed ?= sed
endif

# For alpine image it is required the following env before building the application
DOCKER_IMAGE_GOOS = linux
DOCKER_IMAGE_GOARCH = amd64

PROJECT_ROOT_DIR = .
PROJECT_NAME ?= appcat-apiserver
PROJECT_NAME ?= appcat
PROJECT_OWNER ?= vshn

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
BIN_FILENAME ?= $(PROJECT_DIR)/appcat-apiserver
BIN_FILENAME ?= $(PROJECT_DIR)/appcat

## BUILD:go
go_bin ?= $(PWD)/.work/bin
Expand All @@ -45,8 +52,6 @@ $(protoc_bin): | $(go_bin)
@unzip $(go_bin)/protoc.zip -d .work
@rm $(go_bin)/protoc.zip

include kind/kind.mk
include dev/local.mk
-include docs/antora-preview.mk docs/antora-build.mk

.PHONY: help
Expand All @@ -56,16 +61,23 @@ help: ## Display this help.
.PHONY: generate
generate: export PATH := $(go_bin):$(PATH)
generate: $(protoc_bin) ## Generate code with controller-gen and protobuf.
go version
rm -rf apis/generated
go run sigs.k8s.io/controller-tools/cmd/controller-gen paths=./apis/... object crd:crdVersions=v1 output:artifacts:config=./apis/generated
go generate ./...
go run sigs.k8s.io/controller-tools/cmd/controller-gen object paths="./apis/..."
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=appcat-apiserver paths="{./apis/...,./apiserver/...}" output:artifacts:config=config/
# Because yaml is such a fun and easy specification, we need to hack some things here.
# Depending on the yaml parser implementation the equal sign (=) has special meaning, or not...
# So we make it explicitly a string.
$(sed) -i ':a;N;$$!ba;s/- =\n/- "="\n/g' apis/generated/vshn.appcat.vshn.io_vshnpostgresqls.yaml
rm -rf crds && cp -r apis/generated crds
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=appcat paths="{./apis/...,./pkg/apiserver/...}" output:artifacts:config=config/apiserver
go run k8s.io/code-generator/cmd/go-to-protobuf \
--packages=github.com/vshn/appcat-apiserver/apis/appcat/v1 \
--packages=github.com/vshn/appcat/apis/appcat/v1 \
--output-base=./.work/tmp \
--go-header-file=./hack/boilerplate.txt \
--go-header-file=./pkg/apiserver/hack/boilerplate.txt \
--apimachinery-packages='-k8s.io/apimachinery/pkg/util/intstr,-k8s.io/apimachinery/pkg/api/resource,-k8s.io/apimachinery/pkg/runtime/schema,-k8s.io/apimachinery/pkg/runtime,-k8s.io/apimachinery/pkg/apis/meta/v1,-k8s.io/apimachinery/pkg/apis/meta/v1beta1,-k8s.io/api/core/v1,-k8s.io/api/rbac/v1' \
--proto-import=./.work/kubernetes/vendor/ && \
mv ./.work/tmp/github.com/vshn/appcat-apiserver/apis/appcat/v1/generated.pb.go ./apis/appcat/v1/ && \
mv ./.work/tmp/github.com/vshn/appcat/apis/appcat/v1/generated.pb.go ./apis/appcat/v1/ && \
rm -rf ./.work/tmp

.PHONY: fmt
Expand Down Expand Up @@ -94,10 +106,6 @@ build:
test: ## Run tests
go test ./...

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

.PHONY: docker-build
docker-build:
env CGO_ENABLED=0 GOOS=$(DOCKER_IMAGE_GOOS) GOARCH=$(DOCKER_IMAGE_GOARCH) \
Expand All @@ -109,6 +117,5 @@ docker-push: docker-build ## Push docker image with the manager.
docker push ${GHCR_IMG}

.PHONY: clean
clean: kind-clean
clean:
rm -rf bin/ appcat-apiserver .work/ docs/node_modules $docs_out_dir .public .cache
rm -rf bin/ appcat .work/ docs/node_modules $docs_out_dir .public .cache apiserver.local.config apis/generated default.sock
Loading

0 comments on commit 211aa83

Please sign in to comment.