Skip to content

Commit 348fcbf

Browse files
authored
Create combined image (#16)
* 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
1 parent e989950 commit 348fcbf

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

Dockerfile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Build API
2+
FROM golang:1.22-alpine AS api_builder
3+
4+
RUN apk add build-base
5+
6+
WORKDIR /api
7+
8+
COPY --from=api go.mod .
9+
COPY --from=api go.sum .
10+
11+
RUN go mod download
12+
13+
COPY --from=api ./cmd ./cmd
14+
COPY --from=api ./pkg ./pkg
15+
COPY --from=api ./migrations ./migrations
16+
COPY --from=api ./surveys ./surveys-examples
17+
RUN CGO_ENABLED=1 GOOS=linux go build -o api -tags enablecgo cmd/console-api/api.go
18+
19+
20+
# Build UI
21+
FROM node:20-alpine AS ui_base
22+
23+
FROM ui_base AS deps
24+
RUN apk add --no-cache libc6-compat
25+
WORKDIR /app
26+
27+
COPY --from=ui package.json package-lock.json ./
28+
RUN npm ci
29+
30+
FROM ui_base AS ui_builder
31+
WORKDIR /app
32+
COPY --from=deps /app/node_modules ./node_modules
33+
COPY --from=ui . .
34+
35+
ENV NODE_ENV=production
36+
ARG NEXT_PUBLIC_CONSOLE_API_ADDR
37+
ENV NEXT_PUBLIC_CONSOLE_API_ADDR=$NEXT_PUBLIC_CONSOLE_API_ADDR
38+
39+
RUN npm run build
40+
41+
42+
# Final image
43+
FROM alpine:latest AS runner
44+
45+
RUN apk --no-cache add ca-certificates tzdata nodejs
46+
47+
WORKDIR /app
48+
ENV NODE_ENV=production
49+
50+
COPY --from=ui_builder /app/public ./public
51+
52+
RUN mkdir .next
53+
RUN chown 1000:1000 .next
54+
55+
COPY --from=ui_builder --chown=1000:1000 /app/.next/standalone ./
56+
COPY --from=ui_builder --chown=1000:1000 /app/.next/static ./.next/static
57+
58+
WORKDIR /api
59+
60+
COPY --from=api_builder --chown=1000:1000 /api/api ./api
61+
COPY --from=api_builder --chown=1000:1000 /api/migrations ./migrations
62+
COPY --from=api_builder --chown=1000:1000 /api/surveys-examples ./surveys-examples
63+
64+
RUN mkdir /data
65+
RUN chown 1000:1000 /data
66+
67+
COPY start.sh /start.sh
68+
RUN chmod +x /start.sh
69+
70+
USER 1000:1000
71+
RUN mkdir /data/surveys
72+
RUN mkdir /data/db
73+
74+
EXPOSE 3000
75+
EXPOSE 8080
76+
77+
CMD ["sh", "/start.sh"]

compose-combined.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
formulosity:
3+
restart: unless-stopped
4+
image: formulosity:latest
5+
build:
6+
context: .
7+
additional_contexts:
8+
api: ./api
9+
ui: ./ui
10+
args:
11+
- NEXT_PUBLIC_CONSOLE_API_ADDR=http://127.0.0.1:8080
12+
ports:
13+
- "3000:3000"
14+
- "8080:8080"
15+
init: true
16+
environment:
17+
- LOG_LEVEL=debug
18+
- DATABASE_TYPE=sqlite # postgres|sqlite
19+
- DATABASE_URL=/data/db/formulosity.db
20+
- SURVEYS_DIR=/data/surveys
21+
- CONSOLE_API_ADDR=http://127.0.0.1:8080
22+
- IRON_SESSION_SECRET=e75af92dffba8065f2730472f45f2046941fe35f361739d31992f42d88d6bf6c
23+
- HTTP_BASIC_AUTH=user:pass
24+
volumes:
25+
- formulosity_db:/data/db
26+
- ./api/surveys:/data/surveys
27+
28+
volumes:
29+
formulosity_db:

start.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/api/api &
2+
node /app/server.js &
3+
wait -n

0 commit comments

Comments
 (0)