Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Nov 8, 2024
1 parent 18350f6 commit f730ebc
Show file tree
Hide file tree
Showing 51 changed files with 3,054 additions and 5 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: '3.x'

- name: Test
run: make test

- name: Registry login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_ACCESS_TOKEN }}

- name: Release
run: make release
74 changes: 74 additions & 0 deletions .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Staging

on:
push:
branches:
- "mistress"

env:
COMPONENT: source-websocket
VERSION: latest
CHART_VERSION: 0.0.0

jobs:

deploy:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2

- name: Registry login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_ACCESS_TOKEN }}

- name: Staging
run: make staging

- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.12.0

- name: Helm Lint
run: |
helm lint helm/${COMPONENT}
- name: Helm Package
run: |
helm dependency update helm/${COMPONENT}
mkdir helm/package
helm package helm/${COMPONENT} --destination helm/package
cd helm/package
helm repo index .
- name: Publish Helm Chart
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: helm/package/

- name: Google Cloud Auth
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GKE_SA_KEY }}'

- uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GKE_RPOJECT_ID }}

- name: Kubeconfig
run: |
gcloud components install gke-gcloud-auth-plugin
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER_NAME_DEMO }} \
--region ${{ secrets.GKE_CLUSTER_REGION }} \
--project ${{ secrets.GKE_PROJECT_ID }}
- name: Helm Upgrade
run: |
helm upgrade --install ${COMPONENT} helm/package/${COMPONENT}-0.0.0.tgz \
--set replicaCount=2 \
--set-string podAnnotations.commit=$(git rev-parse --short HEAD)
51 changes: 51 additions & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Testing

on:
push:
branches:
- "*"
- "!mistress"

jobs:

build:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
# repo-token is necessary to avoid the rate limit issue
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: "3.x"

- name: Build
run: make build

test:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
version: "3.x"

- name: Test
run: make test
env:
DB_URI_TEST_MONGO: ${{ secrets.DB_URI_TEST_MONGO }}
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env
**/*.pb.go
cover.tmp
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.23.2-alpine3.20 AS builder
WORKDIR /go/src/source-websocket
COPY . .
RUN \
apk add protoc protobuf-dev make git && \
make build

FROM alpine:3.20
RUN apk --no-cache add ca-certificates \
&& update-ca-certificates
COPY --from=builder /go/src/source-websocket/source-websocket /bin/source-websocket
ENTRYPOINT ["/bin/source-websocket"]
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.PHONY: test clean
default: build

BINARY_FILE_NAME=source-websocket
COVERAGE_FILE_NAME=cover.out
COVERAGE_TMP_FILE_NAME=cover.tmp

proto:
go install github.com/golang/protobuf/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1
PATH=${PATH}:~/go/bin protoc --go_out=plugins=grpc:. --go_opt=paths=source_relative \
api/grpc/*.proto

vet: proto
go vet

test: vet
go test -race -cover -coverprofile=${COVERAGE_FILE_NAME} ./...
cat ${COVERAGE_FILE_NAME} | grep -v _mock.go | grep -v logging.go | grep -v .pb.go > ${COVERAGE_FILE_NAME}.tmp
mv -f ${COVERAGE_FILE_NAME}.tmp ${COVERAGE_FILE_NAME}
go tool cover -func=${COVERAGE_FILE_NAME} | grep -Po '^total\:\h+\(statements\)\h+\K.+(?=\.\d+%)' > ${COVERAGE_TMP_FILE_NAME}
./scripts/cover.sh
rm -f ${COVERAGE_TMP_FILE_NAME}

build: proto
CGO_ENABLED=0 GOOS=linux GOARCH= GOARM= go build -o ${BINARY_FILE_NAME} main.go
chmod ugo+x ${BINARY_FILE_NAME}

docker:
docker build -t awakari/source-websocket .


staging: docker
./scripts/staging.sh

release: docker
./scripts/release.sh

clean:
go clean
rm -f ${BINARY_FILE_NAME} ${COVERAGE_FILE_NAME}
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# source-websocket
WebSocket source implementation for Awakari
Server-sent events source type

```shell
grpcurl \
-plaintext \
-proto api/grpc/service.proto \
-d @ \
localhost:50051 \
awakari.source.websocket.Service/Create
```

```json
{
"url": "wss://www.seismicportal.eu/standing_order/websocket",
"groupId": "default"
}
```
Loading

0 comments on commit f730ebc

Please sign in to comment.