Skip to content

Commit

Permalink
Merge pull request #1165 from flanksource/embedded-pre-download
Browse files Browse the repository at this point in the history
fix: download embedded postgres binary in docker image
  • Loading branch information
moshloop authored Jul 20, 2023
2 parents dddab13 + 3c6fc23 commit e303757
Show file tree
Hide file tree
Showing 4 changed files with 25 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"]
20 changes: 20 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,23 @@ 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 := "temp-database-dir"
if err := os.Mkdir(databaseDir, 0755); err != nil {
logger.Fatalf("Failed to create database directory[%s]: %+v", err)
}
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 e303757

Please sign in to comment.