Skip to content

Commit

Permalink
chore: adopt skaffold and just, test skeleton
Browse files Browse the repository at this point in the history
Signed-off-by: Ievgenii Shepeliuk <[email protected]>
  • Loading branch information
eshepelyuk committed Feb 4, 2022
1 parent 98a69d4 commit 44bc6eb
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 39 deletions.
28 changes: 12 additions & 16 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ on:
branches:
- "master"

env:
IMAGE: openpolicyagent/kube-mgmt

jobs:
build_job:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Build Docker image and Helm chart
run: |
docker build --build-arg VERSION=${{ env.VERSION }} \
--build-arg COMMIT=${{ env.GITHUB_SHA }} \
-t ${{ env.IMAGE }}:${{ env.VERSION }} .
helm lint charts/opa
helm package charts/opa \
--version ${{ env.VERSION }} \
--app-version ${{ env.VERSION }}
env:
VERSION: 0.0.0 # nothing ispublished, version can be set to fake value
- uses: actions/checkout@v2
- uses: volesen/[email protected]
with:
version: 'v1.33.0'
- uses: extractions/setup-just@v1
- run: just test
- uses: rinx/[email protected]
with:
skipClusterCreation: true
- run: |
just k3d
just build
31 changes: 8 additions & 23 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

env:
IMAGE: openpolicyagent/kube-mgmt

jobs:
docker_job:
name: Docker image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- uses: actions/checkout@v2
- uses: volesen/[email protected]
with:
version: 'v1.33.0'
- uses: extractions/setup-just@v1
- name: Calculate release version
id: theVersion
run: echo "::set-output name=theVersion::$(echo ${GITHUB_REF##*/})"
Expand All @@ -23,23 +23,9 @@ jobs:
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker image and Helm chart
run: |
docker build --build-arg VERSION=${{ env.VERSION }} \
--build-arg COMMIT=${{ env.GITHUB_SHA }} \
-t ${{ env.IMAGE }}:${{ env.VERSION }} .
helm package charts/opa \
--version ${{ env.VERSION }} \
--app-version ${{ env.VERSION }}
env:
VERSION: ${{ steps.theVersion.outputs.theVersion }}
- name: Publish Docker image
- name: Build docker image
run: |
docker push ${{ env.IMAGE }}:${{ env.VERSION }}
docker tag ${{ env.IMAGE }}:${{ env.VERSION }} ${{ env.IMAGE }}:latest
docker push ${{ env.IMAGE }}:latest
env:
VERSION: ${{ steps.theVersion.outputs.theVersion }}
just VERSION=${{ steps.theVersion.outputs.theVersion }} build-latest
- name: Upload Helm artifact
uses: actions/upload-artifact@v2
with:
Expand All @@ -51,8 +37,7 @@ jobs:
runs-on: ubuntu-latest
needs: docker_job
steps:
- name: Checkout gh-pages
uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
ref: gh-pages
- name: Download artifact from build job
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bin
.go
*.tgz
skaffold.json



41 changes: 41 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export COMMIT := `git rev-parse --short HEAD`
export VERSION := "0.0.0-" + COMMIT

default:
@just --list

@skaffold-ctx:
skaffold config set default-repo localhost:5000 -k k3d-kube-mgmt

# build docker image and pack helm chart
@build: skaffold-ctx
skaffold build -t {{VERSION}} --file-output=skaffold.json
helm package charts/opa --version {{VERSION}} --app-version {{VERSION}}

build-latest: build
#!/usr/bin/env bash
set -euxo pipefail
LATEST="$(jq -r .builds[0].imageName skaffold.json):latest"
CURRENT="$(jq -r .builds[0].tag skaffold.json)"
docker tag $CURRENT $LATEST
docker push $LATEST
@test-helm:
./test/linter/test.sh

@test-e2e:
./test/e2e/test.sh

# run all tests
test: test-helm test-e2e

# recreate local k8s cluster with k3d
@k3d: && skaffold-ctx
k3d cluster delete kube-mgmt || true
k3d cluster create --config ./test/e2e/k3d.yaml

# @up: skaffold-ctx build
# skaffold run
#
# @down:
# skaffold delete || true
31 changes: 31 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: skaffold/v2beta19
kind: Config
metadata:
name: kube-mgmt
build:
artifacts:
- image: openpolicyagent/kube-mgmt
context: .
docker:
buildArgs:
VERSION: "{{.VERSION}}"
COMMIT: "{{.COMMIT}}"
local:
push: true
useBuildkit: true
profiles:
- name: local
activation:
- kubeContext: k3d-kube-mgmt
deploy:
helm:
releases:
- name: kube-mgmt
chartPath: charts/opa
wait: true
upgradeOnChange: false
skipBuildDependencies: true
artifactOverrides:
image: openpolicyagent/kube-mgmt
imageStrategy:
helm: {}
22 changes: 22 additions & 0 deletions test/e2e/k3d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: k3d.io/v1alpha3
kind: Simple
name: kube-mgmt
servers: 1
agents: 0
registries:
create:
name: kube-mgmt-registry
host: "0.0.0.0"
hostPort: "5000"
config: |
mirrors:
"localhost:5000":
endpoint:
- http://kube-mgmt-registry:5000
options:
k3d:
disableLoadbalancer: true
k3s:
extraArgs:
- arg: "--disable=servicelb,traefik,local-storage,metrics-server"
nodeFilters: ["all"]
4 changes: 4 additions & 0 deletions test/e2e/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "E2E tests version=${VERSION}, sha=${COMMIT}"

10 changes: 10 additions & 0 deletions test/linter/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

helm lint charts/opa --strict
if [ $? -ne 0 ]; then
exit 1
fi

echo "=================================================================================="
echo " LINT PASSED"
echo "=================================================================================="

0 comments on commit 44bc6eb

Please sign in to comment.