From 732c71f7c2e5f0a37c03c2efedcfa8e5360e3fda Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 13 Jul 2025 00:52:57 +0900 Subject: feat(container): fix Docker build --- .dockerignore | 6 +- .gitignore | 4 +- Dockerfile | 5 +- backend/graphql/generated.go | 214 ++++++++++++++++----------------- backend/main.go | 30 ++--- backend/public/dummy.txt | 4 + common/graphql/schema.graphql | 232 ++++++++++++++++++------------------ compose.yaml | 2 +- frontend/graphql-codegen.ts | 4 +- frontend/public/vite.svg | 1 - frontend/src/graphql/schema.graphql | 1 + 11 files changed, 247 insertions(+), 256 deletions(-) create mode 100644 backend/public/dummy.txt delete mode 100644 frontend/public/vite.svg create mode 120000 frontend/src/graphql/schema.graphql diff --git a/.dockerignore b/.dockerignore index 48e8cc4..10446ea 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,4 @@ /backend/feedaka -/frontend/node_modules +/data/ /frontend/dist - -/feedaka.db -/feedaka.db-journal +/frontend/node_modules diff --git a/.gitignore b/.gitignore index 9728745..5345969 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ /backend/feedaka - -/feedaka.db -/feedaka.db-journal +/data/ diff --git a/Dockerfile b/Dockerfile index f60987e..c73319b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,11 +6,12 @@ COPY frontend/package.json frontend/package-lock.json ./ RUN npm install COPY frontend/ ./ +COPY common/graphql/schema.graphql src/graphql/schema.graphql RUN npm run build ########################################## -FROM golang:1.23-alpine AS backend-builder +FROM golang:1.24-alpine AS backend-builder WORKDIR /app @@ -19,7 +20,7 @@ COPY backend/go.mod backend/go.sum ./ RUN go mod download COPY backend/ ./ -COPY --from=frontend-builder /app/dist/style.css ./static/style.css +COPY --from=frontend-builder /app/dist/ ./public/ RUN CGO_ENABLED=1 GOOS=linux go build -o feedaka main.go ########################################## diff --git a/backend/graphql/generated.go b/backend/graphql/generated.go index b09d4d8..e4790bd 100644 --- a/backend/graphql/generated.go +++ b/backend/graphql/generated.go @@ -436,140 +436,140 @@ var sources = []*ast.Source{ Represents a feed subscription in the system """ type Feed { - """ - Unique identifier for the feed - """ - id: ID! + """ + Unique identifier for the feed + """ + id: ID! - """ - URL of the RSS/Atom feed - """ - url: String! + """ + URL of the RSS/Atom feed + """ + url: String! - """ - Title of the feed (extracted from feed metadata) - """ - title: String! + """ + Title of the feed (extracted from feed metadata) + """ + title: String! - """ - Timestamp when the feed was last fetched - """ - fetchedAt: DateTime! + """ + Timestamp when the feed was last fetched + """ + fetchedAt: DateTime! - """ - Whether the user is currently subscribed to this feed - """ - isSubscribed: Boolean! + """ + Whether the user is currently subscribed to this feed + """ + isSubscribed: Boolean! - """ - Articles belonging to this feed - """ - articles: [Article!]! + """ + Articles belonging to this feed + """ + articles: [Article!]! } """ Represents an individual article/post from a feed """ type Article { - """ - Unique identifier for the article - """ - id: ID! - - """ - ID of the feed this article belongs to - """ - feedId: ID! - - """ - GUID from the RSS/Atom feed (unique identifier from feed) - """ - guid: String! - - """ - Title of the article - """ - title: String! - - """ - URL/link to the original article - """ - url: String! - - """ - Whether the article has been marked as read - """ - isRead: Boolean! - - """ - The feed this article belongs to - """ - feed: Feed! + """ + Unique identifier for the article + """ + id: ID! + + """ + ID of the feed this article belongs to + """ + feedId: ID! + + """ + GUID from the RSS/Atom feed (unique identifier from feed) + """ + guid: String! + + """ + Title of the article + """ + title: String! + + """ + URL/link to the original article + """ + url: String! + + """ + Whether the article has been marked as read + """ + isRead: Boolean! + + """ + The feed this article belongs to + """ + feed: Feed! } """ Root query type for reading data """ type Query { - """ - Get all feeds with their metadata - """ - feeds: [Feed!]! + """ + Get all feeds with their metadata + """ + feeds: [Feed!]! - """ - Get all unread articles across all feeds - """ - unreadArticles: [Article!]! + """ + Get all unread articles across all feeds + """ + unreadArticles: [Article!]! - """ - Get all read articles across all feeds - """ - readArticles: [Article!]! + """ + Get all read articles across all feeds + """ + readArticles: [Article!]! - """ - Get a specific feed by ID - """ - feed(id: ID!): Feed + """ + Get a specific feed by ID + """ + feed(id: ID!): Feed - """ - Get a specific article by ID - """ - article(id: ID!): Article + """ + Get a specific article by ID + """ + article(id: ID!): Article } """ Root mutation type for modifying data """ type Mutation { - """ - Add a new feed subscription - """ - addFeed(url: String!): Feed! - - """ - Unsubscribe from a feed (preserves feed and article data) - """ - unsubscribeFeed(id: ID!): Boolean! - - """ - Mark an article as read - """ - markArticleRead(id: ID!): Article! - - """ - Mark an article as unread - """ - markArticleUnread(id: ID!): Article! - - """ - Mark all articles in a feed as read - """ - markFeedRead(id: ID!): Feed! - - """ - Mark all articles in a feed as unread - """ - markFeedUnread(id: ID!): Feed! + """ + Add a new feed subscription + """ + addFeed(url: String!): Feed! + + """ + Unsubscribe from a feed (preserves feed and article data) + """ + unsubscribeFeed(id: ID!): Boolean! + + """ + Mark an article as read + """ + markArticleRead(id: ID!): Article! + + """ + Mark an article as unread + """ + markArticleUnread(id: ID!): Article! + + """ + Mark all articles in a feed as read + """ + markFeedRead(id: ID!): Feed! + + """ + Mark all articles in a feed as unread + """ + markFeedUnread(id: ID!): Feed! } `, BuiltIn: false}, } diff --git a/backend/main.go b/backend/main.go index 150e0af..0efe66a 100644 --- a/backend/main.go +++ b/backend/main.go @@ -34,28 +34,14 @@ import ( var ( database *sql.DB queries *db.Queries - //go:embed static/* - staticFS embed.FS + //go:embed public/* + publicFS embed.FS + //go:embed db/schema.sql + dbSchema string ) func initDB(db *sql.DB) error { - _, err := db.Exec(` -CREATE TABLE IF NOT EXISTS feeds ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - url TEXT NOT NULL, - title TEXT NOT NULL, - fetched_at TEXT NOT NULL -); - -CREATE TABLE IF NOT EXISTS articles ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - feed_id INTEGER NOT NULL, - guid TEXT NOT NULL, - title TEXT NOT NULL, - url TEXT NOT NULL, - is_read INTEGER NOT NULL -); -`) + _, err := db.Exec(dbSchema) return err } @@ -186,7 +172,11 @@ func main() { e.Use(middleware.Recover()) e.Use(middleware.CORS()) - e.GET("/static/*", echo.WrapHandler(http.FileServer(http.FS(staticFS)))) + e.Use(middleware.StaticWithConfig(middleware.StaticConfig{ + HTML5: true, + Root: "public", + Filesystem: http.FS(publicFS), + })) // Setup GraphQL server srv := handler.New(graphql.NewExecutableSchema(graphql.Config{Resolvers: &resolver.Resolver{DB: database, Queries: queries}})) diff --git a/backend/public/dummy.txt b/backend/public/dummy.txt new file mode 100644 index 0000000..1c5c535 --- /dev/null +++ b/backend/public/dummy.txt @@ -0,0 +1,4 @@ +The public directory stores the build artifacts of the frontend. +However, in the local environment, the frontend side runs a development server to serve those files, so this public directory is not used. +Go does not allow specifying an empty directory with go:embed, so we place a dummy file here. +This dummy file is not used in production builds. diff --git a/common/graphql/schema.graphql b/common/graphql/schema.graphql index 75d4d77..a0bfa7e 100644 --- a/common/graphql/schema.graphql +++ b/common/graphql/schema.graphql @@ -4,138 +4,138 @@ scalar DateTime Represents a feed subscription in the system """ type Feed { - """ - Unique identifier for the feed - """ - id: ID! - - """ - URL of the RSS/Atom feed - """ - url: String! - - """ - Title of the feed (extracted from feed metadata) - """ - title: String! - - """ - Timestamp when the feed was last fetched - """ - fetchedAt: DateTime! - - """ - Whether the user is currently subscribed to this feed - """ - isSubscribed: Boolean! - - """ - Articles belonging to this feed - """ - articles: [Article!]! + """ + Unique identifier for the feed + """ + id: ID! + + """ + URL of the RSS/Atom feed + """ + url: String! + + """ + Title of the feed (extracted from feed metadata) + """ + title: String! + + """ + Timestamp when the feed was last fetched + """ + fetchedAt: DateTime! + + """ + Whether the user is currently subscribed to this feed + """ + isSubscribed: Boolean! + + """ + Articles belonging to this feed + """ + articles: [Article!]! } """ Represents an individual article/post from a feed """ type Article { - """ - Unique identifier for the article - """ - id: ID! - - """ - ID of the feed this article belongs to - """ - feedId: ID! - - """ - GUID from the RSS/Atom feed (unique identifier from feed) - """ - guid: String! - - """ - Title of the article - """ - title: String! - - """ - URL/link to the original article - """ - url: String! - - """ - Whether the article has been marked as read - """ - isRead: Boolean! - - """ - The feed this article belongs to - """ - feed: Feed! + """ + Unique identifier for the article + """ + id: ID! + + """ + ID of the feed this article belongs to + """ + feedId: ID! + + """ + GUID from the RSS/Atom feed (unique identifier from feed) + """ + guid: String! + + """ + Title of the article + """ + title: String! + + """ + URL/link to the original article + """ + url: String! + + """ + Whether the article has been marked as read + """ + isRead: Boolean! + + """ + The feed this article belongs to + """ + feed: Feed! } """ Root query type for reading data """ type Query { - """ - Get all feeds with their metadata - """ - feeds: [Feed!]! - - """ - Get all unread articles across all feeds - """ - unreadArticles: [Article!]! - - """ - Get all read articles across all feeds - """ - readArticles: [Article!]! - - """ - Get a specific feed by ID - """ - feed(id: ID!): Feed - - """ - Get a specific article by ID - """ - article(id: ID!): Article + """ + Get all feeds with their metadata + """ + feeds: [Feed!]! + + """ + Get all unread articles across all feeds + """ + unreadArticles: [Article!]! + + """ + Get all read articles across all feeds + """ + readArticles: [Article!]! + + """ + Get a specific feed by ID + """ + feed(id: ID!): Feed + + """ + Get a specific article by ID + """ + article(id: ID!): Article } """ Root mutation type for modifying data """ type Mutation { - """ - Add a new feed subscription - """ - addFeed(url: String!): Feed! - - """ - Unsubscribe from a feed (preserves feed and article data) - """ - unsubscribeFeed(id: ID!): Boolean! - - """ - Mark an article as read - """ - markArticleRead(id: ID!): Article! - - """ - Mark an article as unread - """ - markArticleUnread(id: ID!): Article! - - """ - Mark all articles in a feed as read - """ - markFeedRead(id: ID!): Feed! - - """ - Mark all articles in a feed as unread - """ - markFeedUnread(id: ID!): Feed! + """ + Add a new feed subscription + """ + addFeed(url: String!): Feed! + + """ + Unsubscribe from a feed (preserves feed and article data) + """ + unsubscribeFeed(id: ID!): Boolean! + + """ + Mark an article as read + """ + markArticleRead(id: ID!): Article! + + """ + Mark an article as unread + """ + markArticleUnread(id: ID!): Article! + + """ + Mark all articles in a feed as read + """ + markFeedRead(id: ID!): Feed! + + """ + Mark all articles in a feed as unread + """ + markFeedUnread(id: ID!): Feed! } diff --git a/compose.yaml b/compose.yaml index b4e0dc7..69dad6f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,7 +3,7 @@ services: build: context: . volumes: - - ./feedaka.db:/app/feedaka.db + - ./data/feedaka.db:/app/feedaka.db ports: - '127.0.0.1:8002:8080' environment: diff --git a/frontend/graphql-codegen.ts b/frontend/graphql-codegen.ts index af62625..d5339a4 100644 --- a/frontend/graphql-codegen.ts +++ b/frontend/graphql-codegen.ts @@ -2,8 +2,8 @@ import type { CodegenConfig } from "@graphql-codegen/cli"; const config: CodegenConfig = { overwrite: true, - schema: "../common/graphql/schema.graphql", - documents: ["src/**/*.tsx", "src/**/*.ts", "src/**/*.graphql"], + schema: "src/graphql/schema.graphql", + documents: ["src/graphql/*.graphql"], generates: { "src/graphql/generated/": { preset: "client", diff --git a/frontend/public/vite.svg b/frontend/public/vite.svg deleted file mode 100644 index e7b8dfb..0000000 --- a/frontend/public/vite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/frontend/src/graphql/schema.graphql b/frontend/src/graphql/schema.graphql new file mode 120000 index 0000000..4271904 --- /dev/null +++ b/frontend/src/graphql/schema.graphql @@ -0,0 +1 @@ +../../../common/graphql/schema.graphql \ No newline at end of file -- cgit v1.2.3-70-g09d2