Implement CI with GitHub Actions

This commit is contained in:
stefanprodan 2020-04-08 12:38:47 +03:00
parent 62350a944b
commit 86c2c9f745
12 changed files with 136 additions and 5 deletions

View File

@ -0,0 +1,6 @@
FROM giantswarm/tiny-tools
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -0,0 +1,9 @@
name: 'kubebuilder'
description: 'A GitHub Action to run kubebuilder commands'
author: 'Stefan Prodan'
branding:
icon: 'command'
color: 'blue'
runs:
using: 'docker'
image: 'Dockerfile'

View File

@ -0,0 +1,12 @@
#!/bin/sh -l
VERSION=2.3.1
curl -sL https://go.kubebuilder.io/dl/${VERSION}/linux/amd64 | tar -xz -C /tmp/
mkdir -p $GITHUB_WORKSPACE/kubebuilder
mv /tmp/kubebuilder_${VERSION}_linux_amd64/* $GITHUB_WORKSPACE/kubebuilder/
ls -lh $GITHUB_WORKSPACE/kubebuilder/bin
echo "::add-path::$GITHUB_WORKSPACE/kubebuilder/bin"
echo "::add-path::$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/kubebuilder/bin"

6
.github/actions/kustomize/Dockerfile vendored Normal file
View File

@ -0,0 +1,6 @@
FROM giantswarm/tiny-tools
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

9
.github/actions/kustomize/action.yml vendored Normal file
View File

@ -0,0 +1,9 @@
name: 'kustomize'
description: 'A GitHub Action to run kustomize commands'
author: 'Stefan Prodan'
branding:
icon: 'command'
color: 'blue'
runs:
using: 'docker'
image: 'Dockerfile'

12
.github/actions/kustomize/entrypoint.sh vendored Normal file
View File

@ -0,0 +1,12 @@
#!/bin/sh -l
VERSION=3.1.0
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v${VERSION}/kustomize_${VERSION}_linux_amd64
mkdir -p $GITHUB_WORKSPACE/bin
cp ./kustomize $GITHUB_WORKSPACE/bin
chmod +x $GITHUB_WORKSPACE/bin/kustomize
ls -lh $GITHUB_WORKSPACE/bin
echo "::add-path::$GITHUB_WORKSPACE/bin"
echo "::add-path::$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin"

46
.github/workflows/e2e.yaml vendored Normal file
View File

@ -0,0 +1,46 @@
name: e2e
on:
pull_request:
push:
branches:
- master
jobs:
kind:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Restore Go cache
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup Go
uses: actions/setup-go@v2-beta
with:
go-version: 1.13.x
- name: Setup Kubernetes
uses: engineerd/setup-kind@v0.3.0
- name: Setup Kustomize
uses: ./.github/actions/kustomize
- name: Setup Kubebuilder
uses: ./.github/actions/kubebuilder
- name: Run tests and build image
run: make docker-build IMG=test/source-controller:latest
env:
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
- name: Load test image
run: kind load docker-image test/source-controller:latest
- name: Deploy controller
run: make dev-deploy IMG=test/source-controller:latest
env:
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin
- name: Debug failure
if: failure()
run: |
kubectl -n sourcer-system get all
kubectl -n sourcer-system logs deploy/sourcer-controller

1
.gitignore vendored
View File

@ -14,3 +14,4 @@
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/
bin/ bin/
tmp/

View File

@ -35,9 +35,13 @@ uninstall: manifests
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config # Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG} cd config/manager && kustomize edit set image fluxcd/sourcer=${IMG}
kustomize build config/default | kubectl apply -f - kustomize build config/default | kubectl apply -f -
# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
dev-deploy: manifests
./hack/dev-deploy.sh $(IMG)
# Generate manifests e.g. CRD, RBAC etc. # Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths="./..." output:crd:artifacts:config=config/crd/bases $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths="./..." output:crd:artifacts:config=config/crd/bases
@ -78,3 +82,5 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen
else else
CONTROLLER_GEN=$(shell which controller-gen) CONTROLLER_GEN=$(shell which controller-gen)
endif endif

View File

@ -21,7 +21,8 @@ spec:
terminationGracePeriodSeconds: 10 terminationGracePeriodSeconds: 10
containers: containers:
- name: manager - name: manager
image: controller image: fluxcd/sourcer
imagePullPolicy: IfNotPresent
ports: ports:
- containerPort: 8080 - containerPort: 8080
name: http name: http

View File

@ -5,6 +5,5 @@ resources:
- service.yaml - service.yaml
- deployment.yaml - deployment.yaml
images: images:
- name: controller - name: fluxcd/sourcer
newName: fluxcd/sourcer
newTag: 0.0.1-alpha.1 newTag: 0.0.1-alpha.1

24
hack/dev-deploy.sh Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -o errexit
IMG=$1
TMP_DIR="$(git rev-parse --show-toplevel)/tmp"
mkdir -p ${TMP_DIR}
cat << EOF | tee ${TMP_DIR}/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: sourcer-system
namePrefix: sourcer-
bases:
- ../config/crd
- ../config/rbac
- ../config/manager
EOF
cd ${TMP_DIR} && kustomize edit set image fluxcd/sourcer=${IMG}
kustomize build ${TMP_DIR} | kubectl apply -f -
rm -rf ${TMP_DIR}
kubectl -n sourcer-system rollout status deploy/sourcer-controller --timeout=1m