From eb811ba21e47204066ed27ff27f6923affcc43b9 Mon Sep 17 00:00:00 2001 From: Kenneth Liu <47234+kenliu@users.noreply.github.com> Date: Thu, 19 Sep 2024 08:35:04 -0400 Subject: [PATCH] WIP --- .dockerignore | 8 ++++++++ .gitignore | 1 + Dockerfile | 27 +++++++++++++++++++++++++++ data/database.go | 2 +- main.go | 6 ++++-- 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7a2f2a3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.idea/ +.envrc +secrets.md +database.json +*.log + +# ignore any secrets json files stored in the root directory +/*.json diff --git a/.gitignore b/.gitignore index a74241f..7bcb66b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea/ pinboard-popular-feed .envrc +todo.md secrets.md database.json *.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5fa84da --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Build stage +FROM golang:1.20 AS builder + +WORKDIR /app + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy source code +COPY . . + +# Build the binary +RUN CGO_ENABLED=0 GOOS=linux go build -o pinboard-popular-feed . + +# Final stage +FROM alpine:latest + +WORKDIR /app + +# Copy the binary from the builder stage +COPY --from=builder /app/pinboard-popular-feed . + +# Run the binary +CMD ["./pinboard-popular-feed"] \ No newline at end of file diff --git a/data/database.go b/data/database.go index a35de2a..c4e98c0 100644 --- a/data/database.go +++ b/data/database.go @@ -50,7 +50,7 @@ func (store *BookmarkStore) InitStore(config DBConfig) error { // defer db.Close() store.conn = db - fmt.Println("Successfully connected to the database") + log.Println("Successfully connected to the database") return err } diff --git a/main.go b/main.go index 3a5c897..bdd0cf3 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,8 @@ func main() { flag.Parse() // set up logging + // TODO here we want to write to stdout when running in cloud run + // maybe we have a flag to log to stdout? logFile, err := os.OpenFile("pinboard-popular-feed.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { log.Println("error opening log file") @@ -26,7 +28,7 @@ func main() { log.Println("starting pinboard-popular-feed") // set up mastodon credentials - mastodonCredentials, err := buildMastodonCredentials() + mastodonCredentials, err := createMastodonCredentialsFromEnv() if err != nil { os.Exit(1) } @@ -51,7 +53,7 @@ func main() { log.Println("finished pinboard-popular-feed") } -func buildMastodonCredentials() (MastodonCredentials, error) { +func createMastodonCredentialsFromEnv() (MastodonCredentials, error) { if os.Getenv("MASTODON_ACCESS_TOKEN") == "" { log.Println("MASTODON_ACCESS_TOKEN not set") return MastodonCredentials{}, errors.New("MASTODON_ACCESS_TOKEN not set")