Skip to content

Commit 586fe5d

Browse files
committed
improve docker compose setup, mount config so not required in build
1 parent 4a37894 commit 586fe5d

8 files changed

Lines changed: 42 additions & 21 deletions

File tree

api/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM node:16-alpine
2-
WORKDIR /app
3-
COPY config.js /config.js
4-
COPY api/ .
2+
WORKDIR /sqtracker/app
3+
COPY . .
54
RUN yarn
65
EXPOSE 44444
76
CMD yarn start

api/src/controllers/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getTorrentsPage } from './torrent'
77
import { getUserRatio } from '../utils/ratio'
88
import { mail } from '../index'
99

10-
const sendVerificationEmail = async (address, token) => {
10+
export const sendVerificationEmail = async (address, token) => {
1111
await mail.sendMail({
1212
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
1313
to: address,

api/src/middleware/announce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const handleAnnounce = async (req, res, next) => {
5656
ratio !== -1 &&
5757
Number(params.left > 0)
5858
) {
59-
res.statusMessage = 'Ratio is below minimum threshold'
59+
res.statusMessage = `Ratio is below minimum threshold ${process.env.SQ_MINIMUM_RATIO}`
6060
res.sendStatus(403)
6161
return
6262
}

api/src/setup/createAdminUser.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import bcrypt from 'bcrypt'
22
import crypto from 'crypto'
33
import jwt from 'jsonwebtoken'
44
import User from '../schema/user'
5+
import { sendVerificationEmail } from '../controllers/user'
56

67
const createAdminUser = async () => {
78
const existingAdmin = await User.findOne({ username: 'admin' }).lean()
89
if (!existingAdmin) {
910
const created = Date.now()
11+
1012
const hash = await bcrypt.hash('admin', 10)
13+
1114
const adminUser = new User({
1215
username: 'admin',
13-
email: 'admin@sqtracker',
16+
email: process.env.SQ_ADMIN_EMAIL,
1417
role: 'admin',
1518
password: hash,
1619
created,
@@ -29,7 +32,21 @@ const createAdminUser = async () => {
2932
},
3033
process.env.SQ_JWT_SECRET
3134
)
35+
3236
await adminUser.save()
37+
38+
const emailVerificationValidUntil = created + 48 * 60 * 60 * 1000
39+
const emailVerificationToken = jwt.sign(
40+
{
41+
user: process.env.SQ_ADMIN_EMAIL,
42+
validUntil: emailVerificationValidUntil,
43+
},
44+
process.env.SQ_JWT_SECRET
45+
)
46+
await sendVerificationEmail(
47+
process.env.SQ_ADMIN_EMAIL,
48+
emailVerificationToken
49+
)
3350
}
3451
}
3552

client/.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
**/node_modules/
1+
**/node_modules/
2+
.next

client/Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
FROM node:16-alpine AS builder
2-
WORKDIR /app
3-
COPY config.js /config.js
4-
COPY client/ .
2+
WORKDIR /sqtracker
3+
COPY . .
54
RUN yarn install
5+
RUN echo "{}" > /config.js
66
RUN ./node_modules/.bin/next build
77

88
FROM node:16-alpine
9-
WORKDIR /app
10-
COPY --from=builder /config.js /config.js
11-
COPY --from=builder /app/node_modules ./node_modules
12-
COPY --from=builder /app/public ./public
13-
COPY --from=builder /app/.next ./.next
14-
COPY --from=builder /app/next.config.js ./next.config.js
9+
WORKDIR /sqtracker/client
10+
COPY --from=builder /sqtracker/node_modules ./node_modules
11+
COPY --from=builder /sqtracker/public ./public
12+
COPY --from=builder /sqtracker/.next ./.next
13+
COPY --from=builder /sqtracker/next.config.js ./next.config.js
1514
EXPOSE 44445
1615
CMD ["node_modules/.bin/next", "start", "-p", "44445"]

client/components/Notifications.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const NotificationsProvider = ({ children }) => {
125125
p="20px"
126126
pb="40px"
127127
overflowX="hidden"
128+
zIndex={999}
128129
_css={{ '> * + *': { mt: 3 } }}
129130
>
130131
{notifications.map((notification, i) => (
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ services:
2828
api:
2929
container_name: sq_api
3030
build:
31-
context: .
32-
dockerfile: ./api/Dockerfile
31+
context: ./api
32+
dockerfile: Dockerfile
3333
ports:
3434
- "127.0.0.1:44444:44444"
3535
labels:
@@ -39,20 +39,24 @@ services:
3939
- "traefik.http.services.api.loadbalancer.server.port=44444"
4040
- "traefik.http.middlewares.api-prefix.stripprefix.prefixes=/api"
4141
- "traefik.http.routers.api.middlewares=api-prefix"
42+
volumes:
43+
- ./config.js:/sqtracker/config.js
4244
depends_on:
4345
- database
4446
- tracker
4547
client:
4648
container_name: sq_client
4749
build:
48-
context: .
49-
dockerfile: ./client/Dockerfile
50+
context: ./client
51+
dockerfile: Dockerfile
5052
ports:
5153
- "127.0.0.1:44445:44445"
5254
labels:
5355
- "traefik.enable=true"
5456
- "traefik.http.routers.client.entrypoints=web"
5557
- "traefik.http.routers.client.rule=PathPrefix(`/`)"
5658
- "traefik.http.services.client.loadbalancer.server.port=44445"
59+
volumes:
60+
- ./config.js:/sqtracker/config.js
5761
depends_on:
58-
- api
62+
- api

0 commit comments

Comments
 (0)