Skip to content
Snippets Groups Projects
Verified Commit 00cf7c10 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Update dependencies

parent 78aa2cbc
No related branches found
No related tags found
No related merge requests found
Pipeline #2704 failed
FROM golang FROM golang:1.17-alpine3.15 AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apk --no-cache add \
--virtual .build-deps \
alpine-sdk \
cmake \
sudo \
libssh2 libssh2-dev \
git \
dep \
bash \
curl \
imagemagick \ imagemagick \
libmagickwand-dev imagemagick-dev
WORKDIR /go/src/app WORKDIR /go/src/app
COPY go.* ./ COPY go.* ./
...@@ -10,4 +19,11 @@ RUN go mod download ...@@ -10,4 +19,11 @@ RUN go mod download
COPY . . COPY . .
RUN go build -o app . RUN go build -o app .
FROM alpine:3.15
RUN apk --no-cache add imagemagick
COPY --from=builder /app /app
RUN addgroup -g 1000 -S app && \
adduser -u 1000 -S app -G app \
USER app
ENTRYPOINT ["./app"] ENTRYPOINT ["./app"]
This diff is collapsed.
package main package main
import ( import (
"github.com/go-redis/redis" "context"
"github.com/go-redis/redis/v8"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/gographics/imagick.v2/imagick" "gopkg.in/gographics/imagick.v3/imagick"
"net/http" "net/http"
) )
...@@ -50,9 +51,9 @@ func main() { ...@@ -50,9 +51,9 @@ func main() {
_, _ = w.Write([]byte("OK")) _, _ = w.Write([]byte("OK"))
}) })
go serveQueue(client, config.ImageQueue, func(value string) { go serveQueue(context.Background(), client, config.ImageQueue, func(ctx context.Context, value string) {
queueGaugeQueued.Dec() queueGaugeQueued.Dec()
ProcessImage(&config, client, value) ProcessImage(ctx, &config, client, value)
}) })
if err := http.ListenAndServe(":2112", nil); err != nil { if err := http.ListenAndServe(":2112", nil); err != nil {
panic(err) panic(err)
......
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/go-redis/redis" "github.com/go-redis/redis/v8"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
...@@ -13,7 +14,7 @@ func trackTime(start time.Time, function func(time.Duration)) { ...@@ -13,7 +14,7 @@ func trackTime(start time.Time, function func(time.Duration)) {
function(time.Now().UTC().Sub(start.UTC())) function(time.Now().UTC().Sub(start.UTC()))
} }
func ProcessImage(config *Config, client *redis.Client, value string) { func ProcessImage(ctx context.Context, config *Config, client *redis.Client, value string) {
queueGaugeInProgress.Inc() queueGaugeInProgress.Inc()
defer queueGaugeInProgress.Dec() defer queueGaugeInProgress.Dec()
defer trackTime(time.Now(), func(duration time.Duration) { defer trackTime(time.Now(), func(duration time.Duration) {
...@@ -36,14 +37,14 @@ func ProcessImage(config *Config, client *redis.Client, value string) { ...@@ -36,14 +37,14 @@ func ProcessImage(config *Config, client *redis.Client, value string) {
if len(errors) != 0 { if len(errors) != 0 {
imageCounterFailure.Inc() imageCounterFailure.Inc()
returnResult(config, client, Result{ returnResult(ctx, config, client, Result{
Id: image.Id, Id: image.Id,
Success: false, Success: false,
Errors: errorMessages, Errors: errorMessages,
}) })
} else { } else {
imageCounterSuccess.Inc() imageCounterSuccess.Inc()
returnResult(config, client, Result{ returnResult(ctx, config, client, Result{
Id: image.Id, Id: image.Id,
Success: true, Success: true,
}) })
......
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/go-redis/redis" "github.com/go-redis/redis/v8"
) )
func serveQueue(client *redis.Client, queue string, function func(value string)) { func serveQueue(
ctx context.Context,
client *redis.Client,
queue string,
function func(ctx context.Context, value string),
) {
for { for {
element := client.BLPop(0, fmt.Sprintf("queue:%s", queue)) element := client.BLPop(ctx, 0, fmt.Sprintf("queue:%s", queue))
if len(element.Val()) == 2 { if len(element.Val()) == 2 {
value := element.Val()[1] value := element.Val()[1]
queueGaugeQueued.Inc() queueGaugeQueued.Inc()
go function(value) go function(ctx, value)
} }
} }
} }
func returnResult(config *Config, client *redis.Client, result Result) { func returnResult(ctx context.Context, config *Config, client *redis.Client, result Result) {
raw, err := json.Marshal(result) raw, err := json.Marshal(result)
if err != nil { if err != nil {
panic(err) panic(err)
} }
client.Publish(config.ResultChannel, string(raw)) client.Publish(ctx, config.ResultChannel, string(raw))
} }
...@@ -3,7 +3,7 @@ package main ...@@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/justjanne/imgconv" "github.com/justjanne/imgconv"
"gopkg.in/gographics/imagick.v2/imagick" "gopkg.in/gographics/imagick.v3/imagick"
"path/filepath" "path/filepath"
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment