diff --git a/.dockerignore b/.dockerignore index 6f1931b..7efcaf3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,4 @@ !go.mod !go.sum !*.go +dist diff --git a/.github/workflows/on_merge.yaml b/.github/workflows/on_merge.yaml index a0d8bbb..59b0e0b 100644 --- a/.github/workflows/on_merge.yaml +++ b/.github/workflows/on_merge.yaml @@ -19,4 +19,8 @@ jobs: with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" } - name: run continuous deployment actions - run: earthly --push +continuous-deploy --token ${{ secrets.GITHUB_TOKEN }} + run: | + ./earthly \ + --push \ + +continuous-deploy \ + --token ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 2de42b9..deb9976 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -12,7 +12,7 @@ on: jobs: - build: + build-image: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 @@ -22,7 +22,12 @@ jobs: - uses: earthly/actions-setup@v1 with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" } - - run: earthly +build --GOLANG_VERSION=${{ env.GOLANG_TOOL_VERSION }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + # intentionally avoiding --push, this is just + # to test the command + - run: ./earthly +build-image-multiarch release-test: runs-on: ubuntu-22.04 @@ -36,7 +41,7 @@ jobs: # intentionally avoiding --push, this is just # to test the command - - run: earthly +release --GOLANG_VERSION=${{ env.GOLANG_TOOL_VERSION }} + - run: ./earthly +release-binaries skaffold: runs-on: ubuntu-22.04 diff --git a/.github/workflows/on_pull_request_go.yaml b/.github/workflows/on_pull_request_go.yaml index e0965ed..19811a2 100644 --- a/.github/workflows/on_pull_request_go.yaml +++ b/.github/workflows/on_pull_request_go.yaml @@ -20,4 +20,4 @@ jobs: - uses: earthly/actions-setup@v1 with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" } - - run: earthly +ci-golang --GOLANG_VERSION=${{ env.GOLANG_TOOL_VERSION }} + - run: ./earthly +ci-golang diff --git a/.github/workflows/on_pull_request_helm.yaml b/.github/workflows/on_pull_request_helm.yaml index 74863c8..15c6c03 100644 --- a/.github/workflows/on_pull_request_helm.yaml +++ b/.github/workflows/on_pull_request_helm.yaml @@ -17,4 +17,4 @@ jobs: - uses: earthly/actions-setup@v1 with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" } - - run: earthly +ci-helm + - run: ./earthly +ci-helm diff --git a/.github/workflows/on_release.yaml b/.github/workflows/on_release.yaml index 65511c0..d517642 100644 --- a/.github/workflows/on_release.yaml +++ b/.github/workflows/on_release.yaml @@ -33,12 +33,12 @@ jobs: - name: Build and push the binaries run: | - earthly \ + ./earthly \ --push \ +release-binaries \ - --version=${{ env.RELEASE_VERSION }} \ - --commitSHA=${{ env.SHORT_SHA }} \ - --token ${{ secrets.GITHUB_TOKEN }} + --version=${{ env.RELEASE_VERSION }} \ + --commitSHA=${{ env.SHORT_SHA }} \ + --token ${{ secrets.GITHUB_TOKEN }} release-image: runs-on: ubuntu-22.04 @@ -67,9 +67,9 @@ jobs: - name: Build and push the Docker image run: | - earthly \ + ./earthly \ --push \ +build-image-multiarch \ - --version=${{ env.RELEASE_VERSION }} \ - --commitSHA=${{ env.SHORT_SHA }} \ - --image_name=ghcr.io/${{ github.repository_owner }}/prom-aggregation-gateway + --version=${{ env.RELEASE_VERSION }} \ + --commitSHA=${{ env.SHORT_SHA }} \ + --image_name=ghcr.io/${{ github.repository_owner }}/prom-aggregation-gateway diff --git a/.tool-versions b/.tool-versions index 44d1b83..41cec77 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,9 @@ -# asdf plugin add earthly https://github.com/YR-ZR0/asdf-earthly -earthly 0.6.30 +earthly 0.8.5 +github-cli 2.36.0 golang 1.21.3 -skaffold 2.0.3 +helm-cr 1.4.1 +helm-ct 3.7.1 +kubeconform 0.5.0 +minikube 1.32.0 +skaffold 2.10.1 +staticcheck 2023.1.6 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d95da52..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# builder image -FROM golang:1.21.3-alpine3.18 AS builder - -ARG COMMIT_SHA -ARG VERSION_TAG -ARG GO_MOD_PATH="github.com/zapier/prom-aggregation-gateway" - -RUN mkdir /build -ADD . /build/ -WORKDIR /build - -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-X ${GO_MOD_PATH}/config.CommitSHA=${COMMIT_SHA} -X ${GO_MOD_PATH}/config.Version=${VERSION_TAG}" -a -o prom-aggregation-gateway . - -# generate clean, final image for end users -FROM alpine:3.18 -COPY --chown=nobody:nogroup --from=builder /build/prom-aggregation-gateway . - -USER 65534 - -# executable -ENTRYPOINT [ "./prom-aggregation-gateway" ] diff --git a/Earthfile b/Earthfile index ef58b39..0896680 100644 --- a/Earthfile +++ b/Earthfile @@ -1,21 +1,13 @@ -VERSION 0.6 +VERSION 0.8 -ARG image_name="prom-aggregation-gateway" -ARG token="" +ARG --global token="" -ARG commitSHA="" -ARG version="dev" -ARG PKG_PATH="github.com/zapier/prom-aggregation-gateway" +ARG --global commitSHA="" +ARG --global version="dev" +ARG --global PKG_PATH="github.com/zapier/prom-aggregation-gateway" -ARG ALPINE_VERSION="3.18.4" -ARG GOLANG_ALPINE_VERSION="3.18" -ARG CHART_RELEASER_VERSION="1.4.1" -ARG CHART_TESTING_VERSION="3.7.1" -ARG GITHUB_CLI_VERSION="2.36.0" -ARG GOLANG_VERSION="1.21.3" -ARG HELM_UNITTEST_VERSION="0.2.8" -ARG KUBECONFORM_VERSION="0.5.0" -ARG STATICCHECK_VERSION="2023.1.6" +ARG --global ALPINE_VERSION="3.18" +ARG --global --required GOLANG_VERSION test: BUILD +ci-golang @@ -40,7 +32,7 @@ release: BUILD +build-image go-deps: - FROM golang:${GOLANG_VERSION}-alpine${GOLANG_ALPINE_VERSION} + FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} WORKDIR /src COPY go.mod go.sum /src @@ -64,6 +56,8 @@ build-image: ENV GIN_MODE=release USER 65534 ENTRYPOINT ["/prom-aggregation-gateway"] + + ARG image_name="prom-aggregation-gateway" SAVE IMAGE --push ${image_name}:${version} SAVE IMAGE --push ${image_name}:latest @@ -104,6 +98,7 @@ release-binaries: COPY +build-binaries/_dist dist # install github cli + ARG --required GITHUB_CLI_VERSION RUN FILE=ghcli.tgz \ && URL=https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}/gh_${GITHUB_CLI_VERSION}_linux_amd64.tar.gz \ && wget ${URL} \ @@ -125,6 +120,7 @@ lint-golang: FROM +go-deps # install staticcheck + ARG --required STATICCHECK_VERSION RUN FILE=staticcheck.tgz \ && URL=https://github.com/dominikh/go-tools/releases/download/${STATICCHECK_VERSION}/staticcheck_linux_amd64.tar.gz \ && wget ${URL} \ @@ -150,9 +146,12 @@ test-golang: RUN go test . test-helm: + ARG --required CHART_TESTING_VERSION + FROM quay.io/helmpack/chart-testing:v${CHART_TESTING_VERSION} # install kubeconform + ARG --required KUBECONFORM_VERSION RUN FILE=kubeconform.tgz \ && URL=https://github.com/yannh/kubeconform/releases/download/v${KUBECONFORM_VERSION}/kubeconform-linux-amd64.tar.gz \ && wget ${URL} \ @@ -164,6 +163,7 @@ test-helm: --file ${FILE} \ && kubeconform -v + ARG HELM_UNITTEST_VERSION="0.2.8" RUN apk add --no-cache bash git \ && helm plugin install --version "${HELM_UNITTEST_VERSION}" https://github.com/quintush/helm-unittest \ && helm unittest --help @@ -175,6 +175,8 @@ test-helm: RUN ct --config ./.github/ct.yaml lint ./charts build-helm: + ARG --required CHART_RELEASER_VERSION + FROM quay.io/helmpack/chart-releaser:v${CHART_RELEASER_VERSION} ARG token diff --git a/earthly b/earthly new file mode 100755 index 0000000..fd30bef --- /dev/null +++ b/earthly @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +to_echo() { + if [ "$1" -eq 1 ]; then + echo "$2" + fi +} + +read_tool_versions_write_to_env() { + local -r tool_versions_file="$1" + + # loop over each line of the .tool-versions file + while read -r line; do + # split the line into a bash array using the default space delimeter + IFS=" " read -r -a lineArray <<<"$line" + + # get the key and value from the array, set the key to all uppercase + key="${lineArray[0],,}" + value="${lineArray[1]}" + + # ignore comments, comments always start with # + if [[ ${key:0:1} != "#" ]]; then + full_key="${key/-/_}_tool_version" + export "${full_key}=${value}" + fi + done <"$tool_versions_file" +} + +read_tool_versions_write_to_env '.tool-versions' + +set -x + +earthly $* \ + --CHART_RELEASER_VERSION=${helm_cr_tool_version} \ + --CHART_TESTING_VERSION=${helm_ct_tool_version} \ + --GITHUB_CLI_VERSION=${github_cli_tool_version} \ + --GOLANG_VERSION=${golang_tool_version} \ + --KUBECONFORM_VERSION=${kubeconform_tool_version} \ + --STATICCHECK_VERSION=${staticcheck_tool_version} diff --git a/justfile b/justfile new file mode 100644 index 0000000..5556fa6 --- /dev/null +++ b/justfile @@ -0,0 +1,7 @@ +minikube-up: + minikube start + minikube addons enable ingress + minikube addons enable registryi + +minikube-reset: + minikube delete --all diff --git a/skaffold.yaml b/skaffold.yaml index b395997..f16ebc8 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -7,7 +7,7 @@ build: artifacts: - image: prom-aggregation-gateway custom: - buildCommand: earthly +build-image --version=$IMAGE_TAG --image_name=$IMAGE_REPO + buildCommand: EARTHLY_DISABLE_REMOTE_REGISTRY_PROXY=true ./earthly +build-image --version=$IMAGE_TAG --image_name=$IMAGE_REPO --no-satellite tagPolicy: customTemplate: template: dev