Skip to content

Commit

Permalink
regress go
Browse files Browse the repository at this point in the history
add reg args
  • Loading branch information
matzhaugen committed Feb 19, 2021
1 parent 9b3b1f3 commit 7d05791
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 49 deletions.
50 changes: 14 additions & 36 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ name: build
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]


jobs:
build:
strategy:
matrix:
go-version: [1.13.x]
os: [ubuntu-latest]
operator: [0, 1]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
Expand All @@ -21,19 +20,16 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- uses: docker/setup-buildx-action@v1
id: buildx
- name: Kubernetes KinD Cluster
uses: container-tools/kind-action@v1
- name: Build x86_64 container into library
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
outputs: "type=docker,push=false"
platforms: linux/amd64
tags: |
ghcr.io/openfaas/faas-netes:${{ github.sha }}
run: |
docker build --platform=linux/amd64 --tag=kind-registry:5000/openfaas/faas-netes:${{ github.sha }} .
- name: Push image
run: |
docker push kind-registry:5000/openfaas/faas-netes:${{ github.sha }}
- name: Build multi-arch containers for validation only
uses: docker/build-push-action@v2
with:
Expand All @@ -42,32 +38,14 @@ jobs:
outputs: "type=image,push=false"
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: |
ghcr.io/openfaas/faas-netes:${{ github.sha }}
# Todo - load the image into Kind before running tests
# otherwise, this just tests the chart with images that
# have already been built and pushed in an earlier job
localhost:5000/openfaas/faas-netes:${{ github.sha }}
- name: get tools
run: ./contrib/get_tools.sh
- name: lint chart
run: ./contrib/lint_chart.sh
- name: create cluster
run: ./contrib/create_cluster.sh
- name: deploy function
run: OPERATOR=0 ./contrib/deploy.sh
run: OPERATOR=${{ matrix.operator }} FAASNETES_IMAGE=kind-registry:5000/openfaas/faas-netes:${{ github.sha }} ./contrib/deploy.sh
- name: run function
run: OPERATOR=0 ./contrib/run_function.sh
- name: stop dev cluster
run: ./contrib/stop_dev.sh
- name: wait 10 seconds
run: sleep 10
- name: create cluster
run: ./contrib/create_cluster.sh
- name: deploy function
run: OPERATOR=1 ./contrib/deploy.sh
- name: run function
run: OPERATOR=1 ./contrib/run_function.sh
- name: stop dev cluster
run: ./contrib/stop_dev.sh

run: OPERATOR=${{ matrix.operator }} ./contrib/run_function.sh
# The certifier should also be run here
#
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: build local push namespaces install charts start-kind stop-kind build-buildx render-charts
TAG?=latest
OWNER?=openfaas
REGISTRY?=ghcr.io
export DOCKER_CLI_EXPERIMENTAL=enabled

all: build-docker
Expand All @@ -9,15 +11,15 @@ local:

build-docker:
docker build \
-t ghcr.io/openfaas/faas-netes:$(TAG) .
-t $(REGISTRY)/$(OWNER)/faas-netes:$(TAG) .

.PHONY: build-buildx
build-buildx:
@docker buildx create --use --name=multiarch --node=multiarch && \
docker buildx build \
--output "type=docker,push=false" \
--platform linux/amd64 \
--tag ghcr.io/openfaas/faas-netes:$(TAG) \
--tag $(REGISTRY)/$(OWNER)/faas-netes:$(TAG) \
.

.PHONY: build-buildx-all
Expand All @@ -26,11 +28,21 @@ build-buildx-all:
docker buildx build \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--output "type=image,push=false" \
--tag ghcr.io/openfaas/faas-netes:$(TAG) \
--tag $(REGISTRY)/$(OWNER)/faas-netes:$(TAG) \
.

.PHONY: publish-buildx-all
publish-buildx-all:
@echo $(REGISTRY)/$(OWNER)/faas-netes:$(TAG) && \
docker buildx create --use --name=multiarch --node=multiarch && \
docker buildx build \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--push=true \
--tag $(REGISTRY)/$(OWNER)/faas-netes:$(TAG) \
.

push:
docker push ghcr.io/openfaas/faas-netes:$(TAG)
docker push $(REGISTRY)/$(OWNER)/faas-netes:$(TAG)

namespaces:
kubectl apply -f namespaces.yml
Expand Down
33 changes: 31 additions & 2 deletions contrib/create_cluster.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
#!/usr/bin/env bash

set -o errexit
DEVENV=${OF_DEV_ENV:-kind}
KUBE_VERSION=v1.18.8
REG_NAME=kind-registry
REG_PORT=5000

./contrib/create_local_registry.sh ${REG_NAME} ${REG_PORT}
echo ">>> Creating Kubernetes ${KUBE_VERSION} cluster ${DEVENV}"

kind create cluster --wait 5m --image kindest/node:${KUBE_VERSION} --name "$DEVENV" -v 1
# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster \
--wait 5m --image kindest/node:${KUBE_VERSION} --name "$DEVENV" -v 1 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${REG_PORT}"]
endpoint = ["http://${REG_NAME}:${REG_PORT}"]
EOF


# connect the registry to the cluster network
# (the network may already be connected)
containers=$(docker network inspect kind -f "{{range .Containers}}{{.Name}} {{end}}")
needs_connect="true"
for c in $containers; do
if [ "$c" = "${reg_name}" ]; then
needs_connect="false"
fi
done
if [ "${needs_connect}" = "true" ]; then
docker network connect "kind" "${REG_NAME}" || true
else
echo ">>> Kind network already connected to local registry"
fi


echo ">>> Waiting for CoreDNS"
kubectl --context "kind-$DEVENV" -n kube-system rollout status deployment/coredns
9 changes: 9 additions & 0 deletions contrib/create_local_registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# create registry container unless it already exists
REG_NAME=${$1:-'kind-registry'}
REG_PORT=${$2:-'5000'}
running="$(docker inspect -f '{{.State.Running}}' "${REG_NAME}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${REG_PORT}:5000" --name "${REG_NAME}" \
registry:2
fi
14 changes: 9 additions & 5 deletions contrib/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e

DEVENV=${OF_DEV_ENV:-kind}
OPERATOR=${OPERATOR:-0}
FAASNETES_IMAGE=${FAASNETES_IMAGE:-ghcr.io/openfaas/faas-netes:0.12.18}

echo "Applying namespaces"
kubectl --context "kind-$DEVENV" apply -f ./namespaces.yml
Expand All @@ -17,12 +18,14 @@ if [ -x "$(command -v $sha_cmd)" ]; then
sha_cmd="shasum"
fi

PASSWORD=$(head -c 16 /dev/urandom| $sha_cmd | cut -d " " -f 1)
echo -n $PASSWORD > password.txt


kubectl get secret basic-auth -n openfaas --context "kind-$DEVENV" > /dev/null || \
(PASSWORD=$(head -c 16 /dev/urandom| $sha_cmd | cut -d " " -f 1) && \
echo -n $PASSWORD > password.txt && \
kubectl --context "kind-$DEVENV" -n openfaas create secret generic basic-auth \
--from-literal=basic-auth-user=admin \
--from-literal=basic-auth-password="$PASSWORD"
--from-literal=basic-auth-password="$PASSWORD")

CREATE_OPERATOR=false
if [ "${OPERATOR}" == "1" ]; then
Expand All @@ -38,6 +41,7 @@ helm upgrade \
./chart/openfaas \
--namespace openfaas \
--set basic_auth=true \
--set faasnetes.image=$FAASNETES_IMAGE \
--set functionNamespace=openfaas-fn \
--set operator.create=$CREATE_OPERATOR

Expand All @@ -47,5 +51,5 @@ if [ "${OPERATOR}" == "1" ]; then
-p='[{"op": "add", "path": "/spec/template/spec/containers/1/command", "value": ["./faas-netes", "-operator=true"]} ]' --type=json
fi

kubectl --context "kind-$DEVENV" rollout status deploy/prometheus -n openfaas
kubectl --context "kind-$DEVENV" rollout status deploy/gateway -n openfaas
kubectl --context "kind-$DEVENV" rollout status deploy/prometheus -n openfaas --timeout=2m
kubectl --context "kind-$DEVENV" rollout status deploy/gateway -n openfaas --timeout=4m
2 changes: 1 addition & 1 deletion contrib/get_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

KIND_VERSION="v0.9.0"
KIND_VERSION="v0.10.0"
# Causes a validation failure when linting due to CRDs moving to v1
# HELM_VERSION="v3.4.0"
HELM_VERSION="v3.0.3"
Expand Down
3 changes: 2 additions & 1 deletion contrib/run_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ then
fi

if [ -f "of_${DEVENV}_portforward.pid" ]; then
kill $(<of_${DEVENV}_portforward.pid)
# If the kill fails, there is no process running and the file should be removed
kill $(<of_${DEVENV}_portforward.pid) || rm of_${DEVENV}_portforward.pid
fi

# quietly start portforward and put it in the background, it will not
Expand Down

0 comments on commit 7d05791

Please sign in to comment.