Skip to content

Commit 48917e0

Browse files
docker production files test
1 parent aeb309f commit 48917e0

2 files changed

Lines changed: 155 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM dart:stable AS build
2+
3+
# Accept the GITHUB_PAT and GITHUB_USER as an argument
4+
ARG GITHUB_PAT
5+
ARG GITHUB_USER
6+
7+
WORKDIR /app
8+
COPY . .
9+
10+
# Conditionally configure Git to use the provided GitHub token
11+
RUN if [ -n "$GITHUB_PAT" ] && [ -n "$GITHUB_USER" ]; then \
12+
echo "Configuring Git to use provided GitHub token..."; \
13+
# Add GitHub's public SSH key to known_hosts for security
14+
mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts; \
15+
git config --global credential.helper 'store'; \
16+
echo "url=https://github.com/.insteadOf git://github.com/" >> ~/.gitconfig; \
17+
echo "https://$GITHUB_USER:$GITHUB_PAT@github.com" > ~/.git-credentials; \
18+
else \
19+
echo "No GitHub token provided. Skipping Git configuration..."; \
20+
fi
21+
22+
RUN dart pub get
23+
RUN dart compile exe bin/main.dart -o bin/server
24+
25+
FROM alpine:latest
26+
27+
# Correcting the source directory for runtime dependencies
28+
COPY --from=build /runtime/ /
29+
COPY --from=build /app/bin/server server
30+
COPY --from=build /app/config/ config/
31+
COPY --from=build /app/web/ web/
32+
COPY --from=build /app/migrations/ migrations/
33+
34+
EXPOSE 8080
35+
EXPOSE 8081
36+
EXPOSE 8082
37+
38+
ENTRYPOINT ["/server"]
39+
CMD ["--mode", "production", "--server-id", "default", "--logging", "normal", "--role", "monolith"]
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
services:
2+
traefik:
3+
restart: on-failure
4+
image: traefik:v3.0
5+
command:
6+
- "--api.insecure=true"
7+
- "--providers.docker=true"
8+
- "--entrypoints.web.address=:80"
9+
- "--entrypoints.websecure.address=:443"
10+
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
11+
- "--certificatesresolvers.myresolver.acme.email=nacho.dominguis@proton.me"
12+
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
13+
ports:
14+
- "80:80"
15+
- "443:443"
16+
volumes:
17+
- "/var/run/docker.sock:/var/run/docker.sock"
18+
- "./letsencrypt:/letsencrypt"
19+
depends_on:
20+
- postgres
21+
- serverpod
22+
networks:
23+
- serverpod-network
24+
25+
postgres:
26+
healthcheck:
27+
test: ["CMD", "pg_isready", "-U", "postgres"]
28+
interval: 5s
29+
timeout: 5s
30+
retries: 5
31+
restart: on-failure
32+
image: postgres:latest
33+
labels:
34+
- "traefik.enable=false" # We typically don't expose databases via HTTP.
35+
ports:
36+
# Bind the Postgres port to localhost only so it isn't exposed externally,
37+
# while still allowing connections from the host machine.
38+
- "127.0.0.1:5432:5432"
39+
environment:
40+
- POSTGRES_USER
41+
- POSTGRES_DB
42+
- POSTGRES_PASSWORD
43+
volumes:
44+
- school_data_hub_data:/var/lib/postgresql/data
45+
networks:
46+
- serverpod-network
47+
48+
serverpod:
49+
restart: on-failure
50+
image: ghcr.io/${GHCR_ORG}/school_data_hub_server:latest
51+
environment:
52+
- SERVERPOD_DATABASE_PASSWORD
53+
- SERVERPOD_DATABASE_HOST
54+
- SERVERPOD_DATABASE_NAME
55+
- SERVERPOD_DATABASE_USER
56+
- SERVERPOD_DATABASE_PORT
57+
- SERVERPOD_DATABASE_REQUIRE_SSL
58+
- SERVERPOD_DATABASE_IS_UNIX_SOCKET
59+
- SERVERPOD_API_SERVER_PUBLIC_HOST
60+
- SERVERPOD_API_SERVER_PUBLIC_PORT
61+
- SERVERPOD_API_SERVER_PUBLIC_SCHEME
62+
- SERVERPOD_API_SERVER_PORT
63+
- SERVERPOD_INSIGHTS_SERVER_PUBLIC_HOST
64+
- SERVERPOD_INSIGHTS_SERVER_PUBLIC_PORT
65+
- SERVERPOD_INSIGHTS_SERVER_PUBLIC_SCHEME
66+
- SERVERPOD_INSIGHTS_SERVER_PORT
67+
- SERVERPOD_WEB_SERVER_PUBLIC_HOST
68+
- SERVERPOD_WEB_SERVER_PUBLIC_PORT
69+
- SERVERPOD_WEB_SERVER_PUBLIC_SCHEME
70+
- SERVERPOD_WEB_SERVER_PORT
71+
- SERVERPOD_SERVICE_SECRET
72+
- SERVERPOD_MAX_REQUEST_SIZE
73+
command:
74+
[
75+
"--mode",
76+
"production",
77+
"--server-id",
78+
"default",
79+
"--logging",
80+
"normal",
81+
"--role",
82+
"monolith",
83+
"--apply-migrations",
84+
]
85+
labels:
86+
- "traefik.enable=true"
87+
- "traefik.http.routers.api.rule=Host(`${SERVERPOD_API_SERVER_PUBLIC_HOST}`)"
88+
- "traefik.http.routers.api.entrypoints=websecure"
89+
- "traefik.http.routers.api.service=api-service"
90+
- "traefik.http.routers.api.tls.certresolver=myresolver"
91+
- "traefik.http.services.api-service.loadbalancer.server.port=${SERVERPOD_API_SERVER_PORT}"
92+
93+
- "traefik.http.routers.insights.rule=Host(`${SERVERPOD_INSIGHTS_SERVER_PUBLIC_HOST}`)"
94+
- "traefik.http.routers.insights.entrypoints=websecure"
95+
- "traefik.http.routers.insights.service=insights-service"
96+
- "traefik.http.routers.insights.tls.certresolver=myresolver"
97+
- "traefik.http.services.insights-service.loadbalancer.server.port=${SERVERPOD_INSIGHTS_SERVER_PORT}"
98+
99+
- "traefik.http.routers.web.rule=Host(`${SERVERPOD_WEB_SERVER_PUBLIC_HOST}`)"
100+
- "traefik.http.routers.web.entrypoints=websecure"
101+
- "traefik.http.routers.web.service=web-service"
102+
- "traefik.http.routers.web.tls.certresolver=myresolver"
103+
- "traefik.http.services.web-service.loadbalancer.server.port=${SERVERPOD_WEB_SERVER_PORT}"
104+
depends_on:
105+
postgres:
106+
condition: service_healthy
107+
networks:
108+
- serverpod-network
109+
110+
networks:
111+
serverpod-network:
112+
name: serverpod-network
113+
driver: bridge
114+
115+
volumes:
116+
school_data_hub_data:

0 commit comments

Comments
 (0)