-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create combined Dockerfile and docker-compose file * compose - mount the surveys directory to filesystem instead of docker volume * compose & dockerfile - Also expose port 8080 * start.sh - exit if any background process finishes/crashes instead of waiting for all combined with restart: unless-stopped this will cause the whole container to restart if a background job exits
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Build API | ||
FROM golang:1.22-alpine AS api_builder | ||
|
||
RUN apk add build-base | ||
|
||
WORKDIR /api | ||
|
||
COPY --from=api go.mod . | ||
COPY --from=api go.sum . | ||
|
||
RUN go mod download | ||
|
||
COPY --from=api ./cmd ./cmd | ||
COPY --from=api ./pkg ./pkg | ||
COPY --from=api ./migrations ./migrations | ||
COPY --from=api ./surveys ./surveys-examples | ||
RUN CGO_ENABLED=1 GOOS=linux go build -o api -tags enablecgo cmd/console-api/api.go | ||
|
||
|
||
# Build UI | ||
FROM node:20-alpine AS ui_base | ||
|
||
FROM ui_base AS deps | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app | ||
|
||
COPY --from=ui package.json package-lock.json ./ | ||
RUN npm ci | ||
|
||
FROM ui_base AS ui_builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY --from=ui . . | ||
|
||
ENV NODE_ENV=production | ||
ARG NEXT_PUBLIC_CONSOLE_API_ADDR | ||
ENV NEXT_PUBLIC_CONSOLE_API_ADDR=$NEXT_PUBLIC_CONSOLE_API_ADDR | ||
|
||
RUN npm run build | ||
|
||
|
||
# Final image | ||
FROM alpine:latest AS runner | ||
|
||
RUN apk --no-cache add ca-certificates tzdata nodejs | ||
|
||
WORKDIR /app | ||
ENV NODE_ENV=production | ||
|
||
COPY --from=ui_builder /app/public ./public | ||
|
||
RUN mkdir .next | ||
RUN chown 1000:1000 .next | ||
|
||
COPY --from=ui_builder --chown=1000:1000 /app/.next/standalone ./ | ||
COPY --from=ui_builder --chown=1000:1000 /app/.next/static ./.next/static | ||
|
||
WORKDIR /api | ||
|
||
COPY --from=api_builder --chown=1000:1000 /api/api ./api | ||
COPY --from=api_builder --chown=1000:1000 /api/migrations ./migrations | ||
COPY --from=api_builder --chown=1000:1000 /api/surveys-examples ./surveys-examples | ||
|
||
RUN mkdir /data | ||
RUN chown 1000:1000 /data | ||
|
||
COPY start.sh /start.sh | ||
RUN chmod +x /start.sh | ||
|
||
USER 1000:1000 | ||
RUN mkdir /data/surveys | ||
RUN mkdir /data/db | ||
|
||
EXPOSE 3000 | ||
EXPOSE 8080 | ||
|
||
CMD ["sh", "/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
services: | ||
formulosity: | ||
restart: unless-stopped | ||
image: formulosity:latest | ||
build: | ||
context: . | ||
additional_contexts: | ||
api: ./api | ||
ui: ./ui | ||
args: | ||
- NEXT_PUBLIC_CONSOLE_API_ADDR=http://127.0.0.1:8080 | ||
ports: | ||
- "3000:3000" | ||
- "8080:8080" | ||
init: true | ||
environment: | ||
- LOG_LEVEL=debug | ||
- DATABASE_TYPE=sqlite # postgres|sqlite | ||
- DATABASE_URL=/data/db/formulosity.db | ||
- SURVEYS_DIR=/data/surveys | ||
- CONSOLE_API_ADDR=http://127.0.0.1:8080 | ||
- IRON_SESSION_SECRET=e75af92dffba8065f2730472f45f2046941fe35f361739d31992f42d88d6bf6c | ||
- HTTP_BASIC_AUTH=user:pass | ||
volumes: | ||
- formulosity_db:/data/db | ||
- ./api/surveys:/data/surveys | ||
|
||
volumes: | ||
formulosity_db: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/api/api & | ||
node /app/server.js & | ||
wait -n |