diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..4c799d52 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: Continuous Integration +on: + workflow_dispatch: null + push: + branches: + - main + pull_request: null + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ 'stable', 'oldstable' ] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + - name: Vet + run: make vet + - name: Lint + run: make lint + - name: Helm Lint + run: make helm-lint + - name: Test + run: make test + - name: Build + run: make build + docker-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Docker Meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ github.event.repository.name }} + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=semver,pattern={{raw}},value=${{ github.ref_name }} + - name: Build Dockerfile + uses: docker/build-push-action@v5 + with: + context: . + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + REV=${{ github.ref_name }} diff --git a/.github/workflows/docker-hub.yml b/.github/workflows/docker-hub.yml deleted file mode 100644 index 45b58b26..00000000 --- a/.github/workflows/docker-hub.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Publish Docker Release -on: - release: - types: [ published ] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@61b9e3751b92087fd0b06925ba6dd6314e06f089 # pin@master - - name: Build - run: make build-linux - - name: Publish latest to Registry - uses: elgohr/Publish-Docker-Github-Action@13c6c46d98bc92e6c046454248cd28630400846a # pin@master - with: - name: linode/linode-cloud-controller-manager - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - tags: "latest,${{ github.event.release.tag_name }}" diff --git a/.github/workflows/label-sync.yml b/.github/workflows/label-sync.yml index df229fc0..9b097ecf 100644 --- a/.github/workflows/label-sync.yml +++ b/.github/workflows/label-sync.yml @@ -2,7 +2,7 @@ name: Sync labels on: push: branches: - - master + - main paths: - .github/labels.yml jobs: diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml deleted file mode 100644 index 9e097236..00000000 --- a/.github/workflows/release-drafter.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Release Drafter - -on: - push: - branches: - - master - -jobs: - update_release_draft: - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@fe52e97d262833ae07d05efaf1a239df3f1b5cd4 # pin@v5 - with: - config-name: release-drafter.yml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..d9cccc73 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: Release +on: + push: + tags: + - "v*.*.*" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Create Release Artifacts + run: make release + env: + IMAGE_VERSION: ${{ github.ref_name }} + - name: Upload Release Artifacts + uses: softprops/action-gh-release@v1 + with: + files: | + ./release/helm-chart-${{ github.ref_name }}.tgz + - name: Docker Meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ github.event.repository.name }} + tags: | + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=semver,pattern={{raw}},value=${{ github.ref_name }} + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and Push to Docker Hub + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index fe60f0a4..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Test -on: - push: - branches: - - master - pull_request: -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - - name: lint - run: make lint - - name: build - run: make docker-build - - name: unit test - run: make test - - name: helm lint - run: make helm-lint - - name: helm template - run: make helm-template \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b9a41d20..1c63b4e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,19 @@ -# NB: We now cross-compile the go binary locally using the Makefile -FROM alpine:latest +FROM golang:1.20-alpine as builder +RUN mkdir -p /linode +WORKDIR /linode + +COPY go.mod . +COPY go.sum . +COPY main.go . +COPY cloud ./cloud +COPY sentry ./sentry + +RUN go mod download +RUN go build -a -ldflags '-extldflags "-static"' -o /bin/linode-cloud-controller-manager-linux /linode + +FROM alpine:3.18.4 RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* -COPY dist/linode-cloud-controller-manager-linux-amd64 / -ENTRYPOINT ["/linode-cloud-controller-manager-linux-amd64"] +LABEL maintainers="Linode" +LABEL description="Linode Cloud Controller Manager" +COPY --from=builder /bin/linode-cloud-controller-manager-linux /linode-cloud-controller-manager-linux +ENTRYPOINT ["/linode-cloud-controller-manager-linux"] diff --git a/Makefile b/Makefile index 126a0a2d..2e9a7731 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ IMG ?= linode/linode-cloud-controller-manager:canary +RELEASE_DIR ?= release +GOLANGCI_LINT_IMG := golangci/golangci-lint:v1.44-alpine export GO111MODULE=on @@ -7,17 +9,22 @@ all: build .PHONY: clean clean: - go clean . - rm -r dist/* + @go clean . + @rm -rf ./.tmp + @rm -rf dist/* + @rm -rf $(RELEASE_DIR) .PHONY: codegen codegen: go generate ./... +.PHONY: vet +vet: fmt + go vet ./... + .PHONY: lint -lint: - docker run --rm -v "$(shell pwd):/var/work:ro" -w /var/work \ - golangci/golangci-lint:v1.44.0 golangci-lint run -v --timeout=5m +lint: vet + docker run --rm -v $(PWD):/app -w /app ${GOLANGCI_LINT_IMG} golangci-lint run -v --timeout=5m .PHONY: fmt fmt: @@ -41,6 +48,12 @@ build: codegen CGO_ENABLED=0 \ go build -o dist/linode-cloud-controller-manager . +.PHONY: release +release: + mkdir -p $(RELEASE_DIR) + sed -e 's/appVersion: "latest"/appVersion: "$(IMAGE_VERSION)"/g' ./deploy/chart/Chart.yaml + tar -czvf ./$(RELEASE_DIR)/helm-chart-$(IMAGE_VERSION).tgz -C ./deploy/chart . + .PHONY: imgname # print the Docker image name that will be used # useful for subsequently defining it on the shell diff --git a/deploy/chart/Chart.yaml b/deploy/chart/Chart.yaml index 74139165..c442b685 100644 --- a/deploy/chart/Chart.yaml +++ b/deploy/chart/Chart.yaml @@ -3,4 +3,4 @@ name: ccm-linode description: The Linode Cloud Controller Manager (CCM) provides a way for Kubernetes clusters to access additional Linode services. Linode's CCM will automatically provision a Linode NodeBalancer for Kubernetes Services of type "LoadBalancer". type: application version: 1.0.0 -appVersion: "v0.3.16" +appVersion: "latest"