summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 5cab0a60ab3a43226862fe0a2059e577bc38d0c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Maintainer: Stefan Cocora <stefan dot cocora at gmail dot com>
# Contributor:

_pkgauthor=kubeless
_upstream_pkgname=kubeless
pkgname=kubeless
pkgver=1.0.4
pkgrel=1
pkgdesc="A Kubernetes-native serverless framework that lets you deploy small bits of code without having to worry about the underlying infrastructure plumbing."
arch=('x86_64')
groups=()
depends=(
  "filesystem"
  "glibc"
  "iana-etc"
  "linux-api-headers"
  "tzdata"
)
makedepends=(
  "go"
  "git"
  "wget"
)
_builddepends_bins_path="$HOME/tmp/build/bin"
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=
license=("Apache")
_manifest_non_rbac="${_upstream_pkgname}-non-rbac.yaml"
_manifest_openshift="${_upstream_pkgname}-openshift.yaml"
_manifest_rbac="${_upstream_pkgname}.yaml"
url="https://github.com/${_pkgauthor}/${_upstream_pkgname}"
# https://github.com/kubeless/kubeless/archive/v1.0.0.tar.gz
source=("${pkgname}::git+https://github.com/${_pkgauthor}/${_upstream_pkgname}.git"
  "LICENSE::https://raw.githubusercontent.com/${_pkgauthor}/${_upstream_pkgname}/master/LICENSE")
sha256sums=('SKIP'
            'fdcee9e38cea79678ee1fa2cb86ce9889eea24899b526911dc982bf4519113b2')


prepare() {

  local OP="prepare"

  if [ "$PKGBUILD_DEBUG" = "true" ];
  then
	  cd "${srcdir}/${_upstream_pkgname}"

	  echo "pkgver: $(git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')"

    echo "running function: $OP"
    echo "user: $(whoami)"
    echo "CWD: $CWD"
    echo "PWD: $PWD"
    echo "CI: $CI"
    echo "PKGBUILD_DEBUG: $PKGBUILD_DEBUG"
    echo "BUILDDIR: $BUILDDIR"
    echo "PKGDEST: $PKGDEST"
    echo "SRCDEST: $SRCDEST"
    echo "SRCPKGDEST: $SRCPKGDEST"
    echo "LOGDEST: $LOGDEST"
    echo "PACKAGER: $PACKAGER"
  fi

  # https://github.com/kubeless/kubeless/blob/master/Makefile#L104-L113
  # have to copy/paste this section because the upstream maintainers are using sudo during this section of the Makefile
  mkdir -p "${pkgdir}/usr/local/bin"
  mkdir -p ${_builddepends_bins_path}
  echo "=== fetching kubecfg"
  wget -q -O "${_builddepends_bins_path}/kubecfg" https://github.com/ksonnet/kubecfg/releases/download/v0.9.0/kubecfg-$(go env GOOS)-$(go env GOARCH); \
    chmod +x "${_builddepends_bins_path}/kubecfg";
  echo "=== fetching kubectl"
  KUBECTL_VERSION=$(wget -qO- https://storage.googleapis.com/kubernetes-release/release/stable.txt); \
    wget -q -O "${_builddepends_bins_path}/kubectl" https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/$(go env GOOS)/$(go env GOARCH)/kubectl; \
    chmod +x "${_builddepends_bins_path}/kubectl";

  mkdir -p "${srcdir}/gopath/{bin,src,pkg}"
  mkdir -p "${srcdir}/gopath/src/github.com/${_pkgauthor}"
  cp -r "${srcdir}/${pkgname}" "${srcdir}/gopath/src/github.com/${_pkgauthor}/${pkgname}"
  # build from release tag rather than from the master HEAD
  cd "${srcdir}/gopath/src/github.com/${_pkgauthor}/${pkgname}" && git checkout "v${pkgver}"
}

build() {
  local OP="build"

  if [ "$PKGBUILD_DEBUG" = "true" ];
  then
    echo "running function: $OP"
    echo "user: $(whoami)"
    echo "CWD: $CWD"
    echo "PWD: $PWD"
    echo "CI: $CI"
    echo "PKGBUILD_DEBUG: $PKGBUILD_DEBUG"
    echo "BUILDDIR: $BUILDDIR"
    echo "PKGDEST: $PKGDEST"
    echo "SRCDEST: $SRCDEST"
    echo "SRCPKGDEST: $SRCPKGDEST"
    echo "LOGDEST: $LOGDEST"
    echo "PACKAGER: $PACKAGER"
  fi

  export GOPATH="${srcdir}/gopath"
  export PATH="${_builddepends_bins_path}:${PATH}"
  export CGO_ENABLED=0
  cd "${srcdir}/gopath/src/github.com/${_pkgauthor}/${pkgname}"
  # https://github.com/kubeless/kubeless/blob/master/.circleci/config.yml#L77-L105
  go get -u golang.org/x/lint/golint
  make bootstrap
  # make VERSION=${CONTROLLER_TAG} binary
  make VERSION="${pkgver}" binary
  make test
  make validation
  make all-yaml
  mkdir build-manifests
  MANIFESTS="kubeless kubeless-non-rbac kubeless-openshift"; \
  IFS=' ' read -r -a manifests <<< "$MANIFESTS"; \
  for f in "${manifests[@]}"; do \
    sed -i.bak 's/:latest/'":${CONTROLLER_TAG}"'/g' ${f}.yaml; \
    cp ${f}.yaml build-manifests/; \
  done
}


package() {
  local OP="package"

  if [ "$PKGBUILD_DEBUG" = "true" ];
  then
    echo "running function: $OP"
    echo "user: $(whoami)"
    echo "CWD: $CWD"
    echo "PWD: $PWD"
    echo "CI: $CI"
    echo "PKGBUILD_DEBUG: $PKGBUILD_DEBUG"
    echo "BUILDDIR: $BUILDDIR"
    echo "PKGDEST: $PKGDEST"
    echo "SRCDEST: $SRCDEST"
    echo "SRCPKGDEST: $SRCPKGDEST"
    echo "LOGDEST: $LOGDEST"
    echo "PACKAGER: $PACKAGER"
  fi
  install -Dm755 "${srcdir}/gopath/bin/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"

  mkdir -p "${pkgdir}/usr/share/licenses/${_upstream_pkgname}"
  cp "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/${_upstream_pkgname}"

  mkdir -p "${pkgdir}/usr/share/${_upstream_pkgname}/manifests"
  cp "${srcdir}/gopath/src/github.com/${pkgname}/${_pkgauthor}/build-manifests/${_manifest_non_rbac}" "${pkgdir}/usr/share/${_upstream_pkgname}/manifests/"
  cp "${srcdir}/gopath/src/github.com/${pkgname}/${_pkgauthor}/build-manifests/${_manifest_openshift}" "${pkgdir}/usr/share/${_upstream_pkgname}/manifests/"
  cp "${srcdir}/gopath/src/github.com/${pkgname}/${_pkgauthor}/build-manifests/${_manifest_rbac}" "${pkgdir}/usr/share/${_upstream_pkgname}/manifests/"
  chmod 644 "${pkgdir}/usr/share/${_upstream_pkgname}/manifests/"*.yaml
}