Skip to content

Commit

Permalink
Feature/serve static website (#195)
Browse files Browse the repository at this point in the history
* deploy static website (frontend) with docker container

* fix Vite base path

* use env file for app related envs

* remove NODE_ENV for build
  • Loading branch information
mms-gianni authored Oct 18, 2024
1 parent 6a3b048 commit f976cba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REDDIT_CLIENT_ID=your-reddit-client-id
REDDIT_CLIENT_SECRET=your-reddit-client-secret
REDDIT_USER_AGENT=your-reddit-user-agent
REDDIT_USERNAME=your-reddit-username
REDDIT_PASSWORD=your-reddit-password
YOUTUBE_API_KEY=your-youtube-api-key
PAT=your-github-personal-access-token
PAT2=your-github-personal-access-token
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
FROM golang:1.23.2-alpine as builder
FROM node:23-alpine AS website
ENV VITE_HOST=""
WORKDIR /build
COPY website .
RUN npm install && npm run build
RUN ls -la /build/dist

FROM golang:1.23.2-alpine AS builder
WORKDIR /app
COPY main.go .
COPY cache ./cache
Expand All @@ -13,5 +20,6 @@ RUN go build -o gh_stats_app ./main.go
FROM alpine:latest AS runner
WORKDIR /home/app
COPY --from=builder /app/gh_stats_app .
COPY --from=website /build/dist ./website/dist
EXPOSE 8080
ENTRYPOINT ["./gh_stats_app"]
10 changes: 2 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ services:
environment:
- HOST=0.0.0.0
- PORT=8080
- REDDIT_CLIENT_ID=your-reddit-client-id
- REDDIT_CLIENT_SECRET=your-reddit-client-secret
- REDDIT_USER_AGENT=your-reddit-user-agent
- REDDIT_USERNAME=your-reddit-username
- REDDIT_PASSWORD=your-reddit-password
- YOUTUBE_API_KEY=your-youtube-api-key
- PAT=your-github-personal-access-token
- PAT2=your-github-personal-access-token
env_file:
- .env
healthcheck:
test: ["CMD", "wget", "-q", "http://127.0.0.1:8080/health", "-O", "-"]
interval: 30s
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ func main() {
return c.Send(nil)
})

// Do not index the website
app.Get("/robots.txt", func(c *fiber.Ctx) error {
return c.SendString("User-agent: *\nDisallow: /")
})

// serve the static files from the website/dist folder
app.Static("/", "./website/dist")

// serve the assets files from the website/dist/assets folder
app.Static("/daily-stars-explorer/assets", "./website/dist/assets")

app.Get("/gc", func(c *fiber.Ctx) error {
runtime.GC()
return c.Send(nil)
Expand Down

0 comments on commit f976cba

Please sign in to comment.