Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kenliu committed Sep 19, 2024
1 parent 71db0b9 commit eb811ba
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea/
.envrc
secrets.md
database.json
*.log

# ignore any secrets json files stored in the root directory
/*.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/
pinboard-popular-feed
.envrc
todo.md
secrets.md
database.json
*.log
Expand Down
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion data/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
Expand All @@ -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")
Expand Down

0 comments on commit eb811ba

Please sign in to comment.