diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml new file mode 100644 index 00000000..0a7ace83 --- /dev/null +++ b/.github/workflows/build_and_publish.yml @@ -0,0 +1,57 @@ +name: Image Build and Publish + +on: + push: + branches: + - '**' + tags: + - 'v*.*.*' + pull_request: + branches: + - 'main' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + # list of Docker images to use as base name for tags + images: | + uselagoon/remote-controller + ghcr.io/uselagoon/remote-controller + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/remote-controller.yaml b/.github/workflows/remote-controller.yaml index 7807b6ad..12953378 100644 --- a/.github/workflows/remote-controller.yaml +++ b/.github/workflows/remote-controller.yaml @@ -11,10 +11,20 @@ on: jobs: test-suite: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} strategy: + fail-fast: false matrix: - harbor: ["1.5.6", "1.6.4","1.7.5" ,"1.8.2","1.9.0"] - runs-on: ubuntu-latest + kindest_node_version: [v1.21.12, v1.22.9] + harbor: ["1.5.6", "1.9.0"] + lagoon_build_image: ["uselagoon/kubectl-build-deploy-dind:latest"] + experimental: [false] + # include: + # - kindest_node_version: v1.24.0 + # harbor: "1.9.0" + # lagoon_build_image: "uselagoon/kubectl-build-deploy-dind:latest" + # experimental: true steps: - name: Checkout uses: actions/checkout@v2 @@ -26,36 +36,41 @@ jobs: uses: actions/setup-go@v2 with: go-version: '1.17' - - name: Install kustomize, kubebuilder, helm, docker-compose, kind + - name: Install kubebuilder run: | - #kustomize - curl -sLo /tmp/kustomize_v3.5.4_linux_amd64.tar.gz https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.5.4/kustomize_v3.5.4_linux_amd64.tar.gz - sudo tar -C /usr/local/bin -xzf /tmp/kustomize_v3.5.4_linux_amd64.tar.gz #kubebuilder curl -sL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_linux_amd64.tar.gz | tar -xz -C /tmp/ sudo mkdir -p /usr/local/kubebuilder/bin sudo mv /tmp/kubebuilder_2.3.2_linux_amd64/bin/* /usr/local/kubebuilder/bin chmod +x /usr/local/kubebuilder/bin/* - #helm - curl -sL https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz | tar -xz -C /tmp/ - sudo mv /tmp/linux-amd64/helm /usr/local/bin/helm - chmod +x /usr/local/bin/helm - #docker-compose - sudo curl -sLo /usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" - sudo chmod +x /usr/local/bin/docker-compose - #kind - curl -sLo /tmp/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64 - chmod +x /tmp/kind - sudo mv /tmp/kind /usr/local/bin/ + echo "/usr/local/kubebuilder/bin" >> $GITHUB_PATH + - name: Check go, kustomize, kubebuilder, helm, kind versions + run: | + go version + kustomize version + helm version + kubebuilder version + kind version - name: Create kind cluster - uses: helm/kind-action@v1.2.0 + uses: helm/kind-action@v1.3.0 with: + version: v0.14.0 + node_image: kindest/node:${{ matrix.kindest_node_version }} config: test-resources/kind-config.yaml + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build + uses: docker/build-push-action@v2 + with: + context: . + load: true + tags: uselagoon/remote-controller:test-tag - name: Run Tests run: | export PATH=$PATH:/usr/local/kubebuilder/bin export PATH=$PATH:/usr/local/go/bin export GOPATH=$HOME/go + export OVERRIDE_BUILD_DEPLOY_DIND_IMAGE="${{matrix.lagoon_build_image}}" export HARBOR_VERSION=${{matrix.harbor}} # export GO111MODULE=on make controller-test \ No newline at end of file diff --git a/Makefile b/Makefile index 47a577d6..05fe3e03 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,8 @@ CRD_OPTIONS ?= "crd:trivialVersions=false" CONTROLLER_NAMESPACE ?= lagoon-builddeploy +OVERRIDE_BUILD_DEPLOY_DIND_IMAGE ?= uselagoon/kubectl-build-deploy-dind:latest + # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -38,10 +40,15 @@ outputcrds: manifests uninstall: manifests kustomize build config/crd | kubectl delete -f - +# Deploy controller in the configured Kubernetes cluster in ~/.kube/config +preview: manifests + cd config/manager && kustomize edit set image controller=${IMG} + OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=${OVERRIDE_BUILD_DEPLOY_DIND_IMAGE} kustomize build config/default + # Deploy controller in the configured Kubernetes cluster in ~/.kube/config deploy: manifests cd config/manager && kustomize edit set image controller=${IMG} - kustomize build config/default | kubectl apply -f - + OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=${OVERRIDE_BUILD_DEPLOY_DIND_IMAGE} kustomize build config/default | kubectl apply -f - # Generate manifests e.g. CRD, RBAC etc. manifests: controller-gen diff --git a/config/default/config.properties b/config/default/config.properties new file mode 100644 index 00000000..c87b8038 --- /dev/null +++ b/config/default/config.properties @@ -0,0 +1 @@ +OVERRIDE_BUILD_DEPLOY_DIND_IMAGE \ No newline at end of file diff --git a/config/default/envs.yaml b/config/default/envs.yaml index 026e776c..64a0c621 100644 --- a/config/default/envs.yaml +++ b/config/default/envs.yaml @@ -20,4 +20,9 @@ spec: - name: CONTROLLER_NAMESPACE valueFrom: fieldRef: - fieldPath: metadata.namespace \ No newline at end of file + fieldPath: metadata.namespace + - name: OVERRIDE_BUILD_DEPLOY_DIND_IMAGE + valueFrom: + configMapKeyRef: + name: overrides + key: OVERRIDE_BUILD_DEPLOY_DIND_IMAGE \ No newline at end of file diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index d22ccc90..3ef65238 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -23,6 +23,10 @@ bases: # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. #- ../prometheus +configMapGenerator: + - name: overrides + env: config.properties + patchesStrategicMerge: - envs.yaml # Protect the /metrics endpoint by putting it behind auth. diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 66e873ab..ad13e96b 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: uselagoon/remote-controller - newTag: test-tag + newName: controller + newTag: latest diff --git a/controller-test.sh b/controller-test.sh index 012f6302..4008b841 100755 --- a/controller-test.sh +++ b/controller-test.sh @@ -38,6 +38,9 @@ tear_down () { kubectl get ingress --all-namespaces echo "==> Get pods" kubectl get pods --all-namespaces + echo "==> Get remote logs (docker-host)" + kubectl describe pods --namespace=lagoon --selector=app.kubernetes.io/name=lagoon-remote + kubectl logs --tail=80 --namespace=lagoon --prefix --timestamps --all-containers --selector=app.kubernetes.io/name=lagoon-remote echo "==> Remove cluster" kind delete cluster --name ${KIND_NAME} echo "==> Remove services" @@ -49,8 +52,6 @@ start_docker_compose_services () { echo "==> Bring up local provider" docker-compose up -d CHECK_COUNTER=1 - # echo "==> Ensure mariadb database provider is running" - # mariadb_start_check } mariadb_start_check () { @@ -79,9 +80,7 @@ install_path_provisioner () { } build_deploy_controller () { - echo "==> Build and deploy controller" - make test - make docker-build IMG=${CONTROLLER_IMAGE} + echo "==> Install CRDs and deploy controller" make install kind load docker-image ${CONTROLLER_IMAGE} --name ${KIND_NAME} @@ -145,13 +144,20 @@ check_lagoon_build () { start_docker_compose_services install_path_provisioner +echo "==> Install helm-git plugin" +helm plugin install https://github.com/aslafy-z/helm-git + echo "==> Install lagoon-remote docker-host" helm repo add lagoon-remote https://uselagoon.github.io/lagoon-charts/ ## configure the docker-host to talk to our insecure registry kubectl create namespace lagoon helm upgrade --install -n lagoon lagoon-remote lagoon-remote/lagoon-remote \ --set dockerHost.registry=http://harbor.172.17.0.1.nip.io:32080 \ - --set dioscuri.enabled=false + --set dockerHost.storage.size=10Gi \ + --set dockerHost.extraEnvs[0].name=DOCKER_TLS_VERIFY \ + --set dockerHost.extraEnvs[0].value=1 \ + --set dioscuri.enabled=false \ + --set dbaas-operator.enabled=false CHECK_COUNTER=1 echo "===> Ensure docker-host is running" until $(kubectl -n lagoon get pods $(kubectl -n lagoon get pods | grep "lagoon-remote-docker-host" | awk '{print $1}') --no-headers | grep -q "Running") @@ -162,9 +168,6 @@ if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then sleep 5 else echo "Timeout of $CHECK_TIMEOUT for controller startup reached" - # kubectl -n lagoon get pods - # kubectl -n lagoon logs -f $(kubectl -n lagoon get pods | grep "lagoon-remote-docker-host" | awk '{print $1}') - # kubectl -n lagoon get pods $(kubectl -n lagoon get pods | grep "lagoon-remote-docker-host" | awk '{print $1}') -o yaml check_controller_log tear_down echo "================ END ================" @@ -177,11 +180,11 @@ echo "===> Docker-host is running" echo "===> Install Ingress-Nginx" kubectl create namespace ingress-nginx helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx -helm upgrade --install -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx -f test-resources/ingress-nginx-values.yaml --version 3.31.0 +helm upgrade --install -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx -f test-resources/ingress-nginx-values.yaml --version 4.0.16 NUM_PODS=$(kubectl -n ingress-nginx get pods | grep -ow "Running"| wc -l | tr -d " ") if [ $NUM_PODS -ne 1 ]; then echo "Install ingress-nginx" - helm upgrade --install -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx -f test-resources/ingress-nginx-values.yaml --version 3.31.0 + helm upgrade --install -n ingress-nginx ingress-nginx ingress-nginx/ingress-nginx -f test-resources/ingress-nginx-values.yaml --version 4.0.16 kubectl get pods --all-namespaces echo "Wait for ingress-nginx to become ready" sleep 120 @@ -230,7 +233,6 @@ echo ' \"spec\": { \"build\": { \"ci\": \"true\", - \"image\": \"uselagoon\/kubectl-build-deploy-dind:latest\", \"type\": \"branch\" }, \"gitReference\": \"origin\/main\", diff --git a/test-resources/example-project1.yaml b/test-resources/example-project1.yaml index 1c695cf3..9b497d2e 100644 --- a/test-resources/example-project1.yaml +++ b/test-resources/example-project1.yaml @@ -5,7 +5,6 @@ metadata: spec: build: ci: 'true' #to make sure that readwritemany is changed to readwriteonce - image: uselagoon/kubectl-build-deploy-dind:latest type: branch gitReference: origin/main project: diff --git a/test-resources/example-project2.yaml b/test-resources/example-project2.yaml index fd783176..9ec19c32 100644 --- a/test-resources/example-project2.yaml +++ b/test-resources/example-project2.yaml @@ -5,7 +5,6 @@ metadata: spec: build: ci: 'true' #to make sure that readwritemany is changed to readwriteonce - image: uselagoon/kubectl-build-deploy-dind:latest type: branch gitReference: origin/main project: diff --git a/test-resources/ingress-nginx-values.yaml b/test-resources/ingress-nginx-values.yaml index 7b2dc61b..a02d20a3 100644 --- a/test-resources/ingress-nginx-values.yaml +++ b/test-resources/ingress-nginx-values.yaml @@ -3,4 +3,7 @@ controller: type: NodePort nodePorts: http: 32080 - https: 32443 \ No newline at end of file + https: 32443 + watchIngressWithoutClass: true + ingressClassResource: + default: true \ No newline at end of file