Skip to content

Replace Makefile with Taskfile #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/e2e.yaml

This file was deleted.

17 changes: 12 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ jobs:
with:
go-version-file: "go.mod"

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Docker Login
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v1
Expand All @@ -52,12 +61,10 @@ jobs:
echo IMAGE_TAG="$(git describe --tags --always)" >> $GITHUB_ENV
fi

- name: Generate the operator-controller release manifests
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
make quickstart VERSION=${GITHUB_REF#refs/tags/}
- name: Install Task
run: go install github.com/go-task/task/v3/cmd/task@latest

- name: Run goreleaser
run: make release
run: task release
env:
GITHUB_TOKEN: ${{ github.token }}
51 changes: 51 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: test

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
test: [ sanity, unit, e2e ]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version-file: go.mod

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Install Task
run: go install github.com/go-task/task/v3/cmd/task@latest

- name: Run ${{matrix.test}} test
run: |
task test:${{matrix.test}}

- name: Convert coverage data to Codecov format
if: ${{matrix.test == 'unit' || matrix.test == 'e2e'}}
run: |
go tool covdata textfmt -i=coverage/${{matrix.test}} -o=coverage/${{matrix.test}}.out

- name: Upload coverage data to Codecov
if: ${{matrix.test == 'unit' || matrix.test == 'e2e'}}
uses: codecov/codecov-action@v3
with:
file: coverage/${{matrix.test}}.out
flags: ${{matrix.test}}
fail_ci_if_error: true

32 changes: 0 additions & 32 deletions .github/workflows/unit-test.yaml

This file was deleted.

19 changes: 5 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@ vendor
*.dll
*.so
*.dylib
bin/*
testbin/*
Dockerfile.cross
**/bin/*

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
/coverage

# Release output
dist/**
operator-controller.yaml
install.sh

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*
/dist/**
/install.sh
/operator-controller*.yaml

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~

# TODO dfranz remove this line and the bin folder when tools binaries are moved to their own folder
!bin/.dockerignore
15 changes: 12 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ builds:
- id: operator-controller
main: ./
binary: bin/manager
tags: $GO_BUILD_TAGS
tags:
- "{{ .Env.GO_BUILD_TAGS }}"
goos:
- linux
goarch:
- amd64
- arm64
- ppc64le
- s390x
flags:
- -cover={{ .Env.GO_COVER }}
mod_timestamp: "{{ .CommitTimestamp }}"
asmflags:
- all=-trimpath={{ dir .Env.PWD }}
gcflags:
- all=-trimpath={{ dir .Env.PWD }}
ldflags:
- -X main.Version={{ .Version }}
dockers:
- image_templates:
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
- "{{ .Env.IMAGE_REPO }}:{{ .Env.IMAGE_TAG }}-amd64"
dockerfile: Dockerfile
goos: linux
goarch: amd64
Expand Down Expand Up @@ -58,11 +66,12 @@ changelog:
release:
disable: '{{ ne .Env.ENABLE_RELEASE_PIPELINE "true" }}'
extra_files:
- glob: 'install.sh'
- glob: 'operator-controller.yaml'
- glob: 'install.sh'
header: |
## Installation

```bash
curl -L -s https://github.com/operator-framework/operator-controller/releases/download/{{ .Tag }}/install.sh | bash -s
curl -sSL https://github.com/operator-framework/operator-controller/releases/download/{{ .Env.IMAGE_TAG }}/install.sh | bash -s
```
120 changes: 120 additions & 0 deletions .taskfile.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
version: '3'

includes:
tools:
taskfile: .taskfile.tools.yaml
internal: true

vars:
BIN: "{{.ROOT_DIR}}/bin"
KUSTOMIZE_DIR: "config/default"
CONTROLLER_MANIFEST: ./{{.PROJECT}}.yaml

OLMV0_VERSION: v0.24.0
CERT_MANAGER_VERSION: v1.9.0
RUKPAK_VERSION: v0.11.0

env:
IMAGE_REPO: quay.io/operator-framework/{{.PROJECT}}
IMAGE_TAG: devel

tasks:
generate:
desc: "Run code generation"
summary: |
This task runs go generate and controller-gen to generate code, CRDs,
webhook configurations, and RBAC manifests.
cmds:
- go generate ./...
- "{{.TOOLSBIN}}/controller-gen object:headerFile=hack/boilerplate.go.txt paths=./..."
- "{{.TOOLSBIN}}/controller-gen rbac:roleName=manager-role crd webhook paths=./... output:crd:artifacts:config=config/crd/bases"
deps: [tools:controller-gen]

binary:
desc: "Build the binaries for the current OS"
summary: |
This task uses goreleaser to build the operator binary based on GOOS and GOARCH.
By default, the binary is created at ./bin/manager.

To generate the binary for a different OS, set the GOOS task variable accordingly.

The GO_COVER task variable instruments the operator with coverage enabled when set to "true"
or disabled when set to "false". The default is "false".
env:
GOOS: "{{.GOOS}}"
GO_COVER: '{{.GO_COVER | default "false" }}'
GO_BUILD_TAGS: "{{.GO_BUILD_TAGS}}"
cmds:
- mkdir -p {{.BIN}}
- "{{.TOOLSBIN}}/goreleaser build --debug --single-target --snapshot --clean --output {{.BIN}}/manager"
deps: [tools:goreleaser, generate]

docker:
desc: "Build the docker image"
summary: |
This task builds the operator's linux binary in {{.BIN}}/linux and then uses
the Dockerfile to build the docker image in {{.BIN}}/linux.

GOARCH is taken from the environment to ensure a binary that will run on the local
machine. GOOS is always set to `linux` for the docker build.

By default, the image is tagged as quay.io/operator-framework/{{.PROJECT}}:devel.
You can control the image repo and tag by setting the IMAGE_REPO and IMAGE_TAG
environment variables.
cmds:
- docker build -f Dockerfile -t $IMAGE_REPO:$IMAGE_TAG bin/linux
deps:
- task: binary
vars:
BIN: "{{.ROOT_DIR}}/bin/linux"
GOOS: linux
GO_COVER: "{{.GO_COVER}}"

manifest:
desc: "Generate the operator manifest"
summary: |
This task uses kustomize to generate the operator manifest.

The operator manifest is generated by combining the CRD and default manifests
with the controller image set to the IMAGE_REPO and IMAGE_TAG environment variables.
cmds:
- cd config/manager && {{.TOOLSBIN}}/kustomize edit set image controller=$IMAGE_REPO:$IMAGE_TAG
- "{{.TOOLSBIN}}/kustomize build {{.KUSTOMIZE_DIR}} > {{.CONTROLLER_MANIFEST}}"
deps: [tools:kustomize, generate]

install-script:
desc: "Generate the install script"
summary: |
This task generates the install script that can be used to install the operator.

The CONTROLLER_MANIFEST task variable is used to set the location that
will be used to `kubectl apply -f` the controller manifest. By default,
this is set to `./{{.PROJECT}}.yaml`. However this can be overridden during
a release to reference the release manifest URL that is uploaded to GitHub during
the release.
silent: true
cmds:
- |
cat << EOF > ./install.sh
#!/usr/bin/env bash
set -o pipefail -o errexit -o nounset

# Install OLMv0
curl -L -s https://github.com/operator-framework/operator-lifecycle-manager/releases/download/{{.OLMV0_VERSION}}/install.sh | bash -s {{.OLMV0_VERSION}}

# Install cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/{{.CERT_MANAGER_VERSION}}/cert-manager.yaml
kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s

# Install rukpak
kubectl apply -f https://github.com/operator-framework/rukpak/releases/download/{{.RUKPAK_VERSION}}/rukpak.yaml
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/core --timeout=60s
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/helm-provisioner --timeout=60s
kubectl wait --for=condition=Available --namespace=rukpak-system deployment/rukpak-webhooks --timeout=60s
kubectl wait --for=condition=Available --namespace=crdvalidator-system deployment/crd-validation-webhook --timeout=60s

# Install controller
kubectl apply -f {{.CONTROLLER_MANIFEST}}
kubectl wait --for=condition=Available --namespace={{.PROJECT}}-system deployment/{{.PROJECT}}-controller-manager --timeout=60s
EOF
- chmod +x ./install.sh
34 changes: 34 additions & 0 deletions .taskfile.deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3'

includes:
build:
taskfile: .taskfile.build.yaml
internal: true
kind:
taskfile: .taskfile.kind.yaml
internal: true

tasks:
kind:
cmds:
- task: kind:load-image
vars:
IMAGE: "$IMAGE_REPO:$IMAGE_TAG"
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}"
- ./install.sh
deps:
- task: build:docker
vars:
GO_COVER: "{{.GO_COVER}}"
GO_BUILD_TAGS: "{{.GO_BUILD_TAGS}}"
- task: build:manifest
vars:
KUSTOMIZE_DIR: "{{.KUSTOMIZE_DIR}}"
CONTROLLER_MANIFEST: "{{.CONTROLLER_MANIFEST}}"
- task: build:install-script
vars:
CONTROLLER_MANIFEST: "{{.CONTROLLER_MANIFEST}}"
- task: kind:create
vars:
KIND_CLUSTER_NAME: "{{.KIND_CLUSTER_NAME}}"
KIND_EXTRA_FLAGS: "{{.KIND_EXTRA_FLAGS}}"
Loading