Skip to content
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

Replace Drone pipeline with Github actions #2168

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
110 changes: 110 additions & 0 deletions .github/workflows/release-fleet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Fleet release workflow
name: Fleet release

on:
push:
tags:
- v**

permissions:
contents: write
packages: write

env:
GOARCH: amd64
CGO_ENABLED: 0
SETUP_K3D_VERSION: 'v5.5.1'

jobs:
build-fleet:
runs-on: ubuntu-latest
steps:
- name: Check out Fleet
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true

- name: Run golangci-lint
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always
# use the latest patch version.
version: v1.55
args: --timeout=10m --config=.golangci.json

- name: Run FOSSA scan
uses: fossas/[email protected]
with:
api-key: ${{ secrets.FOSSA_API_KEY }}

- name: Run FOSSA tests
uses: fossas/[email protected]
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
run-tests: true

- name: Check for code changes
run: |
./.github/scripts/check-for-auto-generated-changes.sh
go mod verify
- name: Run unit tests
run: go test -cover -tags=test $(go list ./... | grep -v -e /e2e -e /integrationtests)

- name: Run integration tests
env:
SETUP_ENVTEST_VER: v0.0.0-20240115093953-9e6e3b144a69
ENVTEST_K8S_VERSION: 1.28
run: ./.github/scripts/run-integration-tests.sh

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log into Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: v1.24.0
args: release --clean --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload charts to release
env:
weyfonk marked this conversation as resolved.
Show resolved Hide resolved
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
manno marked this conversation as resolved.
Show resolved Hide resolved
repo: "ghcr.io/rancher/fleet"
tag: "${GITHUB_REF_NAME}"
run: |
sed -i \
-e "s@repository:.*@repository: $repo@" \
-e "s/tag:.*/tag: ${VERSION}/" \
charts/fleet/values.yaml
sed -i \
-e "s@repository:.*@repository: $repo@" \
-e "s/tag: dev/tag: ${VERSION}/" \
charts/fleet-agent/values.yaml
helm package --version="$VERSION" --app-version="$VERSION" -d ./dist ./charts/fleet
helm package --version="$VERSION" --app-version="$VERSION" -d ./dist ./charts/fleet-crd
helm package --version="$VERSION" --app-version="$VERSION" -d ./dist ./charts/fleet-agent
for f in $(find dist/artifacts/ -name '*.tgz'); do
gh release upload $tag $f
done
268 changes: 268 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
---
project_name: fleet

before:
hooks:
- go mod download

archives:
- id: fleet-controller
format: binary
name_template: "{{ .Binary }}"
builds:
- fleet-controller

- id: fleet-agent
format: binary
name_template: "{{ .Binary }}"
builds:
- fleet-agent

- id: fleet-gitcloner
format: binary
name_template: "{{ .Binary }}"
builds:
- fleet-gitcloner

- id: fleet-gitjob
format: binary
name_template: "{{ .Binary }}"
builds:
- fleet-gitjob

- id: fleet-cli
format: binary
name_template: "{{ .Binary }}"
builds:
- fleet-cli

builds:
-
id: fleet-controller
main: ./cmd/fleetcontroller
binary: fleetcontroller-{{ .Os }}-{{ .Arch }}{{ if .Arm }}64{{ end }}
no_unique_dist_dir: true
# gcflags:
# - all="-N -l"
ldflags:
- -w -s
- -X github.com/rancher/fleet/pkg/version.GitCommit={{ .Commit }}
- -X github.com/rancher/fleet/pkg/version.Version={{ .Tag }}
targets:
- linux_amd64_v1
- linux_arm64
-
id: fleet-agent
main: ./cmd/fleetagent
binary: fleetagent-{{ .Os }}-{{ .Arch }}{{ if .Arm }}64{{ end }}
no_unique_dist_dir: true
ldflags:
- -w -s
- -X github.com/rancher/fleet/pkg/version.GitCommit={{ .Commit }}
- -X github.com/rancher/fleet/pkg/version.Version={{ .Tag }}
targets:
- linux_amd64_v1
- linux_arm64
- windows_amd64
-
id: fleet-gitcloner
main: ./cmd/gitcloner
binary: gitcloner-{{ .Os }}-{{ .Arch }}{{ if .Arm }}64{{ end }}
no_unique_dist_dir: true
ldflags:
- -w -s
- -X github.com/rancher/fleet/pkg/version.GitCommit={{ .Commit }}
- -X github.com/rancher/fleet/pkg/version.Version={{ .Tag }}
targets:
- linux_amd64_v1
- linux_arm64
-
id: fleet-gitjob
main: ./cmd/gitjob
binary: gitjob-{{ .Os }}-{{ .Arch }}{{ if .Arm }}64{{ end }}
no_unique_dist_dir: true
ldflags:
- -w -s
- -X github.com/rancher/fleet/pkg/version.GitCommit={{ .Commit }}
- -X github.com/rancher/fleet/pkg/version.Version={{ .Tag }}
targets:
- linux_amd64_v1
- linux_arm64
-
id: fleet-cli
main: ./cmd/fleetcli
binary: fleet-{{ .Os }}-{{ .Arch }}{{ if .Arm }}64{{ end }}
no_unique_dist_dir: true
ldflags:
- -w -s
- -X github.com/rancher/fleet/pkg/version.GitCommit={{ .Commit }}
- -X github.com/rancher/fleet/pkg/version.Version={{ .Tag }}
targets:
- linux_amd64_v1
- linux_arm64
- windows_amd64

changelog:
## Delegate Changelog to release-drafter
disable: false
use: github

env:
- CGO_ENABLED=0

snapshot:
name_template: "{{ .Tag }}-next"

dockers:
# fleet-controller images
-
use: buildx

# GOOS of the built binaries/packages that should be used.
goos: linux

# GOARCH of the built binaries/packages that should be used.
goarch: amd64

# IDs to filter the binaries/packages.
ids:
- fleet-controller

# Templates of the Docker image names.
image_templates:
- "ghcr.io/rancher/fleet:{{ .Tag }}-linux-amd64"

# Path to the Dockerfile (from the project root).
dockerfile: package/Dockerfile

# Template of the docker build flags.
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/rancher/fleet"
- "--build-arg=ARCH=amd64"
- "--build-arg=BUILD_ENV=goreleaser"
- "--platform=linux/amd64"
-
use: buildx
goos: linux
goarch: arm64
ids:
- fleet-controller
image_templates:
- "ghcr.io/rancher/fleet:{{ .Tag }}-linux-arm64"
dockerfile: package/Dockerfile
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/rancher/fleet"
- "--build-arg=ARCH=arm64"
- "--build-arg=BUILD_ENV=goreleaser"
- "--platform=linux/arm64/v8"
# fleet-agent images
-
use: buildx
goos: linux
goarch: amd64
ids:
- fleet-agent
- fleet-cli
image_templates:
- "ghcr.io/rancher/fleet-agent:{{ .Tag }}-linux-amd64"
dockerfile: package/Dockerfile.agent
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/rancher/fleet"
- "--build-arg=ARCH=amd64"
- "--build-arg=BUILD_ENV=goreleaser"
- "--platform=linux/amd64"
extra_files: [ "package/log.sh" ]
-
use: buildx
goos: linux
goarch: arm64
ids:
- fleet-agent
- fleet-cli
image_templates:
- "ghcr.io/rancher/fleet-agent:{{ .Tag }}-linux-arm64"
dockerfile: package/Dockerfile.agent
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/rancher/fleet"
- "--build-arg=ARCH=arm64"
- "--build-arg=BUILD_ENV=goreleaser"
- "--platform=linux/arm64/v8"
extra_files: [ "package/log.sh" ]
# fleet-gitjob images
-
use: buildx
goos: linux
goarch: amd64
ids:
- fleet-gitcloner
- fleet-gitjob
image_templates:
- "ghcr.io/rancher/fleet-gitjob:{{ .Tag }}-linux-amd64"
dockerfile: package/Dockerfile.gitjob
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/rancher/fleet"
- "--build-arg=ARCH=amd64"
- "--build-arg=BUILD_ENV=goreleaser"
- "--platform=linux/amd64"
-
use: buildx
goos: linux
goarch: arm64
ids:
- fleet-gitcloner
- fleet-gitjob
image_templates:
- "ghcr.io/rancher/fleet-gitjob:{{ .Tag }}-linux-arm64"
dockerfile: package/Dockerfile.gitjob
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/rancher/fleet"
- "--build-arg=ARCH=arm64"
- "--build-arg=BUILD_ENV=goreleaser"
- "--platform=linux/arm64/v8"

docker_manifests:
# https://goreleaser.com/customization/docker_manifest/
- name_template: "ghcr.io/rancher/fleet:{{ .Tag }}"
image_templates:
- "ghcr.io/rancher/fleet:{{ .Tag }}-linux-amd64"
- "ghcr.io/rancher/fleet:{{ .Tag }}-linux-arm64"

- name_template: "ghcr.io/rancher/fleet-agent:{{ .Tag }}"
image_templates:
- "ghcr.io/rancher/fleet-agent:{{ .Tag }}-linux-amd64"
- "ghcr.io/rancher/fleet-agent:{{ .Tag }}-linux-arm64"

- name_template: "ghcr.io/rancher/fleet-gitjob:{{ .Tag }}"
image_templates:
- "ghcr.io/rancher/fleet-gitjob:{{ .Tag }}-linux-amd64"
- "ghcr.io/rancher/fleet-gitjob:{{ .Tag }}-linux-arm64"
7 changes: 6 additions & 1 deletion package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG BUILD_ENV=dapper
ARG ARCH

FROM registry.suse.com/bci/bci-busybox:15.5 AS base
FROM --platform=linux/$ARCH registry.suse.com/bci/bci-busybox:15.5 AS base

FROM base AS copy_dapper
ONBUILD ARG ARCH
Expand All @@ -10,6 +11,10 @@ FROM base AS copy_buildx
ONBUILD ARG TARGETARCH
ONBUILD COPY bin/fleetcontroller-linux-${TARGETARCH} /usr/bin/fleetcontroller

FROM base AS copy_goreleaser
ONBUILD ARG ARCH
ONBUILD COPY fleetcontroller-linux-${ARCH} /usr/bin/fleetcontroller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is needed because of no_unique_dist_dirs?

Previously:

fleet/package/Dockerfile

Lines 11 to 12 in fb18a5e

FROM base AS copy_goreleaser
ONBUILD COPY fleetcontroller /usr/bin/fleetcontroller

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.


FROM copy_${BUILD_ENV}
RUN addgroup -g 1000 fleet-apply && adduser -u 1000 -G fleet-apply -D fleet-apply
USER 1000
Expand Down
Loading
Loading