Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download embedded postgres binary in docker image #1165

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading