Skip to content

Commit

Permalink
fix: download embedded postgres binary in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Jul 19, 2023
1 parent 63d00b9 commit a7eea72
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build/full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ RUN curl -L https://github.com/stern/stern/releases/download/v1.25.0/stern_1.25.
# install CA certificates
COPY --from=builder /app/.bin/canary-checker /app

RUN /app/canary-checker go-offline

RUN mkdir /opt/database
RUN groupadd --gid 1000 canary
RUN useradd canary --uid 1000 -g canary -m -d /var/lib/canary
RUN chown -R 1000:1000 /opt/database
RUN chown -R 1000:1000 /app
USER canary:canary

RUN /app/canary-checker go-offline
ENTRYPOINT ["/app/canary-checker"]
4 changes: 2 additions & 2 deletions build/minimal/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ RUN apt-get update && \

COPY --from=builder /app/.bin/canary-checker /app

RUN /app/canary-checker go-offline

RUN mkdir /opt/database
RUN groupadd --gid 1000 canary
RUN useradd canary --uid 1000 -g canary -m -d /var/lib/canary
RUN chown -R 1000:1000 /opt/database
RUN chown -R 1000:1000 /app
USER canary:canary
RUN /app/canary-checker go-offline

ENTRYPOINT ["/app/canary-checker"]
18 changes: 18 additions & 0 deletions cmd/offline.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"os"

"github.com/flanksource/canary-checker/pkg/db"
"github.com/flanksource/commons/logger"
"github.com/spf13/cobra"
Expand All @@ -13,5 +15,21 @@ var GoOffline = &cobra.Command{
if err := db.GoOffline(); err != nil {
logger.Fatalf("Failed to go offline: %+v", err)
}

// Run in embedded mode once to download the postgres binary
databaseDir := "/app/temp-database-dir"
os.Mkdir(databaseDir, 0755)

Check failure on line 21 in cmd/offline.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `os.Mkdir` is not checked (errcheck)
defer os.RemoveAll(databaseDir)

db.ConnectionString = "embedded://" + databaseDir
if err := db.Init(); err != nil {
logger.Fatalf("Failed to run in embedded mode: %+v", err)
}
if err := db.PostgresServer.Stop(); err != nil {
logger.Fatalf("Failed to stop embedded postgres: %+v", err)
}

// Intentionally exit with code 0 for Docker
os.Exit(0)
},
}
2 changes: 1 addition & 1 deletion pkg/jobs/canary/canary_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (job CanaryJob) Run() {
}
for status, checkIDs := range checkDeleteStrategyGroup {
if err := db.AddCheckStatuses(checkIDs, models.CheckHealthStatus(status)); err != nil {
logger.Errorf("error adding statuses for transformed checks")
logger.Errorf("error adding statuses for transformed checks: %v", err)
}
if err := db.RemoveTransformedChecks(checkIDs); err != nil {
logger.Errorf("error deleting transformed checks for canary %s: %v", canaryID, err)
Expand Down

0 comments on commit a7eea72

Please sign in to comment.