-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement threads service #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GOTOOLCHAIN: local | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24.x' | ||
|
|
||
| - name: Install buf | ||
| run: | | ||
| curl -sSL https://github.com/bufbuild/buf/releases/download/v1.64.0/buf-Linux-x86_64.tar.gz \ | ||
| | sudo tar -xzf - -C /usr/local --strip-components=1 buf/bin/buf | ||
|
|
||
| - name: Generate protobuf bindings | ||
| run: | | ||
| buf generate buf.build/agynio/api --path agynio/api/threads/v1 --path agynio/api/notifications/v1 | ||
|
|
||
| - name: Run tests | ||
| run: go test ./... | ||
|
|
||
| - name: Build | ||
| run: go build ./... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| tags: | ||
| - 'v*' | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| jobs: | ||
| publish-edge: | ||
| if: github.ref == 'refs/heads/main' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and push edge image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: ghcr.io/agynio/threads:edge | ||
|
|
||
| publish-release: | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GOTOOLCHAIN: local | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.24.x' | ||
|
|
||
| - uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Install buf | ||
| run: | | ||
| curl -sSL https://github.com/bufbuild/buf/releases/download/v1.64.0/buf-Linux-x86_64.tar.gz \ | ||
| | sudo tar -xzf - -C /usr/local --strip-components=1 buf/bin/buf | ||
|
|
||
| - name: Set release version | ||
| run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Generate protobufs | ||
| run: make proto | ||
|
|
||
| - name: Run tests | ||
| run: go test ./... | ||
|
|
||
| - name: Build binaries | ||
| run: go build ./... | ||
|
|
||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and push release images | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: | | ||
| ghcr.io/agynio/threads:${{ env.VERSION }} | ||
| ghcr.io/agynio/threads:latest | ||
| ghcr.io/agynio/threads:${{ github.sha }} | ||
|
|
||
| - name: Setup Helm | ||
| uses: azure/setup-helm@v4 | ||
|
|
||
| - name: Package Helm chart | ||
| run: | | ||
| helm package charts/threads --version "${VERSION}" --app-version "${VERSION}" | ||
|
|
||
| - name: Push Helm chart to GHCR | ||
| env: | ||
| VERSION: ${{ env.VERSION }} | ||
| run: | | ||
| helm registry login ghcr.io --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} | ||
| helm push threads-${VERSION}.tgz oci://ghcr.io/agynio/charts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| *.local | ||
| .env | ||
| .DS_Store | ||
| gen/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # syntax=docker/dockerfile:1.8 | ||
|
|
||
| FROM golang:1.24 AS builder | ||
|
|
||
| ARG TARGETOS | ||
| ARG TARGETARCH | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| curl && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN curl -sSL https://github.com/bufbuild/buf/releases/download/v1.64.0/buf-Linux-x86_64.tar.gz \ | ||
| | tar -xzf - -C /usr/local --strip-components=1 buf/bin/buf | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download | ||
|
|
||
| COPY . . | ||
noa-lucent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| RUN buf generate buf.build/agynio/api --path agynio/api/threads/v1 --path agynio/api/notifications/v1 | ||
|
|
||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ | ||
| go build -trimpath -ldflags "-s -w" -o /out/threads ./cmd/threads | ||
|
|
||
| FROM gcr.io/distroless/base-debian12 AS runtime | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --from=builder /out/threads /usr/local/bin/threads | ||
|
|
||
| USER nonroot:nonroot | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/threads"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| SHELL := /bin/bash | ||
|
|
||
| PROTO_PATHS := agynio/api/threads/v1 agynio/api/notifications/v1 | ||
|
|
||
| .PHONY: all proto build test lint fmt clean | ||
|
|
||
| all: build | ||
|
|
||
| proto: | ||
| buf generate buf.build/agynio/api $(foreach p,$(PROTO_PATHS),--path $(p)) | ||
|
|
||
| build: | ||
| GOFLAGS=-mod=mod go build ./... | ||
|
|
||
| test: | ||
| GOFLAGS=-mod=mod go test ./... | ||
|
|
||
| lint: | ||
| GOFLAGS=-mod=mod go vet ./... | ||
|
|
||
| fmt: | ||
| gofmt -w $(shell find . -type f -name '*.go') | ||
|
|
||
| clean: | ||
| rm -rf gen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| version: v1 | ||
|
|
||
| plugins: | ||
| - plugin: buf.build/protocolbuffers/go | ||
| out: gen/go | ||
| opt: | ||
| - paths=source_relative | ||
| - Magynio/api/threads/v1/threads.proto=github.com/agynio/threads/gen/go/agynio/api/threads/v1 | ||
| - Magynio/api/notifications/v1/notifications.proto=github.com/agynio/threads/gen/go/agynio/api/notifications/v1 | ||
| - plugin: buf.build/grpc/go | ||
| out: gen/go | ||
| opt: | ||
| - paths=source_relative | ||
| - require_unimplemented_servers=false | ||
| - Magynio/api/threads/v1/threads.proto=github.com/agynio/threads/gen/go/agynio/api/threads/v1 | ||
| - Magynio/api/notifications/v1/notifications.proto=github.com/agynio/threads/gen/go/agynio/api/notifications/v1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| version: v1 | ||
|
|
||
| deps: | ||
| - buf.build/agynio/api |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: v2 | ||
| name: threads | ||
| description: Helm chart for the agynio threads gRPC service | ||
| type: application | ||
| version: 0.1.0 | ||
| appVersion: 0.1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| {{- define "threads.name" -}} | ||
| {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} | ||
| {{- end -}} | ||
|
|
||
| {{- define "threads.fullname" -}} | ||
| {{- if .Values.fullnameOverride -}} | ||
| {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} | ||
| {{- else -}} | ||
| {{- $name := default .Chart.Name .Values.nameOverride -}} | ||
| {{- if contains $name .Release.Name -}} | ||
| {{- .Release.Name | trunc 63 | trimSuffix "-" -}} | ||
| {{- else -}} | ||
| {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
|
|
||
| {{- define "threads.chart" -}} | ||
| {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" -}} | ||
| {{- end -}} | ||
|
|
||
| {{- define "threads.labels" -}} | ||
| helm.sh/chart: {{ include "threads.chart" . }} | ||
| {{ include "threads.selectorLabels" . }} | ||
| {{- with .Chart.AppVersion }} | ||
| app.kubernetes.io/version: {{ . | quote }} | ||
| {{- end }} | ||
| app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
| {{- end -}} | ||
|
|
||
| {{- define "threads.selectorLabels" -}} | ||
| app.kubernetes.io/name: {{ include "threads.name" . }} | ||
| app.kubernetes.io/instance: {{ .Release.Name }} | ||
| {{- end -}} | ||
|
|
||
| {{- define "threads.serviceAccountName" -}} | ||
| {{- if .Values.serviceAccount.create -}} | ||
| {{- default (include "threads.fullname" .) .Values.serviceAccount.name -}} | ||
| {{- else -}} | ||
| {{- default "default" .Values.serviceAccount.name -}} | ||
| {{- end -}} | ||
| {{- end -}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: {{ include "threads.fullname" . }} | ||
| labels: | ||
| {{- include "threads.labels" . | nindent 4 }} | ||
| spec: | ||
| replicas: {{ .Values.replicaCount }} | ||
| selector: | ||
| matchLabels: | ||
| {{- include "threads.selectorLabels" . | nindent 6 }} | ||
| template: | ||
| metadata: | ||
| labels: | ||
| {{- include "threads.selectorLabels" . | nindent 8 }} | ||
| {{- with .Values.podLabels }} | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.podAnnotations }} | ||
| annotations: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| spec: | ||
| serviceAccountName: {{ include "threads.serviceAccountName" . }} | ||
| {{- with .Values.imagePullSecrets }} | ||
| imagePullSecrets: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.podSecurityContext }} | ||
| securityContext: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| containers: | ||
| - name: threads | ||
| image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
| imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
| ports: | ||
| - name: grpc | ||
| containerPort: {{ .Values.service.port }} | ||
| protocol: TCP | ||
| {{- if .Values.probes.liveness.enabled }} | ||
| livenessProbe: | ||
| tcpSocket: | ||
| port: grpc | ||
| initialDelaySeconds: {{ .Values.probes.liveness.initialDelaySeconds }} | ||
| periodSeconds: {{ .Values.probes.liveness.periodSeconds }} | ||
| timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }} | ||
| failureThreshold: {{ .Values.probes.liveness.failureThreshold }} | ||
| successThreshold: {{ .Values.probes.liveness.successThreshold }} | ||
| {{- end }} | ||
| {{- if .Values.probes.readiness.enabled }} | ||
| readinessProbe: | ||
| tcpSocket: | ||
| port: grpc | ||
| initialDelaySeconds: {{ .Values.probes.readiness.initialDelaySeconds }} | ||
| periodSeconds: {{ .Values.probes.readiness.periodSeconds }} | ||
| timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }} | ||
| failureThreshold: {{ .Values.probes.readiness.failureThreshold }} | ||
| successThreshold: {{ .Values.probes.readiness.successThreshold }} | ||
| {{- end }} | ||
| {{- with .Values.securityContext }} | ||
| securityContext: | ||
| {{- toYaml . | nindent 12 }} | ||
| {{- end }} | ||
| env: | ||
| {{- $db := .Values.database -}} | ||
| {{- $url := "" -}} | ||
| {{- $secretName := "" -}} | ||
| {{- $secretKey := "database-url" -}} | ||
| {{- if $db }} | ||
| {{- with $db.url }} | ||
| {{- $url = . -}} | ||
| {{- end }} | ||
| {{- with $db.existingSecret }} | ||
| {{- with .name }} | ||
| {{- $secretName = . -}} | ||
| {{- end }} | ||
| {{- with .key }} | ||
| {{- $secretKey = . -}} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- if and $secretName $url }} | ||
| {{- fail "set only one of database.url or database.existingSecret.name" -}} | ||
| {{- end }} | ||
| - name: DATABASE_URL | ||
| {{- if $secretName }} | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: {{ $secretName }} | ||
| key: {{ $secretKey }} | ||
| {{- else }} | ||
| value: {{ required "database.url or database.existingSecret.name must be set" $url | quote }} | ||
| {{- end }} | ||
| - name: NOTIFICATIONS_ADDRESS | ||
| value: {{ required "notifications.address must be set" .Values.notifications.address | quote }} | ||
| {{- with .Values.resources }} | ||
| resources: | ||
| {{- toYaml . | nindent 12 }} | ||
| {{- end }} | ||
| {{- with .Values.nodeSelector }} | ||
| nodeSelector: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.affinity }} | ||
| affinity: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.tolerations }} | ||
| tolerations: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.