ci(build): deployment fixes

This commit is contained in:
Tine 2024-02-17 20:19:18 +01:00
parent 7699acea6f
commit b1a766f9b6
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
10 changed files with 78 additions and 29 deletions

View file

@ -1,3 +0,0 @@
build
deploy
docs

View file

@ -12,12 +12,12 @@ RUN go mod download
COPY . ./
# Build
RUN CGO_ENABLED=1 GOOS=linux go build -o /zdravko cmd/zdravko/main.go
RUN CGO_ENABLED=1 GOOS=linux go build -o /bin/zdravko cmd/zdravko/main.go
###
# Final production
FROM gcr.io/distroless/base-debian12:nonroot as production
COPY --from=builder /zdravko /zdravko
FROM debian:12-slim as production
COPY --from=builder /bin/zdravko /bin/zdravko
COPY LICENSE /LICENSE
COPY README.md /README.md

View file

@ -86,10 +86,12 @@ func main() {
for sig := range c {
log.Printf("Received signal: %v", sig)
for _, s := range servers {
println("Stopping", s.Name())
err := s.Stop()
if err != nil {
log.Fatalf("Unable to stop server %s: %v", s.Name(), err)
if s != nil {
println("Stopping", s.Name())
err := s.Stop()
if err != nil {
log.Fatalf("Unable to stop server %s: %v", s.Name(), err)
}
}
}
}

View file

@ -1,11 +1,14 @@
# syntax=docker/dockerfile:1
ARG ALPINE_VERSION=3.14
ARG ZDRAVKO_VERSION=main
FROM ghcr.io/mentos1386/zdravko:${ZDRAVKO_VERSION}
RUN apt-get update -y \
&& apt-get install -y ca-certificates fuse3 sqlite3
FROM alpine:${ALPINE_VERSION} as temporal
RUN apk add ca-certificates fuse3 sqlite
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
COPY litefs.yaml /etc/litefs.yaml
COPY --from=ghcr.io/mentos1386/zdravko /zdravko /zdravko
COPY deploy/litefs.yaml /etc/litefs.yml
COPY deploy/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT litefs mount
ENTRYPOINT ["/entrypoint.sh"]

14
deploy/entrypoint.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
PROCESS=${FLY_PROCESS_GROUP}
if [ "$PROCESS" = "server" ]; then
echo "Starting server process"
exec litefs mount -- $@
elif [ "$PROCESS" = "worker" ]; then
echo "Starting worker process"
exec $@
else
echo "Unknown process"
exit 1
fi

View file

@ -5,6 +5,7 @@ primary_region = 'waw'
[build]
dockerfile = "Dockerfile"
context = "deploy"
[env]
ROOT_URL = 'https://zdravko.mnts.dev'
@ -17,8 +18,8 @@ primary_region = 'waw'
TEMPORAL_SERVER_HOST = 'server.process.zdravko.internal:7233'
[processes]
server = "zdravko --temporal=true --server=true --worker=false"
worker = "zdravko --temporal=false --server=false --worker=true"
server = "/zdravko --temporal=true --server=true --worker=false"
worker = "/zdravko --temporal=false --server=false --worker=true"
[[mounts]]
source = "zdravko_data"

View file

@ -7,9 +7,6 @@ fuse:
data:
dir: "/var/lib/litefs"
exec:
- cmd: "/zdravko --temporal=true --server=true --worker=false"
lease:
type: "consul"

View file

@ -6,16 +6,16 @@ import (
"net/http"
)
type HealtcheckHttpActivityParam struct {
type HealtcheckHttpParam struct {
Url string
Method string
}
type HealthcheckHttpActivityResult struct {
type HealthcheckHttpResult struct {
StatusCode int
}
func HealthcheckHttpActivityDefinition(ctx context.Context, param HealtcheckHttpActivityParam) (*HealthcheckHttpActivityResult, error) {
func HealthcheckHttp(ctx context.Context, param HealtcheckHttpParam) (*HealthcheckHttpResult, error) {
if param.Method == "" {
param.Method = "GET"
}
@ -38,5 +38,40 @@ func HealthcheckHttpActivityDefinition(ctx context.Context, param HealtcheckHttp
log.Printf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", response.StatusCode, param.Url)
return &HealthcheckHttpActivityResult{StatusCode: response.StatusCode}, nil
return &HealthcheckHttpResult{StatusCode: response.StatusCode}, nil
}
type HealtcheckHttpAddToHistoryParam struct {
Id string
Success bool
StatusCode int
}
type HealthcheckHttpAddToHistoryResult struct {
}
func HealthcheckHttpWriteResult(ctx context.Context, param HealtcheckHttpParam) (*HealthcheckHttpResult, error) {
if param.Method == "" {
param.Method = "GET"
}
var (
response *http.Response
err error
)
switch param.Method {
case "GET":
response, err = http.Get(param.Url)
case "POST":
response, err = http.Post(param.Url, "application/json", nil)
}
if err != nil {
return nil, err
}
log.Printf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", response.StatusCode, param.Url)
return &HealthcheckHttpResult{StatusCode: response.StatusCode}, nil
}

View file

@ -19,13 +19,13 @@ func HealthcheckHttpWorkflowDefinition(ctx workflow.Context, param HealthcheckHt
}
ctx = workflow.WithActivityOptions(ctx, options)
activityParam := activities.HealtcheckHttpActivityParam{
activityParam := activities.HealtcheckHttpParam{
Url: param.Url,
Method: param.Method,
}
var result *activities.HealthcheckHttpActivityResult
err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttpActivityDefinition, activityParam).Get(ctx, &result)
var result *activities.HealthcheckHttpResult
err := workflow.ExecuteActivity(ctx, activities.HealthcheckHttp, activityParam).Get(ctx, &result)
if err != nil {
return err
}

View file

@ -37,7 +37,7 @@ func (w *Worker) Start() error {
w.worker.RegisterWorkflow(workflows.HealthcheckHttpWorkflowDefinition)
// Register Activities
w.worker.RegisterActivity(activities.HealthcheckHttpActivityDefinition)
w.worker.RegisterActivity(activities.HealthcheckHttp)
return w.worker.Run(worker.InterruptCh())
}