Skip to content

Commit

Permalink
Unbreak make quick (rancher#46561)
Browse files Browse the repository at this point in the history
Recent GHA related changes have broken make quick and the related dev-scripts/build-local.sh script, which were used to compile Rancher and build charts locally.

This functionality required the dapper tool which is now being removed from all scripts.

This change is a first step to restore functionality - at least to rebuild the Rancher Manager images (server and agent).

Signed-off-by: Silvio Moioli <[email protected]>
Co-authored-by: Pedro Tashima <[email protected]>
  • Loading branch information
moio and tashima42 committed Aug 7, 2024
1 parent fa66ca0 commit 00177b3
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ tests/validation/.idea
all.yaml
kustomization.yaml
kontainer-engine
k3s-images.txt
k3s-airgap-images.tar
data.json
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TARGETS := $(shell ls scripts)
DEV_TARGETS := $(shell ls dev-scripts)

.dapper:
@echo Downloading dapper
Expand All @@ -16,4 +17,7 @@ $(TARGETS): .dapper

.DEFAULT_GOAL := ci

.PHONY: $(TARGETS)
$(DEV_TARGETS):
./dev-scripts/$@

.PHONY: $(TARGETS) $(DEV_TARGETS)
65 changes: 0 additions & 65 deletions dev-scripts/build-local.sh

This file was deleted.

58 changes: 58 additions & 0 deletions dev-scripts/quick
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

## This script builds the Rancher server image exclusively, sans Dapper

set -eo pipefail
set -x

# variables
COMMIT=$(git rev-parse --short HEAD)
TAG="${TAG:-$(yq '.env.TAG | sub("-.*", "")' < .github/workflows/pull-request.yml)-${COMMIT}}"
OS="${OS:-linux}"
ARCH="${ARCH:-amd64}"
CATTLE_K3S_VERSION=$(yq '.env.CATTLE_K3S_VERSION' < .github/workflows/pull-request.yml)
CATTLE_KDM_BRANCH=$(yq '.env.CATTLE_KDM_BRANCH' < .github/workflows/pull-request.yml)
RKE_VERSION=$(grep -m1 'github.com/rancher/rke' go.mod | awk '{print $2}')
CATTLE_RANCHER_WEBHOOK_VERSION=$(yq '.webhookVersion' < build.yaml)
CATTLE_CSP_ADAPTER_MIN_VERSION=$(yq '.cspAdapterMinVersion' < build.yaml)
CATTLE_FLEET_VERSION=$(yq '.fleetVersion' < build.yaml)

# download airgap images and export it to a tarball
if [ ! -f ./k3s-images.txt ]; then
curl -Lf https://github.com/rancher/k3s/releases/download/${CATTLE_K3S_VERSION}/k3s-images.txt -o ./k3s-images.txt
fi
if [ ! -f ./k3s-airgap-images.tar ]; then
AIRGAP_IMAGES=$(grep -e 'docker.io/rancher/mirrored-pause' -e 'docker.io/rancher/mirrored-coredns-coredns' ./k3s-images.txt)
xargs -n1 docker pull <<< "${AIRGAP_IMAGES}"
xargs -n2 docker save -o ./k3s-airgap-images.tar <<< "${AIRGAP_IMAGES}"
fi

# download kontainer driver metadata
if [ ! -f ./data.json ]; then
curl -sLf https://releases.rancher.com/kontainer-driver-metadata/${CATTLE_KDM_BRANCH}/data.json > ./data.json
fi

# start the builds
docker buildx build \
--build-arg VERSION="${TAG}" \
--build-arg ARCH=${ARCH} \
--build-arg COMMIT="${COMMIT}" \
--build-arg RKE_VERSION=${RKE_VERSION} \
--build-arg CATTLE_RANCHER_WEBHOOK_VERSION=${CATTLE_RANCHER_WEBHOOK_VERSION} \
--build-arg CATTLE_CSP_ADAPTER_MIN_VERSION=${CATTLE_CSP_ADAPTER_MIN_VERSION} \
--build-arg CATTLE_FLEET_VERSION=${CATTLE_FLEET_VERSION} \
--tag rancher/rancher:${TAG} \
--platform="${OS}/${ARCH}" \
--file ./package/Dockerfile .

docker buildx build \
--build-arg VERSION="${TAG}" \
--build-arg ARCH=${ARCH} \
--build-arg RANCHER_TAG=${TAG} \
--build-arg RANCHER_IMAGE=rancher/rancher:${TAG}-${ARCH} \
--build-arg COMMIT="${COMMIT}" \
--build-arg RKE_VERSION=${RKE_VERSION} \
--build-arg CATTLE_RANCHER_WEBHOOK_VERSION=${CATTLE_RANCHER_WEBHOOK_VERSION} \
--tag rancher/rancher-agent:${TAG} \
--platform="${OS}/${ARCH}" \
--file ./package/Dockerfile.agent .
4 changes: 2 additions & 2 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The following are examples of files that often refer to newly added configuratio

- [build-server](../scripts/build-server)
- [build-agent](../scripts/build-agent)
- [build-local.sh](../dev-scripts/build-local.sh)
- [quick](../dev-scripts/quick)
- [Dockerfile](../package/Dockerfile)
- [Dockerfile.agent](../package/Dockerfile.agent)
- [pkg/settings/setting.go](../pkg/settings/setting.go)
Expand All @@ -66,4 +66,4 @@ The following are examples of files that often refer to newly added configuratio

It's better to follow the standard Kubernetes convention of preferring camelCase keys in the YAML file.

The exported resulting environment variables should be like standard ENV_VARS.
The exported resulting environment variables should be like standard ENV_VARS.
23 changes: 7 additions & 16 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,20 @@
## Generate a local container image

If you need to test some changes in a container image before they make it to a
pull request, you can use the handy [build-local.sh](../dev-scripts/build-local.sh)
script.
pull request, you can use the handy `make quick` script.

This script uses `docker buildx` in order to enable cross-building of different
architecture images. To build an image for your current OS and architecture, run
from the Rancher project root:
```shell
TARGET_REPO="localhost:5000/my-test-repo/image:tag" dev-scripts/build-local.sh
TAG="localhost:5000/my-test-repo/image:tag" make quick
```

If you wish to cross-build for a different OS or architecture, set the variables
`TARGET_ARCH` and/or `TARGET_OS`:
If you wish to cross-build for a different architecture, set the variable `ARCH`:
```shell
TARGET_REPO="localhost:5000/my-test-repo/image:tag" \
TARGET_ARCH="amd64" \
TARGET_OS="linux" \
dev-scripts/build-local.sh
```

To specify a `go` binary other than the one present in your `PATH`, use the
`GO_BINARY` environment variable:
```shell
GO_BINARY="/opt/go1.18/bin/go" dev-scripts/build-local.sh
TAG="localhost:5000/my-test-repo/image:tag" \
ARCH="amd64" \
make quick
```

## Deploy your custom image via Helm
Expand All @@ -37,4 +28,4 @@ helm upgrade --install rancher/rancher \
--create-namespace \
--set rancherImage="my-test-repo/image" \
--set rancherImageTag="dev-tag"
```
```
7 changes: 0 additions & 7 deletions scripts/quick

This file was deleted.

0 comments on commit 00177b3

Please sign in to comment.