Skip to content

Commit

Permalink
feat: Unified gateway deployment image. Closes #639 (#648)
Browse files Browse the repository at this point in the history
* feat: Unified gateway deployment image. Closes #639

* make deployment logic change

* update manifests

* Dockerfile change
  • Loading branch information
whynowy committed May 12, 2020
1 parent 978c40c commit 6bc5dcf
Show file tree
Hide file tree
Showing 59 changed files with 167 additions and 1,224 deletions.
266 changes: 12 additions & 254 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ endif

# Build the project images
.DELETE_ON_ERROR:
all: sensor-linux sensor-controller-linux gateway-controller-linux gateway-client-linux webhook-linux calendar-linux resource-linux minio-linux file-linux nats-linux kafka-linux amqp-linux mqtt-linux storage-grid-linux github-linux hdfs-linux gitlab-linux sns-linux sqs-linux pubsub-linux slack-linux nsq-linux redis-linux emitter-linux stripe-linux azure-events-hub-linux
all: sensor-linux sensor-controller-linux gateway-controller-linux gateway-client-linux gateway-server-linux

all-images: sensor-image sensor-controller-image gateway-controller-image gateway-client-image webhook-image calendar-image resource-image minio-image file-image nats-image kafka-image amqp-image mqtt-image storage-grid-image github-image gitlab-image sns-image pubsub-image hdfs-image sqs-image slack-image nsq-image redis-image emitter-image stripe-image azure-events-hub-image
all-images: sensor-image sensor-controller-image gateway-controller-image gateway-client-image gateway-server-image

all-controller-images: sensor-controller-image gateway-controller-image

Expand Down Expand Up @@ -94,259 +94,17 @@ gateway-client-image:
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)gateway-client:$(IMAGE_TAG) ; fi


# gateway binaries
webhook:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/webhook-gateway ./gateways/server/webhook/cmd/
# gateway binary
gateway-server:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/gateway-server ./gateways/server/cmd/

webhook-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make webhook
gateway-server-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make gateway-server

webhook-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make webhook-linux; fi
docker build -t $(IMAGE_PREFIX)webhook-gateway:$(IMAGE_TAG) -f ./gateways/server/webhook/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)webhook-gateway:$(IMAGE_TAG) ; fi


calendar:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/calendar-gateway ./gateways/server/calendar/cmd/

calendar-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make calendar

calendar-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make calendar-linux; fi
docker build -t $(IMAGE_PREFIX)calendar-gateway:$(IMAGE_TAG) -f ./gateways/server/calendar/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)calendar-gateway:$(IMAGE_TAG) ; fi


resource:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/resource-gateway ./gateways/server/resource/cmd

resource-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make resource

resource-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make resource-linux; fi
docker build -t $(IMAGE_PREFIX)resource-gateway:$(IMAGE_TAG) -f ./gateways/server/resource/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)resource-gateway:$(IMAGE_TAG) ; fi


minio:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/minio-gateway ./gateways/server/minio/cmd

minio-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make minio

minio-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make minio-linux; fi
docker build -t $(IMAGE_PREFIX)artifact-gateway:$(IMAGE_TAG) -f ./gateways/server/minio/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)artifact-gateway:$(IMAGE_TAG) ; fi


file:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/file-gateway ./gateways/server/file/cmd

file-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make file

file-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make file-linux; fi
docker build -t $(IMAGE_PREFIX)file-gateway:$(IMAGE_TAG) -f ./gateways/server/file/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)file-gateway:$(IMAGE_TAG) ; fi


#Stream gateways
nats:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/nats-gateway ./gateways/server/nats/cmd

nats-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make nats

nats-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make nats-linux; fi
docker build -t $(IMAGE_PREFIX)nats-gateway:$(IMAGE_TAG) -f ./gateways/server/nats/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)nats-gateway:$(IMAGE_TAG) ; fi


kafka:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/kafka-gateway ./gateways/server/kafka/cmd

kafka-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make kafka

kafka-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make kafka-linux; fi
docker build -t $(IMAGE_PREFIX)kafka-gateway:$(IMAGE_TAG) -f ./gateways/server/kafka/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)kafka-gateway:$(IMAGE_TAG) ; fi


amqp:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/amqp-gateway ./gateways/server/amqp/cmd

amqp-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make amqp

amqp-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make amqp-linux; fi
docker build -t $(IMAGE_PREFIX)amqp-gateway:$(IMAGE_TAG) -f ./gateways/server/amqp/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)amqp-gateway:$(IMAGE_TAG) ; fi


mqtt:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/mqtt-gateway ./gateways/server/mqtt/cmd

mqtt-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make mqtt

mqtt-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make mqtt-linux; fi
docker build -t $(IMAGE_PREFIX)mqtt-gateway:$(IMAGE_TAG) -f ./gateways/server/mqtt/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)mqtt-gateway:$(IMAGE_TAG) ; fi


# Custom gateways
storage-grid:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/storagegrid-gateway ./gateways/server/storagegrid/cmd

storage-grid-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make storage-grid

storage-grid-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make storage-grid-linux; fi
docker build -t $(IMAGE_PREFIX)storage-grid-gateway:$(IMAGE_TAG) -f ./gateways/server/storagegrid/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)storage-grid-gateway:$(IMAGE_TAG) ; fi

gitlab:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/gitlab-gateway ./gateways/server/gitlab/cmd

gitlab-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make gitlab

gitlab-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make gitlab-linux; fi
docker build -t $(IMAGE_PREFIX)gitlab-gateway:$(IMAGE_TAG) -f ./gateways/server/gitlab/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)gitlab-gateway:$(IMAGE_TAG) ; fi

github:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/github-gateway ./gateways/server/github/cmd

github-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make github

github-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make github-linux; fi
docker build -t $(IMAGE_PREFIX)github-gateway:$(IMAGE_TAG) -f ./gateways/server/github/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)github-gateway:$(IMAGE_TAG) ; fi

sns:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/aws-sns-gateway ./gateways/server/aws-sns/cmd

sns-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make sns

sns-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make sns-linux; fi
docker build -t $(IMAGE_PREFIX)aws-sns-gateway:$(IMAGE_TAG) -f ./gateways/server/aws-sns/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)aws-sns-gateway:$(IMAGE_TAG) ; fi

pubsub:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/gcp-pubsub-gateway ./gateways/server/gcp-pubsub/cmd

pubsub-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make pubsub

pubsub-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make pubsub-linux; fi
docker build -t $(IMAGE_PREFIX)gcp-pubsub-gateway:$(IMAGE_TAG) -f ./gateways/server/gcp-pubsub/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)gcp-pubsub-gateway:$(IMAGE_TAG) ; fi

hdfs:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/hdfs-gateway ./gateways/server/hdfs/cmd

hdfs-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make hdfs

hdfs-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make hdfs-linux; fi
docker build -t $(IMAGE_PREFIX)hdfs-gateway:$(IMAGE_TAG) -f ./gateways/server/hdfs/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)hdfs-gateway:$(IMAGE_TAG) ; fi

sqs:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/aws-sqs-gateway ./gateways/server/aws-sqs/cmd

sqs-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make sqs

sqs-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make sqs-linux; fi
docker build -t $(IMAGE_PREFIX)aws-sqs-gateway:$(IMAGE_TAG) -f ./gateways/server/aws-sqs/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)aws-sqs-gateway:$(IMAGE_TAG) ; fi

slack:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/slack-gateway ./gateways/server/slack/cmd

slack-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make slack

slack-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make slack-linux; fi
docker build -t $(IMAGE_PREFIX)slack-gateway:$(IMAGE_TAG) -f ./gateways/server/slack/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)slack-gateway:$(IMAGE_TAG) ; fi

nsq:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/nsq-gateway ./gateways/server/nsq/cmd

nsq-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make nsq

nsq-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make nsq-linux; fi
docker build -t $(IMAGE_PREFIX)nsq-gateway:$(IMAGE_TAG) -f ./gateways/server/nsq/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)nsq-gateway:$(IMAGE_TAG) ; fi

redis:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/redis-gateway ./gateways/server/redis/cmd

redis-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make redis

redis-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make redis-linux; fi
docker build -t $(IMAGE_PREFIX)redis-gateway:$(IMAGE_TAG) -f ./gateways/server/redis/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)redis-gateway:$(IMAGE_TAG) ; fi

emitter:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/emitter-gateway ./gateways/server/emitter/cmd

emitter-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make emitter

emitter-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make emitter-linux; fi
docker build -t $(IMAGE_PREFIX)emitter-gateway:$(IMAGE_TAG) -f ./gateways/server/emitter/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)emitter-gateway:$(IMAGE_TAG) ; fi

stripe:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/stripe-gateway ./gateways/server/stripe/cmd

stripe-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make stripe

stripe-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make stripe-linux; fi
docker build -t $(IMAGE_PREFIX)stripe-gateway:$(IMAGE_TAG) -f ./gateways/server/stripe/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)stripe-gateway:$(IMAGE_TAG) ; fi

azure-events-hub:
go build -v -ldflags '${LDFLAGS}' -o ${DIST_DIR}/azure-events-hub-gateway ./gateways/server/azure-events-hub/cmd

azure-events-hub-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 make azure-events-hub

azure-events-hub-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make azure-events-hub-linux; fi
docker build -t $(IMAGE_PREFIX)azure-events-hub-gateway:$(IMAGE_TAG) -f ./gateways/server/azure-events-hub/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)azure-events-hub-gateway:$(IMAGE_TAG) ; fi
gateway-server-image:
@if [ "$(BUILD_BINARY)" = "true" ]; then make gateway-server-linux; fi
docker build -t $(IMAGE_PREFIX)gateway-server:$(IMAGE_TAG) -f ./gateways/server/Dockerfile .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)gateway-server:$(IMAGE_TAG) ; fi

test:
go test $(shell go list ./... | grep -v /vendor/ | grep -v /test/e2e/) -race -short -v
Expand Down Expand Up @@ -379,7 +137,7 @@ kind-e2e:
./hack/e2e/kind-run-e2e.sh

.PHONY: build-e2e-images
build-e2e-images: sensor-controller-image gateway-controller-image gateway-client-image webhook-image
build-e2e-images: sensor-controller-image gateway-controller-image gateway-client-image gateway-server-image

.PHONY: lint
lint:
Expand Down
10 changes: 4 additions & 6 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ const (
EnvVarResourceName = "NAME"
// EnvVarNamespace refers to a K8s namespace
EnvVarNamespace = "NAMESPACE"
// EnvVarClientImage refers to the env var for gateway client image
EnvVarClientImage = "GATEWAY_CLIENT_IMAGE"
// EnvVarImageRegistry refers to the default image registry of gateway images
EnvVarImageRegistry = "GATEWAY_IMAGE_REGISTRY"
// EnvVarImageVersion refers to the version of the gateway images
EnvVarImageVersion = "GATEWAY_IMAGE_VERSION"
// EnvVarGatewayClientImage refers to the env var for gateway client image
EnvVarGatewayClientImage = "GATEWAY_CLIENT_IMAGE"
// EnvVarGatewayServerImage refers to the default gateway server image
EnvVarGatewayServerImage = "GATEWAY_SERVER_IMAGE"
// EnvVarSensorImage refers to the default sensor image
EnvVarSensorImage = "SENSOR_IMAGE"
)
Expand Down
8 changes: 6 additions & 2 deletions controllers/gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
FROM centos:7
FROM alpine:latest as certs
RUN apk --update add ca-certificates

FROM scratch
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY dist/gateway-controller /bin/
ENTRYPOINT [ "/bin/gateway-controller" ]
ENTRYPOINT [ "/bin/gateway-controller" ]
26 changes: 5 additions & 21 deletions controllers/gateway/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/argoproj/argo-events/common"
"github.com/argoproj/argo-events/controllers/gateway"
apicommon "github.com/argoproj/argo-events/pkg/apis/common"
)

func main() {
Expand All @@ -45,21 +44,16 @@ func main() {
namespace = common.DefaultControllerNamespace
}

clientImage, ok := os.LookupEnv(common.EnvVarClientImage)
clientImage, ok := os.LookupEnv(common.EnvVarGatewayClientImage)
if !ok {
panic(fmt.Sprintf("Env var %s for gateway client image is not provided", common.EnvVarClientImage))
panic(fmt.Sprintf("Env var %s for gateway client image is not provided", common.EnvVarGatewayClientImage))
}
gatewayImageRegistry, ok := os.LookupEnv(common.EnvVarImageRegistry)
serverImage, ok := os.LookupEnv(common.EnvVarGatewayServerImage)
if !ok {
gatewayImageRegistry = "docker.io"
panic(fmt.Sprintf("Env var %s for gateway server image is not provided", common.EnvVarGatewayServerImage))
}
gatewayImageVersion, ok := os.LookupEnv(common.EnvVarImageVersion)
if !ok {
gatewayImageVersion = "latest"
}
gatewayImages := getGatewayImages(gatewayImageRegistry, gatewayImageVersion)
// create new gateway controller
controller := gateway.NewGatewayController(restConfig, configMap, namespace, clientImage, gatewayImages)
controller := gateway.NewGatewayController(restConfig, configMap, namespace, clientImage, serverImage)
// watch for configuration updates for the controller
err = controller.ResyncConfig(namespace)
if err != nil {
Expand All @@ -69,13 +63,3 @@ func main() {
go controller.Run(context.Background(), 1)
select {}
}

// getGatewayImages is used to get the gateway image mapping
// TODO: temporarily solution, need to figure out a better way
func getGatewayImages(gatewayImageRegistry, gatewayImageVersion string) map[apicommon.EventSourceType]string {
var result = make(map[apicommon.EventSourceType]string)
for k, v := range apicommon.GetGatewayImageNameMapping() {
result[k] = fmt.Sprintf("%s/%s:%s", gatewayImageRegistry, v, gatewayImageVersion)
}
return result
}

0 comments on commit 6bc5dcf

Please sign in to comment.