Skip to content

Commit

Permalink
Merge pull request #44 from zapier/more-ci-work
Browse files Browse the repository at this point in the history
build dev image on push to main, make earthly dry
  • Loading branch information
Matt Morrison authored Jul 25, 2023
2 parents 9d52a82 + adb75c0 commit 405eb5b
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 25 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/on_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
on:
push:
branches:
- main

jobs:
release-docker:
runs-on: ubuntu-22.04

permissions:
contents: read
packages: write

strategy:
matrix:
platform:
- { earthly: linux/arm64, suffix: linux-arm64 }
- { earthly: linux/amd64, suffix: linux-amd64 }

steps:
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all
if: matrix.platform == 'linux/arm64'

- uses: actions/checkout@v3

- uses: wistia/[email protected]

- uses: earthly/actions-setup@v1
with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" }

- name: extract sha
run: |
echo "GIT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: login to registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push the Docker image
run: |
earthly \
--platform ${{ matrix.platform.earthly }} \
--push \
+docker-dev \
--HELM_VERSION=${{ env.HELM_TOOL_VERSION }} \
--KUSTOMIZE_VERSION=${{ env.KUSTOMIZE_TOOL_VERSION }} \
--GIT_TAG=main-${{ matrix.platform.suffix }} \
--GIT_COMMIT=${{ env.GIT_COMMIT }} \
--CI_REGISTRY_IMAGE=ghcr.io/${{ github.repository_owner }}/kubechecks
release-multiarch:
runs-on: ubuntu-22.04

needs:
- release-docker

permissions:
packages: write

steps:
- name: extract sha
run: |
echo "GIT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: login to registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: int128/docker-manifest-create-action@v1
with:
tags: ghcr.io/${{ github.repository_owner }}/kubechecks:${{ env.GIT_RELEASE_TAG }}
suffixes: |
-linux-amd64
-linux-arm64
11 changes: 6 additions & 5 deletions .github/workflows/on_pull-request_helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
- 'Earthfile'
- 'charts/**'

env:
EARTHLY_TOOL_VERSION: 0.7
GOLANG_TOOL_VERSION: 1.19.3

jobs:
ci-helm:
runs-on: ubuntu-22.04
Expand All @@ -21,4 +17,9 @@ jobs:
- uses: earthly/actions-setup@v1
with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" }

- run: earthly +ci-helm
- run: |
earthly \
+ci-helm \
--HELM_VERSION=${{ env.HELM_TOOL_VERSION }} \
--CHART_TESTING_VERSION=${{ env.HELM-CT_TOOL_VERSION }} \
--KUBECONFORM_VERSION=${{ env.KUBECONFORM_TOOL_VERSION }}
12 changes: 7 additions & 5 deletions .github/workflows/on_tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ jobs:
with:
image: tonistiigi/binfmt:latest
platforms: all
if: matrix.platform == 'linux/arm64'

- name: checkout the source code
uses: actions/checkout@v3
- uses: actions/checkout@v3

- uses: wistia/[email protected]

Expand All @@ -60,7 +60,7 @@ jobs:

- name: extract tag and sha
run: |
echo "GIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "GIT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "GIT_RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: login to registry
Expand All @@ -75,9 +75,11 @@ jobs:
earthly \
--platform ${{ matrix.platform.earthly }} \
--push \
+docker \
+docker-tag \
--HELM_VERSION=${{ env.HELM_TOOL_VERSION }} \
--KUSTOMIZE_VERSION=${{ env.KUSTOMIZE_TOOL_VERSION }} \
--GIT_TAG=${{ env.GIT_RELEASE_TAG }}-${{ matrix.platform.suffix }} \
--GIT_COMMIT=${{ env.GIT_SHA_SHORT }} \
--GIT_COMMIT=${{ env.GIT_COMMIT }} \
--CI_REGISTRY_IMAGE=ghcr.io/${{ github.repository_owner }}/kubechecks
release-multiarch:
Expand Down
9 changes: 6 additions & 3 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
tilt 0.33.1
earthly 0.7.12
golang 1.19.11
kustomize 4.5.7
earthly 0.7.4
helm 3.12.2
helm-ct 3.8.0
kubeconform 0.6.3
kustomize 5.1.0
tilt 0.33.2
29 changes: 19 additions & 10 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ docker:
RUN apt update && apt install -y ca-certificates curl git

WORKDIR /tmp
ARG KUSTOMIZE_VERSION=4.5.7
RUN \
curl \
--fail \
Expand All @@ -79,7 +80,9 @@ docker:
"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" \
--output install_kustomize.sh && \
chmod 700 install_kustomize.sh && \
./install_kustomize.sh 4.5.7 /usr/local/bin
./install_kustomize.sh ${KUSTOMIZE_VERSION} /usr/local/bin

ARG HELM_VERSION=3.10.0
RUN \
curl \
--fail \
Expand All @@ -89,7 +92,7 @@ docker:
"https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3" \
--output get-helm-3.sh && \
chmod 700 get-helm-3.sh && \
./get-helm-3.sh -v v3.10.0
./get-helm-3.sh -v v${HELM_VERSION}

RUN mkdir /app

Expand All @@ -102,12 +105,19 @@ docker:

CMD ["./kubechecks", "controller"]

docker-dev:
FROM +docker

ARG CI_REGISTRY_IMAGE="ghcr.io/zapier/kubechecks"
SAVE IMAGE --push $CI_REGISTRY_IMAGE:dev

docker-tag:
FROM +docker

ARG CI_REGISTRY_IMAGE="ghcr.io/zapier/kubechecks"
ARG --required GIT_TAG
ARG --required GIT_COMMIT

SAVE IMAGE --push $CI_REGISTRY_IMAGE:latest
SAVE IMAGE --push $CI_REGISTRY_IMAGE:$GIT_COMMIT
SAVE IMAGE --push $CI_REGISTRY_IMAGE:$GIT_TAG

dlv:
Expand All @@ -120,7 +130,7 @@ dlv:

docker-debug:
ARG CI_REGISTRY_IMAGE="kubechecks"
FROM +docker --GIT_TAG=debug --GIT_COMMIT=abcdef --CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE
FROM +docker --GIT_TAG=debug --GIT_COMMIT=abcdef

COPY (+dlv/dlv --GOARCH=$GOARCH --VARIANT=$TARGETVARIANT) /usr/local/bin/dlv

Expand Down Expand Up @@ -152,12 +162,10 @@ lint-golang:

test-helm:
ARG CHART_TESTING_VERSION="3.7.1"
ARG HELM_VERSION="3.8.1"
ARG HELM_UNITTEST_VERSION="0.3.3"
ARG KUBECONFORM_VERSION="0.5.0"
FROM quay.io/helmpack/chart-testing:v${CHART_TESTING_VERSION}

# install kubeconform
ARG KUBECONFORM_VERSION="0.5.0"
RUN FILE=kubeconform.tgz \
&& URL=https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz \
&& wget ${URL} \
Expand All @@ -169,9 +177,11 @@ test-helm:
--file ${FILE} \
&& kubeconform -v

ARG HELM_UNITTEST_VERSION="0.3.3"
RUN apk add --no-cache bash git \
&& helm plugin install --version "${HELM_UNITTEST_VERSION}" https://github.com/helm-unittest/helm-unittest \
&& helm unittest --help

# actually lint the chart
WORKDIR /src
COPY . /src
Expand All @@ -180,10 +190,9 @@ test-helm:

release-helm:
ARG CHART_RELEASER_VERSION="1.6.0"
ARG HELM_VERSION="3.8.1"
ARG token=""
FROM quay.io/helmpack/chart-releaser:v${CHART_RELEASER_VERSION}

ARG HELM_VERSION="3.8.1"
RUN FILE=helm.tgz \
&& URL=https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz \
&& wget ${URL} \
Expand Down
32 changes: 30 additions & 2 deletions pkg/affected_apps/best_effort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zapier/kubechecks/pkg/app_directory"
)

Expand Down Expand Up @@ -158,13 +159,40 @@ func TestBestEffortMatcher(t *testing.T) {

matcher := NewBestEffortMatcher(tt.args.repoName, testRepoFiles)
got, err = matcher.AffectedApps(context.TODO(), tt.args.fileList)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, tt.want, got, "GenerateListOfAffectedApps not equal")
assert.Equal(t, len(tt.want.Applications), len(got.Applications))
assert.Equal(t, len(tt.want.ApplicationSets), len(got.ApplicationSets))

// ordering doesn't matter, we just want to make sure the items all exist
wantAppsMap := listToMap(tt.want.Applications, appStubKey)
gotAppsMap := listToMap(got.Applications, appStubKey)
assert.Equal(t, wantAppsMap, gotAppsMap, "Applications not equal")

wantAppSetsMap := listToMap(tt.want.ApplicationSets, appSetKey)
gotAppSetsMap := listToMap(got.ApplicationSets, appSetKey)
assert.Equal(t, wantAppSetsMap, gotAppSetsMap, "ApplicationSets not equal")
})
}
}

func appSetKey(item ApplicationSet) string {
return item.Name
}

func appStubKey(stub app_directory.ApplicationStub) string {
return stub.Name
}

func listToMap[T any](items []T, makeKey func(T) string) map[string]T {
result := make(map[string]T)
for _, item := range items {
key := makeKey(item)
result[key] = item
}
return result
}

var testRepoFiles = []string{
"apps/echo-server/foo-eks-01/Chart.yaml",
"apps/echo-server/foo-eks-01/values.yaml",
Expand Down

0 comments on commit 405eb5b

Please sign in to comment.