Skip to content
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
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
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 ./...
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.local
.env
.DS_Store
gen/
38 changes: 38 additions & 0 deletions Dockerfile
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 . .

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"]
25 changes: 25 additions & 0 deletions Makefile
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
16 changes: 16 additions & 0 deletions buf.gen.yaml
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
4 changes: 4 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1

deps:
- buf.build/agynio/api
6 changes: 6 additions & 0 deletions charts/threads/Chart.yaml
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
42 changes: 42 additions & 0 deletions charts/threads/templates/_helpers.tpl
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 -}}
112 changes: 112 additions & 0 deletions charts/threads/templates/deployment.yaml
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 }}
Loading
Loading