diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..e45d6c8 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,51 @@ +name: ci + +env: + CGO_ENABLED: 0 + YQ_VERSION: v4.25.1 + +on: [ pull_request ] +permissions: + contents: read +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name : setup Go + uses : actions/setup-go@v5 + with: + go-version: 1.22 + - name: Install mikefarah/yq + run: | + sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; + - name : Install helm + run : | + curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 + chmod 700 get_helm.sh + ./get_helm.sh + helm version + - name: Perform CI + run : make ci + push-images: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name : Export image version + run : | + source ./scripts/version + echo IMAGE=$IMAGE >> $GITHUB_ENV + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build Helm Project Operator image + uses: docker/build-push-action@v5 + with: + context: . + file: ./package/Dockerfile + push: false + tags: ${{ env.IMAGE }} + platforms: linux/amd64 \ No newline at end of file diff --git a/.github/workflows/e2e-ci.yaml b/.github/workflows/e2e-ci.yaml index 602877c..d633170 100644 --- a/.github/workflows/e2e-ci.yaml +++ b/.github/workflows/e2e-ci.yaml @@ -26,7 +26,6 @@ on: - 'Makefile' env: - GOARCH: amd64 CGO_ENABLED: 0 YQ_VERSION: v4.25.1 E2E_CI: true @@ -49,25 +48,21 @@ jobs: # k3d version list k3s | sed 's/+/-/' | sort -h - ${{ github.event.inputs.k3s_version || 'v1.20.15-k3s1' }} steps: - - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name : setup Go uses : actions/setup-go@v5 with: go-version: 1.22 - - - name: Install mikefarah/yq + - name: Install mikefarah/yq run: | sudo wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq; - - - name: Perform CI + - name: Perform CI run: | REPO=${REPO} TAG=${TAG} ./scripts/build; REPO=${REPO} TAG=${TAG} ./scripts/package; - - - name: Provision k3d Cluster + - name: Provision k3d Cluster uses: AbsaOSS/k3d-action@v2 # k3d will automatically create a network named k3d-test-cluster-1 with the range 172.18.0.0/16 with: @@ -76,40 +71,31 @@ jobs: --agents 1 --network "nw01" --image docker.io/rancher/k3s:${{matrix.k3s_version}} - - - name: Import Images Into k3d + - name: Import Images Into k3d run: | k3d image import ${REPO}/helm-project-operator:${TAG} -c e2e-ci-helm-project-operator; - - - name: Setup kubectl context + - name: Setup kubectl context run: | kubectl config use-context k3d-e2e-ci-helm-project-operator; - - - name: Set Up Tmate Debug Session + - name: Set Up Tmate Debug Session if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.enable_tmate == 'true' }} uses: mxschmitt/action-tmate@v3 timeout-minutes: 15 with: limit-access-to-actor: true - - - name: Install Helm Project Operator + - name: Install Helm Project Operator run: ./.github/workflows/e2e/scripts/install-helm-project-operator.sh; - - - name: Check if Helm Project Operator is up + + - name: Check if Helm Project Operator is up run: ./.github/workflows/e2e/scripts/validate-helm-project-operator.sh; - - - name: Check if Project Registration Namespace is auto-created on namespace detection + - name: Check if Project Registration Namespace is auto-created on namespace detection run: ./.github/workflows/e2e/scripts/create-project-namespace.sh; - - - name: Deploy Example Chart via ProjectHelmChart CR + - name: Deploy Example Chart via ProjectHelmChart CR run: ./.github/workflows/e2e/scripts/create-projecthelmchart.sh; - - - name: Delete Example Chart + - name: Delete Example Chart run: ./.github/workflows/e2e/scripts/delete-projecthelmchart.sh; - - - name: Uninstall Helm Project Operator + - name: Uninstall Helm Project Operator run: ./.github/workflows/e2e/scripts/uninstall-helm-project-operator.sh; - - - name: Delete k3d cluster + - name: Delete k3d cluster if: always() run: k3d cluster delete e2e-ci-helm-project-operator diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml deleted file mode 100644 index e5b4a2f..0000000 --- a/.github/workflows/pull-request.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: CI-pullrequest - -on: [pull_request] - -jobs: - build: - runs-on: ubuntu-latest - container: - image: rancher/dapper:v0.6.0 - steps: - - uses: actions/checkout@v1 - - name: Run CI - run: dapper ci diff --git a/Makefile b/Makefile index 5d7b47e..348fabd 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,8 @@ TARGETS := $(shell ls scripts) -.dapper: - @echo Downloading dapper - @curl -sL https://releases.rancher.com/dapper/latest/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp - @@chmod +x .dapper.tmp - @./.dapper.tmp -v - @mv .dapper.tmp .dapper - -$(TARGETS): .dapper - ./.dapper $@ +$(TARGETS): + ./scripts/$@ .DEFAULT_GOAL := default -.PHONY: $(TARGETS) +.PHONY: $(TARGETS) \ No newline at end of file diff --git a/package/Dockerfile b/package/Dockerfile index 4d9379c..a18d8c1 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -1,8 +1,26 @@ -FROM registry.suse.com/bci/bci-micro:15.4 +FROM registry.suse.com/bci/golang:1.22 AS helm +RUN zypper -n install git +RUN git -C / clone --branch release-v3.9.0 --depth=1 https://github.com/rancher/helm +RUN make -C /helm + +FROM registry.suse.com/bci/golang:1.22 as builder +WORKDIR /usr/src/app +ENV YQ_VERSION=v4.25.1 +RUN zypper -n install git curl wget make +RUN export ARCH=$(go env GOHOSTARCH) +RUN wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq; +COPY --from=helm ./helm/bin/helm /usr/local/bin/ +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN make build-chart +RUN make build + +FROM registry.suse.com/bci/bci-micro:15.5 RUN echo 'helmprojectoperator:x:1000:1000::/home/helmprojectoperator:/bin/bash' >> /etc/passwd && \ echo 'helmprojectoperator:x:1000:' >> /etc/group && \ mkdir /home/helmprojectoperator && \ chown -R helmprojectoperator:helmprojectoperator /home/helmprojectoperator -COPY bin/helm-project-operator /usr/bin/ +COPY --from=builder /usr/src/app/bin/helm-project-operator /usr/bin/ USER helmprojectoperator CMD ["helm-project-operator"] diff --git a/scripts/package b/scripts/package index 0df435b..b257c59 100755 --- a/scripts/package +++ b/scripts/package @@ -4,15 +4,7 @@ set -e source $(dirname $0)/version cd $(dirname $0)/.. - -mkdir -p dist/artifacts -cp bin/helm-project-operator dist/artifacts/helm-project-operator${SUFFIX} - -IMAGE=${REPO}/helm-project-operator:${TAG} +echo Building ${IMAGE} ... DOCKERFILE=package/Dockerfile -if [ -e ${DOCKERFILE}.${ARCH} ]; then - DOCKERFILE=${DOCKERFILE}.${ARCH} -fi - docker build -f ${DOCKERFILE} -t ${IMAGE} . echo Built ${IMAGE} diff --git a/scripts/version b/scripts/version index 1646092..30abcef 100755 --- a/scripts/version +++ b/scripts/version @@ -13,15 +13,10 @@ else VERSION="${COMMIT}${DIRTY}" fi -if [ -z "$ARCH" ]; then - ARCH=$(go env GOHOSTARCH) -fi - -SUFFIX="-${ARCH}" - -TAG=${TAG:-${VERSION}${SUFFIX}} +TAG=${TAG:-${VERSION}} REPO=${REPO:-rancher} if echo $TAG | grep -q dirty; then TAG=dev fi +IMAGE=${IMAGE:-${REPO}/helm-project-operator:${TAG}} \ No newline at end of file