Skaffold for Fission (#1172)

Skaffold for development of Fission and switching to multi-stage Dockerfile for all components.
This commit is contained in:
Vishal
2019-05-27 12:51:00 +05:30
committed by GitHub
parent c3177f9ebd
commit 49f9944b86
21 changed files with 215 additions and 123 deletions
+15
View File
@@ -0,0 +1,15 @@
*.md
*.sh
Documentation
charts
examples
environments/*
!environments/fetcher
demos
test
Makefile
LICENSE
glide.*
.travis.yml
.gitignore
.git
+1 -1
View File
@@ -37,8 +37,8 @@ before_script:
- hack/verify-govet.sh
- helm lint charts/fission-all/ charts/fission-core/
- go mod download
- go mod vendor
- go build -o fission/fission fission/*.go
- ./fission-bundle/build.sh
- hack/runtests.sh
script:
-9
View File
@@ -1,9 +0,0 @@
FROM alpine:3.5
RUN apk update
# Install some utility libraries for builders extending image
RUN apk add coreutils binutils findutils grep
ADD builder /builder
EXPOSE 8001
+26
View File
@@ -0,0 +1,26 @@
FROM golang:1.11-alpine as fission-builder
RUN apk add bash ca-certificates git gcc g++ libc-dev
ARG GITCOMMIT=unknown
# E.g. GITCOMMIT=$(git rev-parse HEAD)
ARG BUILDVERSION=unknown
# E.g. BUILDVERSION=$(git rev-parse HEAD)
ARG BUILDDATE=unknown
# E.g. BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
ARG GOPKG=github.com/fission/fission
COPY . /go/src/${GOPKG}
WORKDIR /go/src/${GOPKG}/builder/cmd
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-o /go/bin/builder \
-gcflags=-trimpath=$GOPATH \
-asmflags=-trimpath=$GOPATH \
-ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}"
FROM alpine:3.5
COPY --from=fission-builder /go/bin/builder /
EXPOSE 8001
ENTRYPOINT ["/builder"]
-18
View File
@@ -1,18 +0,0 @@
#!/bin/bash
version=$1
if [ -z $version ]; then
version=$(git rev-parse HEAD)
fi
date=$2
if [ -z $date ]; then
date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
fi
gitcommit=$3
if [ -z $gitcommit ]; then
gitcommit=$(git rev-parse HEAD)
fi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-X github.com/fission/fission.GitCommit=$gitcommit -X github.com/fission/fission.BuildDate=$date -X github.com/fission/fission.Version=$version" -o builder .
-5
View File
@@ -1,5 +0,0 @@
FROM alpine:3.4
ADD fetcher /
EXPOSE 8000
@@ -0,0 +1,26 @@
FROM golang:1.11-alpine as builder
RUN apk add bash ca-certificates git gcc g++ libc-dev
ARG GITCOMMIT=unknown
# E.g. GITCOMMIT=$(git rev-parse HEAD)
ARG BUILDVERSION=unknown
# E.g. BUILDVERSION=$(git rev-parse HEAD)
ARG BUILDDATE=unknown
# E.g. BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
ARG GOPKG=github.com/fission/fission
COPY . /go/src/${GOPKG}
WORKDIR /go/src/${GOPKG}/environments/fetcher/cmd
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-o /go/bin/fetcher \
-gcflags=-trimpath=$GOPATH \
-asmflags=-trimpath=$GOPATH \
-ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}"
FROM alpine:3.4
COPY --from=builder /go/bin/fetcher /
EXPOSE 8000
ENTRYPOINT ["/fetcher"]
-17
View File
@@ -1,17 +0,0 @@
#!/bin/sh
version=$1
if [ -z $version ]; then
version=$(git rev-parse HEAD)
fi
date=$2
if [ -z $date ]; then
date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
fi
gitcommit=$3
if [ -z $gitcommit ]; then
gitcommit=$(git rev-parse HEAD)
fi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-X github.com/fission/fission.GitCommit=$gitcommit -X github.com/fission/fission.BuildDate=$date -X github.com/fission/fission.Version=$version" -o fetcher .
+1 -1
View File
@@ -209,7 +209,7 @@ func (deploy *NewDeploy) getDeploymentSpec(fn *crd.Function, env *crd.Environmen
PreStop: &apiv1.Handler{
Exec: &apiv1.ExecAction{
Command: []string{
"sleep",
"/bin/sleep",
fmt.Sprintf("%v", gracePeriodSeconds),
},
},
+1 -1
View File
@@ -387,7 +387,7 @@ func (gp *GenericPool) createPool() error {
PreStop: &apiv1.Handler{
Exec: &apiv1.ExecAction{
Command: []string{
"sleep",
"/bin/sleep",
fmt.Sprintf("%v", gracePeriodSeconds),
},
},
-3
View File
@@ -1,3 +0,0 @@
FROM alpine:3.4
RUN apk add --update ca-certificates
ADD fission-bundle /
+28
View File
@@ -0,0 +1,28 @@
FROM golang:1.11-alpine as builder
RUN apk add bash ca-certificates git gcc g++ libc-dev
ARG GITCOMMIT=unknown
# E.g. GITCOMMIT=$(git rev-parse HEAD)
ARG BUILDVERSION=unknown
# E.g. BUILDVERSION=$(git rev-parse HEAD)
ARG BUILDDATE=unknown
# E.g. BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
ARG GOPKG=github.com/fission/fission
COPY . /go/src/${GOPKG}
RUN rm -f /go/src/${GOPKG}/Dockerfile*
WORKDIR /go/src/${GOPKG}/fission-bundle
ENV GO111MODULE=on
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -mod vendor \
-o /go/bin/fission-bundle \
-gcflags=-trimpath=$GOPATH \
-asmflags=-trimpath=$GOPATH \
-ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}"
FROM alpine:3.4
RUN apk add --update ca-certificates
COPY --from=builder /go/bin/fission-bundle /
ENTRYPOINT ["/fission-bundle"]
-17
View File
@@ -1,17 +0,0 @@
#!/bin/sh
version=$1
if [ -z $version ]; then
version=$(git rev-parse HEAD)
fi
date=$2
if [ -z $date ]; then
date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
fi
gitcommit=$3
if [ -z $gitcommit ]; then
gitcommit=$(git rev-parse HEAD)
fi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-X github.com/fission/fission.GitCommit=$gitcommit -X github.com/fission/fission.BuildDate=$date -X github.com/fission/fission.Version=$version"
+8
View File
@@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"log"
"os"
@@ -150,6 +151,13 @@ func registerTraceExporter(logger *zap.Logger, arguments map[string]interface{})
}
func main() {
// From https://github.com/containous/traefik/pull/1817/files
// Tell glog to log into STDERR. Otherwise, we risk
// certain kinds of API errors getting logged into a directory not
// available in a `FROM scratch` Docker container, causing glog to abort
// hard with an exit code > 0.
flag.Set("logtostderr", "true")
usage := `fission-bundle: Package of all fission microservices: controller, router, executor.
Use it to start one or more of the fission servers:
+6 -14
View File
@@ -52,13 +52,8 @@ build_fission_bundle_image() {
local tag=fission/fission-bundle:$version
pushd $DIR/fission-bundle
./build.sh $version $date $gitcommit
docker build -t $tag .
docker tag $tag fission/fission-bundle:latest
popd
docker build -t $tag -f $ROOT/fission-bundle/Dockerfile.fission-bundle --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version .
docker tag $tag fission/fission-bundle:latest
}
build_fetcher_image() {
@@ -69,8 +64,7 @@ build_fetcher_image() {
pushd $DIR/environments/fetcher/cmd
./build.sh $version $date $gitcommit
docker build -t $tag .
docker build -t $tag -f $ROOT/environments/fetcher/cmd/Dockerfile.fission-fetcher --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version .
docker tag $tag fission/fetcher:latest
popd
@@ -89,8 +83,7 @@ build_builder_image() {
pushd $DIR/builder/cmd
./build.sh $version $date $gitcommit
docker build -t $tag .
docker build -t $tag -f $ROOT/builder/cmd/Dockerfile.fission-builder --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version .
docker tag $tag fission/builder:latest
popd
@@ -134,9 +127,8 @@ build_pre_upgrade_checks_image() {
local tag=fission/pre-upgrade-checks:$version
pushd $DIR/preupgradechecks
./build.sh $version $date $gitcommit
docker build -t $tag .
docker build -t $tag -f $ROOT/preupgradechecks/Dockerfile.fission-preupgradechecks --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version .
docker tag $tag fission/pre-upgrade-checks:latest
popd
+1
View File
@@ -324,6 +324,7 @@ fi
release_environment_check $version $chartsrepo
go mod vendor
# Build release-builder image
docker build -t fission-release-builder -f $GOPATH/src/github.com/fission/fission/hack/Dockerfile .
-3
View File
@@ -1,3 +0,0 @@
FROM alpine:3.4
RUN apk add --update ca-certificates
ADD pre-upgrade-checks /
@@ -0,0 +1,28 @@
FROM golang:1.11-alpine as builder
RUN apk add bash ca-certificates git gcc g++ libc-dev
ARG GITCOMMIT=unknown
# E.g. GITCOMMIT=$(git rev-parse HEAD)
ARG BUILDVERSION=unknown
# E.g. BUILDVERSION=$(git rev-parse HEAD)
ARG BUILDDATE=unknown
# E.g. BUILDDATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
ARG GOPKG=github.com/fission/fission
COPY . /go/src/${GOPKG}
WORKDIR /go/src/${GOPKG}/preupgradechecks
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a \
-o /go/bin/pre-upgrade-checks \
-gcflags=-trimpath=$GOPATH \
-asmflags=-trimpath=$GOPATH \
-ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}"
FROM alpine:3.4
RUN apk add --update ca-certificates
COPY --from=builder /go/bin/pre-upgrade-checks /
ENTRYPOINT ["/pre-upgrade-checks"]
EXPOSE 8001
-18
View File
@@ -1,18 +0,0 @@
#!/bin/sh
version=$1
if [ -z $version ]; then
version=$(git rev-parse HEAD)
fi
date=$2
if [ -z $date ]; then
date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
fi
gitcommit=$3
if [ -z $gitcommit ]; then
gitcommit=$(git rev-parse HEAD)
fi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-X github.com/fission/fission.GitCommit=$gitcommit -X github.com/fission/fission.BuildDate=$date -X github.com/fission/fission.Version=$version" -o pre-upgrade-checks
+58
View File
@@ -0,0 +1,58 @@
####################################
# This file can be used with Skaffold (https://github.com/GoogleContainerTools/skaffold) to
# build and deploy Fission to Kubernetes cluster.
#
############## Usage ##############
# Skaffold CLI should be installed on your machine.
# Change <DOCKERHUB_REPO> -> to your Dockerhub username
# Run `go mod vendor` so that all dependencies are downloaded
# Run `skaffold run` to build and deploy with helm.
# Run`skaffold build` to only build and push images
############## Current Limitations ##############
# 1) You can not refer to dynamically generated tag from build section in Helm values
# - hence you have to use "latest" tag
############### Possible enhancements ##############
# 1) Add profiles to suit various deployment needs
####################################
apiVersion: skaffold/v1beta9
kind: Config
build:
artifacts:
- image: <DOCKERHUB_REPO>/fission
context: .
docker:
dockerfile: fission-bundle/Dockerfile.fission-bundle
- image: <DOCKERHUB_REPO>/fetcher
docker:
dockerfile: environments/fetcher/cmd/Dockerfile.fission-fetcher
- image: <DOCKERHUB_REPO>/preupgradechecks
docker:
dockerfile: preupgradechecks/Dockerfile.fission-preupgradechecks
tagPolicy:
envTemplate:
template: "{{.IMAGE_NAME}}:skaffold-test"
deploy:
helm:
releases:
- name: fission
chartPath: ./charts/fission-all
valuesFiles:
- ./charts/fission-all/values.yaml
namespace: "fission"
setValues:
image: <DOCKERHUB_REPO>/fission
imageTag: skaffold-test
fetcherImage: <DOCKERHUB_REPO>/fetcher
fetcherImageTag: skaffold-test
namespace: fission
preUpgradeChecksImage: <DOCKERHUB_REPO>/preupgradechecks
repository: index.docker.io
setValueTemplates: {}
wait: true
recreatePods: false
overrides: {}
packaged: null
imageStrategy:
fqn: null
helm: null
+16 -16
View File
@@ -44,18 +44,27 @@ gcloud_login() {
gcloud auth activate-service-account --key-file $KEY
}
getVersion() {
echo $(git rev-parse HEAD)
}
getDate() {
echo $(date -u +'%Y-%m-%dT%H:%M:%SZ')
}
getGitCommit() {
echo $(git rev-parse HEAD)
}
build_and_push_pre_upgrade_check_image() {
image_tag=$1
travis_fold_start build_and_push_pre_upgrade_check_image $image_tag
pushd $ROOT/preupgradechecks
./build.sh
docker build -q -t $image_tag .
docker build -t $image_tag -f $ROOT/preupgradechecks/Dockerfile.fission-preupgradechecks --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) .
gcloud_login
gcloud docker -- push $image_tag
popd
travis_fold_end build_and_push_pre_upgrade_check_image
}
@@ -63,14 +72,11 @@ build_and_push_fission_bundle() {
image_tag=$1
travis_fold_start build_and_push_fission_bundle $image_tag
pushd $ROOT/fission-bundle
./build.sh
docker build -q -t $image_tag .
docker build -q -t $image_tag -f $ROOT/fission-bundle/Dockerfile.fission-bundle --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) .
gcloud_login
gcloud docker -- push $image_tag
popd
travis_fold_end build_and_push_fission_bundle
}
@@ -78,14 +84,11 @@ build_and_push_fetcher() {
image_tag=$1
travis_fold_start build_and_push_fetcher $image_tag
pushd $ROOT/environments/fetcher/cmd
./build.sh
docker build -q -t $image_tag .
docker build -q -t $image_tag -f $ROOT/environments/fetcher/cmd/Dockerfile.fission-fetcher --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) .
gcloud_login
gcloud docker -- push $image_tag
popd
travis_fold_end build_and_push_fetcher
}
@@ -94,14 +97,11 @@ build_and_push_builder() {
image_tag=$1
travis_fold_start build_and_push_builder $image_tag
pushd $ROOT/builder/cmd
./build.sh
docker build -q -t $image_tag .
docker build -q -t $image_tag -f $ROOT/builder/cmd/Dockerfile.fission-builder --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) .
gcloud_login
gcloud docker -- push $image_tag
popd
travis_fold_end build_and_push_builder
}