Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit c8ae4b9

Browse files
authored
Merge pull request #5 from devhou-se/feat/sreeification-aas
Sreeification As A Service
2 parents 38f7582 + 2ea5285 commit c8ae4b9

22 files changed

Lines changed: 1129 additions & 72 deletions

File tree

.github/workflows/cd.yaml

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
setup-build-publish-deploy:
11-
name: Setup, Build, Publish, and Deploy
10+
build-proxy:
11+
name: Build Proxy
1212
runs-on: ubuntu-latest
1313

1414
steps:
@@ -27,15 +27,81 @@ jobs:
2727
run: |
2828
gcloud --quiet auth configure-docker
2929
30-
- name: Build and Push Docker Image
30+
- name: Build Docker Image
3131
run: |
3232
docker build -t gcr.io/baileybutler-syd/sreekipedia:${{ github.sha }} .
3333
docker push gcr.io/baileybutler-syd/sreekipedia:${{ github.sha }}
3434
35+
deploy-proxy:
36+
name: Deploy Proxy
37+
runs-on: ubuntu-latest
38+
needs:
39+
- build-proxy
40+
- build-sreeifier
41+
42+
steps:
43+
- name: Authorise GCP
44+
uses: google-github-actions/auth@v1
45+
with:
46+
credentials_json: ${{ secrets.SA_JSON }}
47+
48+
- name: Set up Cloud SDK
49+
uses: google-github-actions/setup-gcloud@v0.3
50+
3551
- name: Deploy to Cloud Run
3652
uses: google-github-actions/deploy-cloudrun@v1
3753
with:
3854
service: sreekipedia
3955
image: gcr.io/baileybutler-syd/sreekipedia:${{ github.sha }}
4056
region: asia-southeast1
41-
flags: "--min-instances=1 --max-instances=100 --allow-unauthenticated"
57+
flags: "--min-instances=0 --max-instances=100 --allow-unauthenticated"
58+
env_vars: |
59+
SREEIFIER_SERVER=sreeifier-vvgwyvu7bq-as.a.run.app:443
60+
61+
build-sreeifier:
62+
name: Build Sreeifier
63+
runs-on: ubuntu-latest
64+
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v2
68+
69+
- name: Authorise GCP
70+
uses: google-github-actions/auth@v1
71+
with:
72+
credentials_json: ${{ secrets.SA_JSON }}
73+
74+
- name: Set up Cloud SDK
75+
uses: google-github-actions/setup-gcloud@v0.3
76+
77+
- name: Configure Docker
78+
run: |
79+
gcloud --quiet auth configure-docker
80+
81+
- name: Build Docker Image
82+
run: |
83+
docker build -t gcr.io/baileybutler-syd/sreeifier:${{ github.sha }} ./python
84+
docker push gcr.io/baileybutler-syd/sreeifier:${{ github.sha }}
85+
86+
deploy-sreeifier:
87+
name: Deploy Sreeifier
88+
runs-on: ubuntu-latest
89+
needs:
90+
- build-sreeifier
91+
92+
steps:
93+
- name: Authorise GCP
94+
uses: google-github-actions/auth@v1
95+
with:
96+
credentials_json: ${{ secrets.SA_JSON }}
97+
98+
- name: Set up Cloud SDK
99+
uses: google-github-actions/setup-gcloud@v0.3
100+
101+
- name: Deploy to Cloud Run
102+
uses: google-github-actions/deploy-cloudrun@v1
103+
with:
104+
service: sreeifier
105+
image: gcr.io/baileybutler-syd/sreeifier:${{ github.sha }}
106+
region: asia-southeast1
107+
flags: "--min-instances=0 --max-instances=100 --use-http2 --allow-unauthenticated"

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.idea/*
1+
.idea/*
2+
*/.idea/*
3+
*.pyc

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ WORKDIR /app
55
COPY go.mod go.mod
66
COPY go.sum go.sum
77

8+
RUN go mod download
9+
810
COPY ./internal ./internal
911
COPY ./app.go ./app.go
1012

app.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package main
22

33
import (
4-
"github.com/devhou-se/sreetcode/internal/server"
4+
"log/slog"
5+
6+
"github.com/devhou-se/sreetcode/internal/config"
7+
"github.com/devhou-se/sreetcode/internal/service"
58
)
69

710
func main() {
8-
s, err := server.NewWebServer()
11+
cfg := config.Load()
12+
13+
s, err := service.NewWebServer(cfg)
914
if err != nil {
1015
panic(err)
1116
}
1217

18+
slog.Info("Starting server")
1319
if err := s.ListenAndServe(); err != nil {
1420
panic(err)
1521
}

buf.gen.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: v1
2+
managed:
3+
enabled: true
4+
plugins:
5+
- plugin: buf.build/protocolbuffers/go
6+
out: internal/gen
7+
opt: paths=source_relative
8+
- plugin: buf.build/grpc/go
9+
out: internal/gen
10+
opt: paths=source_relative
11+
- plugin: buf.build/protocolbuffers/python
12+
out: python/gen
13+
- plugin: buf.build/grpc/python
14+
out: python/gen

docker-compose.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
sreeifier:
3+
build: ./python
4+
environment:
5+
- PORT=50051
6+
ports:
7+
- 50051:50051
8+
9+
proxy:
10+
build: .
11+
depends_on:
12+
- sreeifier
13+
ports:
14+
- 8080:8080
15+
environment:
16+
- INSECURE=true
17+
- SREEIFIER_SERVER=sreeifier:50051

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ go 1.21
55
require (
66
cloud.google.com/go/storage v1.33.0
77
github.com/go-chi/chi/v5 v5.0.10
8-
github.com/go-chi/hostrouter v0.2.0
8+
google.golang.org/grpc v1.56.2
9+
google.golang.org/protobuf v1.31.0
910
)
1011

1112
require (
@@ -32,6 +33,4 @@ require (
3233
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
3334
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
3435
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
35-
google.golang.org/grpc v1.56.2 // indirect
36-
google.golang.org/protobuf v1.31.0 // indirect
3736
)

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
3030
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
3131
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
3232
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
33-
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
3433
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
3534
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
36-
github.com/go-chi/hostrouter v0.2.0 h1:GwC7TZz8+SlJN/tV/aeJgx4F+mI5+sp+5H1PelQUjHM=
37-
github.com/go-chi/hostrouter v0.2.0/go.mod h1:pJ49vWVmtsKRKZivQx0YMYv4h0aX+Gcn6V23Np9Wf1s=
3835
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
3936
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
4037
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=

internal/config/config.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package config
2+
3+
import (
4+
"os"
5+
)
6+
7+
type Config struct {
8+
// Insecure is true if the server should use an insecure connection.
9+
Insecure bool
10+
// SreeifierServer is the address of the Sreeification gRPC server.
11+
SreeifierServer string
12+
}
13+
14+
func envOrDefault(key, def string) string {
15+
v := os.Getenv(key)
16+
if v == "" {
17+
v = def
18+
}
19+
return v
20+
}
21+
22+
func Load() Config {
23+
return Config{
24+
Insecure: envOrDefault("INSECURE", "") != "",
25+
SreeifierServer: envOrDefault("SREEIFIER_SERVER", "sreeifier-vvgwyvu7bq-as.a.run.app:443"),
26+
}
27+
}

0 commit comments

Comments
 (0)