diff --git a/Dockerfile b/.docker/lifecycle-controller-manager/Dockerfile similarity index 100% rename from Dockerfile rename to .docker/lifecycle-controller-manager/Dockerfile diff --git a/cmd/lifecycle-service/Dockerfile b/.docker/lifecycle-service/Dockerfile similarity index 100% rename from cmd/lifecycle-service/Dockerfile rename to .docker/lifecycle-service/Dockerfile diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f185b41 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + - package-ecosystem: "docker" + directory: "/.docker/lifecycle-controller-manager" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + - package-ecosystem: "docker" + directory: "/.docker/lifecycle-service" + schedule: + interval: "daily" + open-pull-requests-limit: 10 \ No newline at end of file diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000..c1f2e1e --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,29 @@ +name: Dependabot auto-approve + +on: pull_request + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }} + steps: + - name: Dependabot metadata + id: dependabot-metadata + uses: dependabot/fetch-metadata@v1 + - uses: actions/checkout@v4 + - name: Setup gh cli + uses: ksivamuthu/actions-setup-gh-cli@v2 + - name: Approve a Dependabot PR + run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + - name: Enable auto-merge for Dependabot PRs + run: gh pr merge --auto --squash "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index c85dfd2..0000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Lint Golang Codebase - -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - '**/*.md' -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - uses: actions/setup-go@v4 - with: - go-version-file: go.mod - - uses: golangci/golangci-lint-action@v3 - with: - version: v1.55.2 - args: --timeout 15m diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml new file mode 100644 index 0000000..ed5c2ce --- /dev/null +++ b/.github/workflows/pipeline.yaml @@ -0,0 +1,183 @@ +name: Main commit workflow + +on: + workflow_dispatch: + push: + branches: + - main + tags: + - v* + paths-ignore: + - '**.md' + pull_request: + branches: + - main + paths-ignore: + - 'docs/**' + - '**/*.md' + +permissions: + contents: read + packages: write + + +env: + platforms: linux/amd64,linux/arm64 + registry: ghcr.io + +jobs: + go-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup golang + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Lint golang sources + uses: golangci/golangci-lint-action@v4 + with: + args: -e S1008 --timeout 15m + + go-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup golang + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run tests + run: make test + + docker-build-controller-manager: + needs: [ go-lint, go-test ] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.registry }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get metadata for docker + uses: docker/metadata-action@v5 + id: meta + with: + images: | + ghcr.io/${{ github.repository_owner }}/lifecycle-controller-manager + tags: | + type=schedule + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=semver,pattern={{version}} + type=sha + flavor: | + latest=${{ github.ref == 'refs/heads/main' }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:latest + platforms: ${{env.platforms}} + + - name: Set up Docker Context for Buildx + id: buildx-context + run: | + docker context create builders + + - name: Set up Docker Buildx + timeout-minutes: 5 + uses: docker/setup-buildx-action@v3 + with: + version: latest + endpoint: builders + + - name: Build and push + uses: docker/build-push-action@v5 + timeout-minutes: 60 + with: + file: .docker/lifecycle-controller-manager/Dockerfile + context: . + platforms: ${{ env.platforms }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + docker-build-lifecycle-service: + needs: [ go-lint, go-test ] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.registry }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Get metadata for docker + uses: docker/metadata-action@v5 + id: meta + with: + images: | + ghcr.io/${{ github.repository_owner }}/lifecycle-service + tags: | + type=schedule + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=semver,pattern={{version}} + type=sha + flavor: | + latest=${{ github.ref == 'refs/heads/main' }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:latest + platforms: ${{env.platforms}} + + - name: Set up Docker Context for Buildx + id: buildx-context + run: | + docker context create builders + + - name: Set up Docker Buildx + timeout-minutes: 5 + uses: docker/setup-buildx-action@v3 + with: + version: latest + endpoint: builders + + - name: Build and push + uses: docker/build-push-action@v5 + timeout-minutes: 60 + with: + file: .docker/lifecycle-service/Dockerfile + context: . + platforms: ${{ env.platforms }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 9a0616d..d6eb26d 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -1,25 +1,23 @@ name: Release Drafter on: + workflow_dispatch: push: branches: - main pull_request: - types: [ opened, reopened, synchronize ] + +permissions: + contents: write + pull-requests: write jobs: update_release_draft: - permissions: - # write permission is required to create a github release - contents: write - # write permission is required for autolabeler - # otherwise, read permission is required at least - pull-requests: write runs-on: ubuntu-latest steps: - # Drafts your next Release notes as Pull Requests are merged into "main" - - uses: release-drafter/release-drafter@v5 + - uses: release-drafter/release-drafter@v6 with: + disable-releaser: github.ref != 'refs/heads/main' config-name: release-drafter.yml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/size-labels.yaml b/.github/workflows/size-labels.yaml new file mode 100644 index 0000000..02d2ecd --- /dev/null +++ b/.github/workflows/size-labels.yaml @@ -0,0 +1,16 @@ +name: 'Assign size labels to PRs' + +on: [workflow_dispatch, pull_request] + +permissions: + contents: read + pull-requests: write + +jobs: + size-label: + runs-on: ubuntu-latest + steps: + - name: size-label + uses: pascalgn/size-label-action@v0.5.0 + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index d651b2e..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Pull Request Code test - -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - '**/*.md' -jobs: - tests: - name: test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - uses: actions/setup-go@v4 - with: - go-version-file: go.mod - - run: make test diff --git a/Makefile b/Makefile index 5727799..cf5d6ce 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ IMG ?= controller:latest -DOCKERFILE ?= . .PHONY: fmt fmt: goimports @@ -56,12 +55,12 @@ docs: gen-crd-api-reference-docs ## Run go generate to generate API reference do ### BUILD IMAGES ### .PHONY: docker-build-controller-manager -docker-build: ## Build docker image with the manager. - docker build . -t ${IMG} +docker-build-controller-manager: ## Build docker image with the manager. + docker build . -t ${IMG} -f .docker/lifecycle-controller-manager/Dockerfile .PHONY: docker-build-lifecycle-service -docker-build-lcmi: ## Build docker image with the manager. - docker build . -t ${IMG} -f ${DOCKERFILE} +docker-build-lifecycle-service: ## Build docker image with the manager. + docker build . -t ${IMG} -f .docker/lifecycle-service/Dockerfile ### INSTALL AND DEPLOY ### .PHONY: install @@ -73,21 +72,21 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified $(KUSTOMIZE) build config/crd | kubectl delete -f - .PHONY: deploy-controller-manager -deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. +deploy-controller-manager: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/default | kubectl apply -f - .PHONY: undeploy-controller-manager -undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. +undeploy-controller-manager: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/default | kubectl delete -f - .PHONY: deploy-lifecycle-service -deploy-lcmi: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. +deploy-lifecycle-service: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/lcmi/manager && $(KUSTOMIZE) edit set image controller=${IMG} $(KUSTOMIZE) build config/lcmi/default | kubectl apply -f - .PHONY: undeploy-lifecycle-service -undeploy-lcmi: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. +undeploy-lifecycle-service: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/lcmi/default | kubectl delete -f - ### AUXILIARY ###