Skip to content

Commit

Permalink
set up multi-entrypoint script
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Dec 10, 2023
1 parent 9dfe31b commit abfaec4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
37 changes: 22 additions & 15 deletions docker/all/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ FROM golang:latest as api-builder
RUN git config --global --add safe.directory /server

WORKDIR /server
ADD . .

RUN go install github.com/go-task/task/v3/cmd/task@latest
RUN task backend
COPY go.mod go.sum ./
RUN go mod download

ADD ./app ./app
ADD ./cmd ./cmd
ADD ./internal ./internal
ADD ./Taskfile.yml .

RUN CGO_ENABLED=0 GOOS=linux go build ./cmd/backend

FROM node:18-alpine AS base

Expand All @@ -32,6 +38,7 @@ COPY --from=deps /app/node_modules ./node_modules
COPY ./web .

ENV NEXT_TELEMETRY_DISABLED 1
ENV NEXT_BUILD_STANDALONE true

RUN yarn build

Expand All @@ -46,26 +53,26 @@ ENV NODE_ENV production

ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN addgroup --system --gid 1001 storyden
RUN adduser --system --uid 1001 storyden
RUN chown storyden:storyden /app
USER storyden

COPY --from=builder /app/public ./public

RUN mkdir .next
RUN chown nextjs:nodejs .next
RUN mkdir .next && mkdir data

COPY --from=api-builder --chown=nextjs:nodejs /server/backend.exe ./backend.exe
COPY --from=api-builder --chown=storyden:storyden /server/backend ./backend
COPY --from=builder --chown=storyden:storyden /app/.next/standalone ./
COPY --from=builder --chown=storyden:storyden /app/.next/static ./.next/static

# Not enabled currently.
# COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

# TODO: Spin up the backend server here too.
CMD ["node", "server.js"]
VOLUME [ "/data" ]

COPY ./docker/all/docker-entrypoint.sh ./
ENTRYPOINT ["sh", "./docker-entrypoint.sh"]
8 changes: 8 additions & 0 deletions docker/all/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#/usr/bin/env sh

./backend &
node server.js &

ret=$(wait)
kill -INT $(jobs -p)
exit $ret
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Config struct {
Production bool `envconfig:"PRODUCTION" default:"false"`
LogLevel zapcore.Level `envconfig:"LOG_LEVEL" default:"info"`

DatabaseURL string `envconfig:"DATABASE_URL" default:"sqlite://data.db?_pragma=foreign_keys(1)"`
DatabaseURL string `envconfig:"DATABASE_URL" default:"sqlite://data/data.db?_pragma=foreign_keys(1)"`
ListenAddr string `envconfig:"LISTEN_ADDR" default:"0.0.0.0:8000"`
CookieDomain string `envconfig:"COOKIE_DOMAIN" default:"localhost"`
SessionKey string `envconfig:"SESSION_KEY" default:"0000000000000000"`
Expand Down
3 changes: 3 additions & 0 deletions web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */

const isStandalone = process.env.NEXT_BUILD_STANDALONE === "true";

const nextConfig = {
output: isStandalone ? "standalone" : undefined,
reactStrictMode: true,
swcMinify: true,
async rewrites() {
Expand Down

0 comments on commit abfaec4

Please sign in to comment.