Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Go Language Support – Milestone v0.2.0 #43

Merged
merged 4 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Update the VARIANT arg in devcontainer.json to pick an Go version
ARG VARIANT=1
FROM golang:1.14

# This Dockerfile adds a non-root user with sudo access. Update the “remoteUser” property in
# devcontainer.json to use it. More info: https://aka.ms/vscode-remote/containers/non-root-user.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Options for common setup script - SHA generated on release
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="false"
ARG COMMON_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/master/script-library/common-debian.sh"
ARG COMMON_SCRIPT_SHA="dev-mode"

# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends curl ca-certificates 2>&1 \
&& curl -sSL ${COMMON_SCRIPT_SOURCE} -o /tmp/common-setup.sh \
&& ([ "${COMMON_SCRIPT_SHA}" = "dev-mode" ] || (echo "${COMMON_SCRIPT_SHA} /tmp/common-setup.sh" | sha256sum -c -)) \
&& /bin/bash /tmp/common-setup.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Use Docker within a Codespace
# https://docs.microsoft.com/en-us/visualstudio/codespaces/reference/configuring#use-docker-within-a-codespace
RUN groupadd -g 800 docker
RUN usermod -a -G docker vscode

# Install Go tools
ARG GO_TOOLS_WITH_MODULES="\
golang.org/x/tools/gopls \
honnef.co/go/tools/... \
golang.org/x/tools/cmd/gorename \
golang.org/x/tools/cmd/goimports \
golang.org/x/tools/cmd/guru \
golang.org/x/lint/golint \
github.com/mdempsky/gocode \
github.com/cweill/gotests/... \
github.com/haya14busa/goplay/cmd/goplay \
github.com/sqs/goreturns \
github.com/josharian/impl \
github.com/davidrjenni/reftools/cmd/fillstruct \
github.com/uudashr/gopkgs/v2/cmd/gopkgs \
github.com/ramya-rao-a/go-outline \
github.com/acroca/go-symbols \
github.com/godoctor/godoctor \
github.com/rogpeppe/godef \
github.com/zmb3/gogetdoc \
github.com/fatih/gomodifytags \
github.com/mgechev/revive \
github.com/go-delve/delve/cmd/dlv"
RUN mkdir -p /tmp/gotools \
&& cd /tmp/gotools \
&& export GOPATH=/tmp/gotools \
# Go tools w/module support
&& export GO111MODULE=on \
&& (echo "${GO_TOOLS_WITH_MODULES}" | xargs -n 1 go get -x )2>&1 \
# gocode-gomod
&& export GO111MODULE=auto \
&& go get -x -d github.com/stamblerre/gocode 2>&1 \
&& go build -o gocode-gomod github.com/stamblerre/gocode \
# golangci-lint
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin 2>&1 \
# Move Go tools into path and clean up
&& mv /tmp/gotools/bin/* /usr/local/bin/ \
&& mv gocode-gomod /usr/local/bin/ \
&& rm -rf /tmp/gotools

ENV GO111MODULE=auto

RUN go get github.com/golang/protobuf/protoc-gen-go

RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends protobuf-compiler docker.io
12 changes: 12 additions & 0 deletions .devcontainer/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail

readonly CMD=${1:-image}
readonly IMAGE=cloudstateio/cloudstate-go-devcontainer:latest
docker build . -t "$IMAGE"
if [ "$CMD" == "push" ]; then
docker push "$IMAGE"
fi
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Go",
"image": "cloudstateio/cloudstate-go-devcontainer",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"-v",
"/var/run/docker.sock:/var/run/docker.sock"
],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"go.gopath": "/go"
},
"extensions": [
"golang.go"
],
"remoteUser": "vscode"
}
42 changes: 29 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@ language: go
os:
- linux
go:
- 1.13.x

- 1.14.x
services:
- docker
env:
global:
# encrypted with: travis encrypt --pro -r cloudstateio/go-support DEPLOY_DOCS_TOKEN=<token>
- secure: "L1uMy3mR5U+0HFmjJwSD6i/av667T187DkzIlRwfTnEGPG6LoZ5EwyGC/IxbKbV2EyUmxt7zDO+OXvsiZx0l0mXZ5ozAKdTB7eb/ujhinwnvB82OtKu8ejvZqI0ooPO+D1RlxqZF5HCX69L0DfTjhytkqLUIlN4CTtSO4ElJ/1Ottg0c3qiNUYvNdFqsKsF7Dq7EJU8G/vZ6o1WCUJzawLshOGDQ9jSL14QnKquFr/cMXHcg3GgiPVl2NFWAld0fOuNpYqUy2X3O7V4/FOJGe+btOao4xQyVsn9V/1VFsqRCyp1uy+kPbQbA0f+fBY3CnDpLKHrhYv8TDdfP9tbUEIhGikc+aqYeGOP6+4vPK/Xi/p2pZEZErPcBfc7CoJECNG4csMjq0GGdhp6UYJO1JPMVrLFZsWLoxPiXTkreQ+Gj4+Jgia20xfcUR/tkZrCQMnkySfFPHK48g2VOadfIZNz6hbdMGrZUarMrWC/hi3DIUdoT0Wn6y5LuP8goAbIBI/+KXvECIdiqTHu7WIwtdesTIZJvHhdp44zec8Teb0Bo6uYoIrKXvfTQbgvTzMzZO8DZ1L21OL7EKD9H6rvFabZXz5I2i9695Q6gkQYmK6Twg6CK1p/aZXmJWN8QXceXPavl3iNvC2fMSFxZvHBuqAjknCQlmTH7/BKyEw5AQ/Q="
# Docker hub password; encrypted with: travis encrypt --pro -r cloudstateio/go-support DOCKER_PASSWORD={password}
- secure: "OMwsvgBLGl+804bEIo9UigU9EDz3jnKR3oCkowbzfeT+yGb/aGqUFBBBw6fzruaB3h8Uyhe1wQUgAOwEE7xMQmNhKvHEYW0esQZQHmGeUgyCyeelh5U7iamivokXnCx2zhRj+kgd4gQE+RCunhqDcHNXGxDEf1GmQ0U/HAYVNyt6jEOVEEqb0UiG0NkTO6wRcw5fJsNrb1kPRHBM5OkoVlSNwu90kVlDgo/MPbEaNw1qkx52cA1FrTuBap4sHZNXs4BRFAoIivJNrHhrjiz41jdblcmBPLnL6hkGUguJKCBTxyuKInRKI4/grU47yg/0KNqjGOOF1MZcNbp1e09vZ1TDLHxYj4Qy3hclJTrpemcT5xdoud4nsIVyAFstR1xm2J6iKNJ+qz85wWYhxfgk8o3MJFepYqEZsNaDfGd/lWHYRXml5UJwlwA5eG/D6Q6CKn4qF1DUn5+yLgsO73MQ1qAMADgp1dhkhHELcs94w8GOWCvaNy7Zt4fKpEOLc1ThCnKQYjXQ3zOsEcciuoYtK0QxgaqpHgnvNZcZOB3H/iBkdnNW3YaQUl2+4Ooq/JmYissj6GXD1NbP5xNCEThFCGsroHm6OAJRM3BaWmna6DBworwg+lr6PMyn9fVhbOJKaH5wdfwQXOFwQ798rxK6n/oZVIBSztHhY29JNCZMtoo="
jobs:
include:
- stage: build
before_install:
- go get -t -v ./...
script:
- go test -v -race -coverprofile=coverage.txt -covermode=atomic -bench=. ./...
- go test -v -race -coverprofile=coverage_all.txt -covermode=atomic -coverpkg=github.com/cloudstateio/go-support/cloudstate/... ./...
- cat coverage_all.txt | grep -v ".pb.go" > coverage.txt && rm coverage_all.txt
after_success:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then bash <(curl -s https://codecov.io/bash); fi

- stage: validate docs
script: make -C docs

- stage: verification
name: tck verification
script:
- cd tck && ./run_tck.sh
- stage: deploy docs
name: deploy release docs to cloudstate.io
if: tag =~ ^v
script: make -C docs deploy

env:
global:
# encrypted with: travis encrypt --pro -r cloudstateio/go-support DEPLOY_DOCS_TOKEN=<token>
secure: "L1uMy3mR5U+0HFmjJwSD6i/av667T187DkzIlRwfTnEGPG6LoZ5EwyGC/IxbKbV2EyUmxt7zDO+OXvsiZx0l0mXZ5ozAKdTB7eb/ujhinwnvB82OtKu8ejvZqI0ooPO+D1RlxqZF5HCX69L0DfTjhytkqLUIlN4CTtSO4ElJ/1Ottg0c3qiNUYvNdFqsKsF7Dq7EJU8G/vZ6o1WCUJzawLshOGDQ9jSL14QnKquFr/cMXHcg3GgiPVl2NFWAld0fOuNpYqUy2X3O7V4/FOJGe+btOao4xQyVsn9V/1VFsqRCyp1uy+kPbQbA0f+fBY3CnDpLKHrhYv8TDdfP9tbUEIhGikc+aqYeGOP6+4vPK/Xi/p2pZEZErPcBfc7CoJECNG4csMjq0GGdhp6UYJO1JPMVrLFZsWLoxPiXTkreQ+Gj4+Jgia20xfcUR/tkZrCQMnkySfFPHK48g2VOadfIZNz6hbdMGrZUarMrWC/hi3DIUdoT0Wn6y5LuP8goAbIBI/+KXvECIdiqTHu7WIwtdesTIZJvHhdp44zec8Teb0Bo6uYoIrKXvfTQbgvTzMzZO8DZ1L21OL7EKD9H6rvFabZXz5I2i9695Q6gkQYmK6Twg6CK1p/aZXmJWN8QXceXPavl3iNvC2fMSFxZvHBuqAjknCQlmTH7/BKyEw5AQ/Q="
language: scala
script: cd docs && sbt deploy
- stage: deploy docs
name: deploy snapshot docs to cloudstate.io
if: branch = master AND type = push
language: scala
script: cd docs && sbt deploy
- stage: deploy devcontainer image
name: deploy devcontainer image to dockerhub
if: branch = master AND type = push
script:
- echo "$DOCKER_PASSWORD" | docker login -u cloudstatebot --password-stdin
- pushd . && cd .devcontainer && ./build.sh push && popd
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Cloudstate stateful service support in Go
[![Build Status](https://travis-ci.com/cloudstateio/go-support.svg)](https://travis-ci.com/cloudstateio/go-support)
[![GoDev](https://img.shields.io/static/v1?label=godev&message=reference&color=00add8)](https://pkg.go.dev/mod/github.com/cloudstateio/go-support)
[![Build Status](https://travis-ci.com/cloudstateio/go-support.svg)](https://travis-ci.com/cloudstateio/go-support)
[![Go Report Card](https://goreportcard.com/badge/github.com/cloudstateio/go-support)](https://goreportcard.com/report/github.com/cloudstateio/go-support)
[![codecov](https://codecov.io/gh/cloudstateio/go-support/branch/master/graph/badge.svg)](https://codecov.io/gh/cloudstateio/go-support)
[![GoDoc](https://godoc.org/github.com/cloudstateio/go-support/cloudstate?status.svg)](https://godoc.org/github.com/cloudstateio/go-support/cloudstate)

This package provides support for writing [Cloudstate](https://github.com/cloudstateio/cloudstate) stateful functions in Go.

Expand Down
21 changes: 10 additions & 11 deletions build/TCK.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
FROM golang:1.13.1-alpine3.10
FROM golang:1.14.4-alpine3.12 as builder

RUN apk --no-cache add git
RUN apk --no-cache add ca-certificates

WORKDIR /go/src/app
COPY . .

#
# -race and therefore CGO needs gcc, we don't want it to have in our build
RUN CGO_ENABLED=0 go build -v -o tck_shoppingcart ./tck/cmd/tck_shoppingcart
RUN CGO_ENABLED=0 go build -v -o tck_eventsourced ./tck/cmd/tck_eventsourced
RUN go install -v ./...

#
# multistage – copy over the binary
FROM alpine:latest
RUN apk --no-cache add ca-certificates

WORKDIR /root/
COPY --from=0 /go/bin/tck_shoppingcart .

RUN mkdir -p /srv/
WORKDIR /srv
COPY --from=builder /go/bin/tck_eventsourced .
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
EXPOSE 8080
ENV HOST 0.0.0.0
ENV PORT 8080

CMD ["./tck_shoppingcart"]
CMD ["./tck_eventsourced"]
4 changes: 2 additions & 2 deletions build/build-and-publish-docker-image-tck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -o nounset
set -o errexit
set -o pipefail

docker build -t gcr.io/mrcllnz/cloudstate-go-tck:latest -f ./build/TCK.Dockerfile .
docker push gcr.io/mrcllnz/cloudstate-go-tck:latest
DOCKER_BUILDKIT=1 docker build -t cloudstateio/cloudstate-go-tck:latest -f ./build/TCK.Dockerfile . || exit $?
docker push cloudstateio/cloudstate-go-tck:latest
76 changes: 67 additions & 9 deletions build/compile-pb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,70 @@ set -o nounset
set -o errexit
set -o pipefail

# CloudState protocol
protoc --go_out=plugins=grpc,paths=source_relative:. --proto_path=protobuf/frontend/ protobuf/frontend/cloudstate/entity_key.proto
protoc --go_out=plugins=grpc:. --proto_path=protobuf/protocol/ protobuf/protocol/cloudstate/entity.proto
protoc --go_out=plugins=grpc:. --proto_path=protobuf/protocol/ protobuf/protocol/cloudstate/event_sourced.proto
protoc --go_out=plugins=grpc:. --proto_path=protobuf/protocol/ protobuf/protocol/cloudstate/function.proto

# TCK shopping cart sample
protoc --go_out=plugins=grpc:. --proto_path=protobuf/protocol/ --proto_path=protobuf/frontend/ --proto_path=protobuf/proxy/ --proto_path=protobuf/example/ protobuf/example/shoppingcart/shoppingcart.proto
protoc --go_out=plugins=grpc,paths=source_relative:tck/shoppingcart/persistence --proto_path=protobuf/protocol/ --proto_path=protobuf/frontend/ --proto_path=protobuf/proxy/ --proto_path=protobuf/example/shoppingcart/persistence/ protobuf/example/shoppingcart/persistence/domain.proto
# Cloudstate
protoc --go_out=plugins=grpc,paths=source_relative:cloudstate/protocol --proto_path=protobuf/protocol/cloudstate entity.proto
protoc --go_out=plugins=grpc,paths=source_relative:. --proto_path=protobuf/frontend/ cloudstate/entity_key.proto
protoc --go_out=plugins=grpc,paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol \
--proto_path=protobuf/protocol/cloudstate crdt.proto
protoc --go_out=plugins=grpc,paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ \
--proto_path=protobuf/protocol/cloudstate function.proto
protoc --go_out=plugins=grpc,paths=source_relative:cloudstate/entity --proto_path=protobuf/protocol/ \
--proto_path=protobuf/protocol/cloudstate event_sourced.proto

# TCK CRDT
protoc --go_out=plugins=grpc,paths=source_relative:./tck/crdt \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=protobuf/tck tck_crdt.proto

# TCK Eventsourced
protoc --go_out=plugins=grpc,paths=source_relative:./tck/eventsourced \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=protobuf/tck/cloudstate/tck/model \
--proto_path=protobuf/tck eventsourced.proto

# CRDT shopping cart example
protoc --go_out=plugins=grpc,paths=source_relative:./example/crdt_shoppingcart/shoppingcart --proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/crdt_shoppingcart/shoppingcart shoppingcart.proto hotitems.proto

protoc --go_out=plugins=grpc,paths=source_relative:./example/crdt_shoppingcart/domain --proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/crdt_shoppingcart/domain domain.proto

# event sourced shopping cart example
protoc --go_out=plugins=grpc,paths=source_relative:./example/shoppingcart/ \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/shoppingcart shoppingcart.proto
protoc --go_out=plugins=grpc,paths=source_relative:./example/shoppingcart/persistence \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/shoppingcart/persistence domain.proto

# chat example
protoc --go_out=plugins=grpc,paths=source_relative:./example/chat/presence/ \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/chat/presence/ example/chat/presence/presence.proto
protoc --go_out=plugins=grpc,paths=source_relative:./example/chat/friends/ \
--proto_path=protobuf/protocol \
--proto_path=protobuf/frontend \
--proto_path=protobuf/frontend/cloudstate \
--proto_path=protobuf/proxy \
--proto_path=example/chat/friends/ example/chat/friends/friends.proto
32 changes: 0 additions & 32 deletions build/fetch-cloudstate-pb.sh

This file was deleted.

Loading