Skip to content

Commit

Permalink
Add a install-dependencies.sh script
Browse files Browse the repository at this point in the history
This is similar to what is in seastar and scylla. I am pretty sure it
is incomplete, but it is easy to add more distros and dependencies.

This avoids all binary packages and I have been able to build the
operator on my raspberrypi :-)

I have selected the version in order to cause the smallest possible
change to go.mod in the following patch.

Signed-off-by: Rafael Ávila de Espíndola <espindola@scylladb.com>
  • Loading branch information
espindola authored and zimnx committed Nov 3, 2020
1 parent 652194d commit 3396c8e
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 120 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yaml
Expand Up @@ -29,13 +29,13 @@ jobs:
id: cache-tools
uses: actions/cache@v1
with:
path: ${{ format('{0}/bin/deps', env.working-directory-rel) }}
key: ${{ runner.os }}-${{ hashFiles(format('{0}/hack/binary_deps.py', env.working-directory-rel)) }}
path: ${{ format('{0}/bin', env.GOPATH) }}
key: ${{ runner.os }}-${{ hashFiles(format('{0}/install-dependencies.sh', env.working-directory-rel)) }}

- name: Install binary deps
- name: Install deps
if: steps['cache-tools'].outputs['cache-hit'] != 'true'
working-directory: ${{ env.working-directory }}
run: make bin/deps
run: ./install-dependencies.sh

- name: Go Dependencies
working-directory: ${{ env.working-directory }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -5,7 +5,6 @@
*.dll
*.so
*.dylib
bin/deps
bin/scylla-operator
dist/

Expand Down
36 changes: 13 additions & 23 deletions Makefile
Expand Up @@ -9,11 +9,10 @@ CRD_OPTIONS ?= "crd:trivialVersions=true"

.EXPORT_ALL_VARIABLES:
DOCKER_BUILDKIT := 1
KUBEBUILDER_ASSETS := $(CURDIR)/bin/deps
PATH := $(CURDIR)/bin/deps:$(PATH):
PATH := $(CURDIR)/bin/deps/go/bin:$(PATH):
GOROOT := $(CURDIR)/bin/deps/go
GOVERSION := $(shell go version)
GOPATH := $(shell go env GOPATH)
KUBEBUILDER_ASSETS := $(GOPATH)/bin
PATH := $(GOPATH)/bin:$(PATH):

# Default package
PKG := ./pkg/...
Expand Down Expand Up @@ -50,8 +49,8 @@ deploy: manifests cert-manager
kustomize build config/operator/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: bin/deps controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="$(PKG)" output:crd:artifacts:config=config/operator/crd/bases output:rbac:artifacts:config=config/operator/rbac/bases
manifests:
controller-gen $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="$(PKG)" output:crd:artifacts:config=config/operator/crd/bases output:rbac:artifacts:config=config/operator/rbac/bases
kustomize build config/operator/default > examples/generic/operator.yaml
kustomize build config/operator/default > examples/gke/operator.yaml
kustomize build config/operator/default > examples/eks/operator.yaml
Expand All @@ -60,20 +59,20 @@ manifests: bin/deps controller-gen
kustomize build config/manager/default > examples/eks/manager.yaml

# Run go fmt against code
fmt: bin/deps
fmt:
go fmt $(PKG)

# Run go vet against code
vet: bin/deps
vet:
go vet $(PKG)

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="$(PKG)"
generate:
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="$(PKG)"

# Build the docker image
.PHONY: docker-build
docker-build: bin/deps
docker-build:
goreleaser --skip-validate --skip-publish --rm-dist

# Push the docker image
Expand All @@ -82,22 +81,13 @@ docker-push:

# Ensure dependencies
.PHONY: vendor
vendor: bin/deps
vendor:
go mod vendor

# Build local-build binary
.PHONY: local-build
local-build: fmt vet vendor
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -a -o bin/scylla-operator github.com/scylladb/scylla-operator/pkg/cmd
CGO_ENABLED=0 go build -trimpath -a -o bin/scylla-operator github.com/scylladb/scylla-operator/pkg/cmd

# find or download controller-gen
# download controller-gen if necessary
controller-gen: bin/deps
CONTROLLER_GEN=bin/deps/controller-gen

release: bin/deps
release:
goreleaser --rm-dist

bin/deps: hack/binary_deps.py
mkdir -p bin/deps
hack/binary_deps.py bin/deps
4 changes: 0 additions & 4 deletions bin/go.mod

This file was deleted.

7 changes: 2 additions & 5 deletions docs/source/contributing.md
Expand Up @@ -13,13 +13,10 @@ To develop on scylla-operator, your environment must have the following:
7. Git client installed
8. Github account

To install all binary dependencies (Go, kustomize, kubebuilder, dep), simply run:
To install all dependencies (Go, kustomize, kubebuilder, dep), simply run:
```bash
make bin/deps
./install-dependencies.sh
```
This will install all binary dependencies under `bin/deps`.
If you have some of the above already installed, it is completely safe to run the command, since it only
affects the `bin/deps` folder.

## Initial Setup

Expand Down
83 changes: 0 additions & 83 deletions hack/binary_deps.py

This file was deleted.

83 changes: 83 additions & 0 deletions install-dependencies.sh
@@ -0,0 +1,83 @@
#!/bin/bash
#
# This file is open source software, licensed to you under the terms
# of the Apache License, Version 2.0 (the "License"). See the NOTICE file
# distributed with this work for additional information regarding copyright
# ownership. You may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set -euo pipefail

. /etc/os-release

debian_packages=(
ca-certificates
etcd
git
make
)

fedora_packages=(
etcd
git-core
golang-bin
make

# Unfortunately podman doesn't work very well with kubernetes. See
# https://fedoramagazine.org/docker-and-fedora-32/ for how to get
# docker to work on a current fedora.
moby-engine
)

if [ "$ID" = "fedora" ]
then
sudo dnf install -y "${fedora_packages[@]}"
fi

if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]
then
# If someone has a non-system installation of go, just use that.
if ! which go
then
sudo apt-get install golang
fi

# Similarly for docker
if ! which docker
then
sudo apt-get install -y docker.io
fi

sudo apt-get install -y "${debian_packages[@]}"
fi

go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 sigs.k8s.io/kustomize/kustomize/v3@v3.5.1 github.com/goreleaser/goreleaser@v0.138.0

mkdir -p tmp
cd tmp

# Kubernetes commands don't work with "go get"
# https://github.com/kubernetes/kubernetes/issues/79384
git clone https://github.com/kubernetes/kubernetes.git
cd kubernetes
# v1.19.x requires go 1.15.0
git checkout v1.18.9
make WHAT=cmd/kube-apiserver
cp _output/bin/kube-apiserver $(go env GOPATH)/bin
cd ..

cd ..
rm -rf tmp

# KUBEBUILDER_ASSETS has to be a single directory
cp /usr/bin/etcd $(go env GOPATH)/bin

0 comments on commit 3396c8e

Please sign in to comment.